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
[9512] Initial configuration for black, take two #1380
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The old pycodestyle target would fail in CI if someone submitted a PR,
but it did not pass pycodestyle changes.
If someone submits a PR, and it is not formatted with black,
will there be a CI failure, so that the user will know that they have to reformat their patch with black,
with tox -e black
?
tox.ini
Outdated
|
||
[testenv:black] | ||
skip_install=True | ||
basepython=python3.6 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this PR, the basepython for running black is Python 3.6.
However, Python 3.5 support has not yet been dropped from Twisted.
Do you need to specify --target
to black, to prevent style changes incompatible with Python 3.5 from going in?
I'm not in favor of pinning the tox environment for black to a specific Python version,
because a Twisted contributor may have a different version of Python installed on their system,
and tox -e black
will not work for them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe that the target-version
in pyproject.toml
ensures that 3.5-compatible syntax is used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you are correct. That's good enough then.
tox.ini
Outdated
@@ -151,6 +148,25 @@ deps=https://github.com/twisted/pydoctor/archive/3f9c64829dfa040b334c9ae27c332c7 | |||
[testenv:manifest-checker] | |||
skip_install = true | |||
|
|||
[testenv:lint] | |||
skip_install=True | |||
basepython=python3.6 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not in favor of pinning the lint target to Python 3.6,
because tox -e lint
will not work for contributors who do not have Python 3.6 installed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really understand the motivation for this change myself. Perhaps the goal was to prevent linting tools from running under Python 2.7 if Tox was installed with that Python version? I'll remove it.
tox.ini
Outdated
lint: diff-cover==0.9.12 | ||
lint: pycodestyle | ||
|
||
black: black>=19.3b0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Further down in the deps
section, you have: black==20.8b1
.
Might be good to keep this consistent
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I'll clean this up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reference to pycodestyle
should be removed from README.rst
.
Might want to add reference to tox -e black
there.
If a user files a PR, and their PR does not match black's coding style, |
@rodrigc Thank you for the review! I believe that I have addressed all your comments. ChangesI consolidated the Tox configuration to have a factor-based style throughout. This seemed to be most similar to what was already there. I'd contrast the factor-based style with the explicit I removed some detritus for a I added a GitHub Actions workflow that runs the linting tools. I like GHA for this because it is lower-latency than Travis, though the log UI is more difficult to use. I also filed #9953 to do more of this. Merge ProcedureThere is a bit of instability in Black's output on one file that'll need to be worked around when running it (filed upstream here), so the procedure on merge will be:
Running the tool twice with Overall:
|
|
||
To automatically format code according to the coding standards:: | ||
|
||
$ tox -e black-reformat |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, this gives clear instructions on how to reformat the code.
@@ -76,18 +76,19 @@ Indentation is 4 spaces per indent. | |||
Tabs are not allowed. | |||
It is preferred that every block appears on a new line, so that control structure indentation is always visible. | |||
|
|||
Lines are flowed at 79 columns. | |||
Lines are flowed at 88 columns per `The Black Code Style <https://github.com/psf/black/blob/master/docs/the_black_code_style.md>`_. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is OK. In future, we may want to remove all mention of number of columns, etc.
from this document, and just say that Twisted follows the style guidelines as followed by Black, and just give a pointer Black's guidelines. In the end, very few people will read this anyways.
As long as they are told during review time to run tox -e black-reformat
to make their
PR acceptable, that is probably good enough.
Might want to add the required invocation of black to the wiki here: https://twistedmatrix.com/trac/wiki/TwistedDevelopment#GettingYourPatchAccepted |
|
||
runs-on: ubuntu-20.04 | ||
env: | ||
TOXENV: "lint,black,manifest-checker,twine" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding this GitHub action which invokes black is good.
@@ -148,20 +165,10 @@ commands = | |||
[testenv:apidocs] | |||
deps=https://github.com/twisted/pydoctor/archive/3f9c64829dfa040b334c9ae27c332c7078356e79.zip | |||
|
|||
[testenv:manifest-checker] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, looks like this block which got deleted moved to: https://github.com/twisted/twisted/pull/1380/files#diff-b91f3d5bd63fcd17221b267e851608e8R108
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this looks ok.
- You have a GitHub Action which invokes black, so we can get feedback from CI
tox -e black
runs the check, andtox -e black-reformat
can be run by a contributor to reformat their code
So I would say merge this, and let's get this going.
In follow-up items, I would say:
- Make a follow-up PR which reformats the tree. I can quickly review/approve
- Make a follow-up PR which adds a value to
.git-blame-ignore-revs
. I can quickly review/approve - Send a e-mail to the mailing list, informing that coding style has changed to black, and give pointers to what a user should do to make their existing PR's acceptable to the new coding style.
- The docs regarding coding style should be cut to the bare minimum, and just have pointers to the Black guidelines. Also, just mention in the docs that
tox -e black-reformat
must be run to make any contribution acceptable. - Take a pass through the wiki, and add references to black as appropriate, such as: https://twistedmatrix.com/trac/wiki/TwistedDevelopment#GettingYourPatchAccepted
- Do we need to add Black to the Contributor Checklist: that is displayed for ever PR?
This is a rebase of, and closes #1134. I removed the documentation changes that proved so contentious, but added a few necessary to reconcile with The Black Code Style.
Contributor Checklist:
review
to the keywords field in Trac, and putting a link to this PR in the comment; it shows up in https://twisted.reviews/ now.