-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[python] Use PEP-0008 compliant code headers #762
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
[python] Use PEP-0008 compliant code headers #762
Conversation
I didn't know there was a guideline about that! I am not an expert in Python, but if our scripts trigger warnings in a standard style checker tool, that is an issue (and a barrier for) contributors. This looks like a reasonable header to me, except that we lost the |
238d518
to
359787e
Compare
Good point! Updated the commit with the following template:
|
@modocache Sorry, I forgot to mention that it has to be on the first line, or on the second line if the first line is a shebang. http://www.gnu.org/software/emacs/manual/html_node/emacs/Specifying-File-Variables.html |
@gribozavr Below are all PEP-8 violations found in current
|
@practicalswift I'm not an expert in Python style, so let me ask a question: which of these warnings are reasonably expected to be seen a well-written Python project? Are projects typically strictly following PEP-8? Why am I asking? Our intent is to maintain a high quality bar for the Python code. Conforming to a style guide requirements where there is no actual consensus in the community just to silence a style checker tool is not interesting. |
@gribozavr The PEP 8 guidelines were formalised back in 2001 (see https://www.python.org/dev/peps/pep-0008/) and I would say that there is very broad consensus in the Python community around these recommendations. @modocache, do you agree? :-) I would say that it is reasonable to expect that all new Python being added to the Swift project should adhere to PEP 8 (it is easily checked with the To show the changes needed to bring the code base into PEP 8 compliance I have pushed to an experimental branch https://github.com/practicalswift/swift/commits/fix-pep8-violations which fixes all PEP 8 violations (left to do: |
If there is broad agreement about following these guidelines, I don't see a reason why we shouldn't do so as well, especially given that there are tools that check them automatically. |
@gribozavr Do you want me to submit a PR to request a merge of https://github.com/practicalswift/swift/tree/fix-pep8-violations ? If so I should probably rebase when this PR (#762) is merged. My branch @modocache, if you have time - please take a look at https://github.com/practicalswift/swift/tree/fix-pep8-violations and see if you have any suggestions on how to improve :-) |
Running the Python style guide checker [`pep8`](https://pypi.python.org/pypi/pep8) on the Python code headers in this repository results in the following error being emitted: $ pep8 utils/build-script utils/build-script:1:1: E265 block comment should start with '# ' utils/build-script:3:1: E266 too many leading '#' for block comment utils/build-script:5:1: E266 too many leading '#' for block comment utils/build-script:6:1: E266 too many leading '#' for block comment utils/build-script:8:1: E266 too many leading '#' for block comment utils/build-script:9:1: E266 too many leading '#' for block comment utils/build-script:11:1: E265 block comment should start with '# ' utils/build-script:11:80: E501 line too long (80 > 79 characters) The problem is that the code header used in most Python files in the repository: 1. Do not place a space in between `#` and the rest of the comment. 2. Contains some lines that just barely exceed the recommend length limit. In addition, not all code headers in the repository follow the same template. This commit moves all Python code headers to the following template: # subfolder/file_name.py - Very brief description -*- python -*-- # # This source file is part of the Swift.org open source project # # Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors # Licensed under Apache License v2.0 with Runtime Library Exception # # See http://swift.org/LICENSE.txt for license information # See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors # # ----------------------------------------------------------------------------- # # This file contains stuff that I am describing here in the header and will # be sure to keep up to date. # # ----------------------------------------------------------------------------
359787e
to
a45a426
Compare
@gribozavr Updated with the
Below I have some findings on PEP-0008 compliance. I think this may end up being a long discussion (or bikeshed 😉), but I think this pull request should be merged in the meantime--however you feel about PEP-0008 compliance, this pull request at least standardizes the existing code headers.
This is a really interesting question. I initially strongly agreed with @practicalswift -- I was under the impression that there was broad consensus around PEP-0008. And while I do believe most people try to adhere to those guidelines, in practice it appears projects do not always conform. As an experiment, I tried running
There clearly aren't enough data points here, but I think it's safe to say that PEP-0008 compliance is not stringently observed in the Python community. In addition, some maintainers actively do not follow PEP-0008; see: https://github.com/kennethreitz/requests/pull/1964#issuecomment-37736480 Here are my conclusions:
|
After reviewing https://github.com/practicalswift/swift/tree/fix-pep8-violations, I'd argue it's a huge improvement for consistency in our Python code. Just my two cents, though! |
I agree.
Very interesting data! Thank you for gathering it! This is exactly the kind of practical evidence I was looking for. And, unfortunately, it does show that there is no broad consensus.
I agree. |
[python] Use PEP-0008 compliant code headers
@modocache Thanks for providing data. The consensus around PEP 8 is not as strong as I assumed :-) @modocache, @gribozavr I think we have already covered the most severe violations (unused imports, deprecated syntax, etc.) in the current code base - the remaining changes are quite cosmetic (max 80 chars, indentation style, etc.). So let's skip them for now :-) |
Add code headers missing from the Python files in `test/Driver`, as per the template from swiftlang#762.
Add code headers missing from the Python files in utils/cmpcodesize, as per the template from swiftlang#762.
Add code headers missing from utils/viewcfg, as per the template from swiftlang#762.
Add code headers missing from `utils/line-directive`, as per the template from swiftlang#762.
@modocache, @gribozavr: A thought - instead of striving for full PEP8 conformance, what about striving for no PEP8 regressions instead? That is we accept the current classes of violations found in the repo, but we strive for not introducing any new violation types. The following
@modocache, if you have time it would be really interesting to see your table above but with numbers from a re-run with these ignores applied :-) Hopefully the remaining rules after those ignores are totally non-controversial :-) |
Running the Python style guide checker
pep8
on the Python code headers in this repository results in the following error being emitted:The problem is that the code header used in most Python files in the repository:
#
and the rest of the comment.limit.
In addition, not all code headers in the repository follow the same template.
This commit moves all Python code headers to the following template:
There are also many Python files in this repository without any code headers at all. If we can agree upon a template I'll send another pull request to add all the missing headers.