Skip to content

Require black and isort for contributions - #3329

Merged
JelleZijlstra merged 21 commits into
masterfrom
black-contributing
Jun 28, 2020
Merged

JelleZijlstra merged 21 commits into
masterfrom
black-contributing

Conversation

@srittau

@srittau srittau commented Oct 9, 2019

Copy link
Copy Markdown
Collaborator
  • Add explanation to CONTRIBUTNG.md
  • Add sample pre-commit script
  • Check for correctly formatted files in CI
  • Only install flake8 packages when running flake8 in CI

This is a draft, which we should merge only after the following are solved:

  • There is a problem with isort that causes it to crash on stdlib/3/io.pyi. Reported as Type-annotated "encoding" field crashes isort PyCQA/isort#1027.
  • We need to reformat all files at once. My suggestion is to make sure that the PR to do that is open only for a short time, ideally only as long as CI needs, to minimize the disruption.

* Add explanation to CONTRIBUTNG.md
* Add sample pre-commit script
* Check for correctly formatted files in CI
Comment thread stdlib/3/encodings/__init__.pyi Resolved
Comment thread .travis.yml Resolved
@srittau srittau added the project: infrastructure typeshed build, test, or distribution related label May 28, 2020
@JelleZijlstra

Copy link
Copy Markdown
Member

Should we land this soon? Currently not that many PRs are open, and I'd love to get this in so I don't have to worry about how to format stubs.

cc @CraftSpider and @hauntsaninja

@hauntsaninja

Copy link
Copy Markdown
Collaborator

Assuming we're doing this*, now seems like a good time to me too!

Details

I know it's not the Black way, so hiding my small dissent. Despite liking it in code, I've personally come to dislike one line per arg in stubs. In particular, I find it much harder to compare long overloads (e.g. stdlib/3/subprocess.pyi). I can get over it, but thought I'd mention in case other people feel similarly.

@srittau

srittau commented Jun 11, 2020

Copy link
Copy Markdown
Collaborator Author

@hauntsaninja Quick reply to your gripes: I am not totally on board with all formatting decisions of black (or PEP 8), either, but in the end it's more important to me to have consistent formatting than one that perfectly aligns with my tastes.

@CraftSpider

Copy link
Copy Markdown
Contributor

It seems like we're not likely to get much lower, I'm down to land this soon.

DetailsAs for the formatting style, I also find one line per arg int stubs less readable, but consistency is generally more important. If most others also find it inconvenient, that makes it definitely a known papercut, but if that's the only one I think that's an acceptable trade-off for the consistency gained.

@srittau

srittau commented Jun 12, 2020

Copy link
Copy Markdown
Collaborator Author

We can land this once #4224 lands.

srittau added 2 commits June 19, 2020 10:18
The previous version automatically reformatted the changed files.
This can be problematic when only committing partial files. The
new version is safer only checks the changed files, with the option
to change the files in the comments.
@JelleZijlstra

Copy link
Copy Markdown
Member

We applied Black/isort in #4287. I'm going to fix up this PR and merge it after lunch (unless @hauntsaninja or @srittau gets to it first).

should have re-run black after moving the type ignore
@JelleZijlstra

Copy link
Copy Markdown
Member

Hm, isort is failing in CI, maybe it's not picking up our config from pyproject.toml?

@JelleZijlstra

Copy link
Copy Markdown
Member

Ah /home/travis/virtualenv/python3.8.1/lib/python3.8/site-packages/isort/settings.py:296: UserWarning: Found /home/travis/build/python/typeshed/pyproject.toml with [tool.isort] section, but toml package is not installed. To configure isort with /home/travis/build/python/typeshed/pyproject.toml, install with 'isort[pyproject]'.

@Eric-Arellano

Copy link
Copy Markdown
Contributor

but toml package is not installed. To configure isort with /home/travis/build/python/typeshed/pyproject.toml, install with 'isort[pyproject]'.

Rather than installing toml as a dedicated requirement, I believe the error message is saying to install isort[pyproject], similar to how you can install requests[security]. Your requirements.txt would have isort[pyproject]==4.3.21.

@JelleZijlstra

Copy link
Copy Markdown
Member

@Eric-Arellano you're right, I was too lazy to figure out how to combine the [pyproject] and ==version syntax, but that's a better way. What I did should work too though because the pyproject extra just installs toml (https://github.com/timothycrosley/isort/blob/develop/pyproject.toml#L42).

@hauntsaninja

Copy link
Copy Markdown
Collaborator

Looks like isort is still failing

@JelleZijlstra

Copy link
Copy Markdown
Member

OK, now there's another isort error, which is apparently because isort behaves differently depending on whether or not typing-extensions is installed in the current environment (?!?).

For now I'm going to remove isort from CI and land the Black part of his PR. We can try to figure out a less fragile isort config in a separate PR.

@JelleZijlstra

Copy link
Copy Markdown
Member

CI passed, I'm landing this now. We can discuss how to turn on isort in #4288.

@JelleZijlstra
JelleZijlstra merged commit 4586ed9 into master Jun 28, 2020
@JelleZijlstra
JelleZijlstra deleted the black-contributing branch June 28, 2020 22:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

project: infrastructure typeshed build, test, or distribution related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants