-
Notifications
You must be signed in to change notification settings - Fork 696
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
Make securedrop PEP8-compliant (mostly) and add PEP8 pre-commit hook #1471
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.
Script looks good, and this is a useful hook I'd like to make available for developers.
I stopped commenting on it after the first few, and this is a person opinion, but I believe the syntax is too spaced out, sometimes for no gain in readability. Being able to see a large context of code is useful in my opinion, though I'm not just suggesting you cram as much as possible while being PEP8-compliant. Thoughts?
The one other thing is that something should go in the developer docs about this one.
@@ -109,7 +108,8 @@ def documents_messages_count(self): | |||
for submission in self.submissions: | |||
if submission.filename.endswith('msg.gpg'): | |||
self.docs_msgs_count['messages'] += 1 | |||
elif submission.filename.endswith('doc.gz.gpg') or submission.filename.endswith('doc.zip.gpg'): | |||
elif submission.filename.endswith('doc.gz.gpg') or \ | |||
submission.filename.endswith('doc.zip.gpg'): |
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 sure if the spacing on this bottom line is right. Further, I think we should follow PEP8 advice here:
The preferred way of wrapping long lines is by using Python's implied line continuation inside parentheses, brackets and braces. Long lines can be broken over multiple lines by wrapping expressions in parentheses. These should be used in preference to using a backslash for line continuation.
I also think think line breaks should come before binary operators (see https://www.python.org/dev/peps/pep-0008/#should-a-line-break-before-or-after-a-binary-operator).
@@ -184,7 +184,8 @@ class SourceStar(Base): | |||
|
|||
def __eq__(self, other): | |||
if isinstance(other, SourceStar): | |||
return self.source_id == other.source_id and self.id == other.id and self.starred == other.starred | |||
return self.source_id == other.source_id and \ |
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.
Parens instead of backslash, break before binary operator.
login_flashed_msg += ( | ||
" Please wait for a new " | ||
"two-factor token before logging in again." | ||
) |
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.
Could probably be 2 lines.
Journalist.MAX_PASSWORD_LEN | ||
), | ||
"error" | ||
) |
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 one it's not just for compactness--I think the spacing you have here actually hurts readability.
@@ -131,7 +131,7 @@ class Submission(Base): | |||
source = relationship( | |||
"Source", | |||
backref=backref("submissions", order_by=id, cascade="delete") | |||
) | |||
) |
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.
Not a fan of this C-style syntax to be honest. I prefer to fit more content in a page view, so long as it doesn't hurt readability. IMO the right-hand side is not so complicated that putting it into two lines would hurt readability. I do use it here for example, where the two vars in the brackets would otherwise be flush with the rest of the arguments, making it otherwise harder to tell they were nested in a list.
@fowlslegs Totally agree with the parenthesis over using backslashes, never saw that in PEP8. In regards to the conversation that occurred in #886, what are your thoughts on:
|
|
Okay, internal survey says FPF prefers 79/ official PEP8 decree. |
@ajvb is taking some time off, so someone should take over this PR. All that's left to be done is:
|
Ouch, badly in need of a rebase. Thank you for writing this, @ajvb! We'll get it over the finish line once the test churn settles down. @redshiftzero @fowlslegs is now a good time to tackle rebasing this? |
Ah, #1516 is still outstanding, let's get that in! |
Putting this in the 0.4 milestone issue because the associated issue, #886, currently is. As noted there, big changes in |
I think we should either close this PR, or commit to reworking it for an upcoming release such as |
@fowlslegs Agreed. Which would you advise? |
After 0.4 is released, let's rework this and get it into 0.4.1 (and maybe add |
Testing story here is relevant #1894 (comment). |
@redshiftzero Sounds good! |
Following up now that 0.4 has been released. First, thanks again for your contributions @ajvb 💎. Unfortunately, as we can see from the conflicts, the codebase has changed significantly since this PR was written. However since then, @dachary has gradually flake8'd almost all the code in However, I think the pre-commit hook in this PR would be really handy for developers. I've worked on a few projects that have |
Adding the int() to the string output from `wc -l` for integer comparison dragged the line over the 80 char mark, which caused the linting checks to fail on the testinfra directory. Fixed. Relevant to #1471, which included a pre-commit hook for linting that never got merged.
Thanks again for your PR @ajvb. Unfortunately we are closing this PR in light of superseding PR #2237. If you are interested in trying to contribute to SecureDrop again, please feel free - you're welcome to drop by our Gitter or take a look at anything tagged "hackathon" (these tend to be smaller issues). |
@redshiftzero Sounds good! My apologizes for being so unresponsive. Glad this was resolved nonetheless :) |
This PR is purely style fixes.
It makes the entire
securedrop/
directory PEP8 compliant except for a few cases ofE402 module level import not at top of file
within thetest/
directory.This is because of overriding config.py like so:
As well, this PR creates the
git_helpers/
directory and adds a pep8 pre-commit hook.One last thing, I would highly recommend adding CodeClimate (or similar) to do PEP8-on-PR checking per our conversation in #886. This will make sure that these style "problems" don't come back.
Example pep8 pre-commit hook output: