Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

STYLE: Specify target-version for black #29607

Merged
merged 2 commits into from
Nov 14, 2019

Conversation

jschendel
Copy link
Member

The target-version option explicitly tells black that it can use Python features from the supplied versions. The default is per-file detection by looking for the presence specific syntax, e.g. f-strings would indicate py36.

Currently black does not detect this for us since we just bumped to py36, so detection will not occur until f-strings are added, which would in turn necessitate these changes as part of the f-string PRs, making them a bit more convoluted than needed. This resolves that issue by explicitly telling black our supported versions and enforcing those changes for the entire codebase in this PR.

@jschendel jschendel added the Code Style Code style, linting, code_checks label Nov 14, 2019
@jschendel jschendel added this to the 1.0 milestone Nov 14, 2019
@kaathi524 kaathi524 mentioned this pull request Nov 14, 2019
@@ -10,3 +10,23 @@ requires = [
"numpy==1.16.0; python_version=='3.6' and platform_system=='AIX'",
"numpy==1.16.0; python_version>='3.7' and platform_system=='AIX'",
]

[tool.black]
target-version = ['py36', 'py37', 'py38']
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking over the black issue tracker it looks like we should be specifying all versions instead of just the lower bound. The logic being that a new version of Python could change the syntax such that a kind of formatting that black thinks is ideal is no longer supported.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a reason for pyproject.toml instead of setup.cfg?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

black does not support configuration through setup.cfg nor do they plan on supporting it in the future

@@ -56,7 +56,7 @@ if [[ -z "$CHECK" || "$CHECK" == "lint" ]]; then
black --version

MSG='Checking black formatting' ; echo $MSG
black . --check --exclude '(asv_bench/env|\.egg|\.git|\.hg|\.mypy_cache|\.nox|\.tox|\.venv|_build|buck-out|build|dist|setup.py)'
black . --check
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved the --exclude option to pyproject.toml since I had to create an entry there for target-version. Also has the advantage that users running black (either explicitly or through pre-commit) will now pick this up as well, so local behavior will match CI.

@jreback
Copy link
Contributor

jreback commented Nov 14, 2019

can u update the template and pre-commit hooks as well?

or do they read the pyproject.toml?

@jschendel
Copy link
Member Author

I tested it locally and it looks like it reads the pyproject.toml by default, like how flake8 reads from setup.cfg by default with pre-commit, etc.

@jorisvandenbossche
Copy link
Member

Yes, when we started using black, we didn't yet have the pyproject.toml, so needed to put the config flags into the CI call itself. But now we have that, we should indeed move the config there.

@jreback
Copy link
Contributor

jreback commented Nov 14, 2019

lgtm. can you merge master (conflict); merge on green.

@jorisvandenbossche jorisvandenbossche merged commit 193a46e into pandas-dev:master Nov 14, 2019
@jorisvandenbossche
Copy link
Member

thanks @jschendel !

Reksbril pushed a commit to Reksbril/pandas that referenced this pull request Nov 18, 2019
proost pushed a commit to proost/pandas that referenced this pull request Dec 19, 2019
proost pushed a commit to proost/pandas that referenced this pull request Dec 19, 2019
@jschendel jschendel deleted the black-target-version branch December 20, 2019 01:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Code Style Code style, linting, code_checks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants