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

Lints all Python files via flake8 #62

Merged
merged 6 commits into from
Feb 1, 2018
Merged

Lints all Python files via flake8 #62

merged 6 commits into from
Feb 1, 2018

Conversation

conorsch
Copy link
Contributor

@conorsch conorsch commented Jan 30, 2018

Cosmetic changes throughout, guided by flake8. The vast majority of changes were whitespace-related—pretty standard for Python projects—although in at least one case, the linter caught a genuine error in code, in which the test name test_decrypt_sd_submission_desktop was used twice, causing clobbering. That's resolved now.

Note that it's not easy to run make flake8 in the development environment: you'll need to run sudo dnf install python2-flake8 in the Work VM in order to use it. The goal is at least to get coverage in CI working, so that we have flake8 validation running prior to every PR merge.

Partial completion toward #56.

Marking this PR as "WIP" until I confirm CI is working as expected. Done, CI is passing.

@conorsch conorsch added the WIP label Jan 30, 2018
@conorsch conorsch force-pushed the 56-linting-flake8 branch 2 times, most recently from 9495499 to 57f609d Compare January 31, 2018 00:12
Conor Schaefer added 6 commits January 30, 2018 16:37
Runs flake8 to lint all Python files. Deferring to the `flake8` commands
on which files are Python, rather than explicitly passing a whitelist of
files to lint.

Users must install at least v3.3.0 of flake8; older versions, such as
2.5.5 (currently available in the Fedora 25 EOL repos), are not
sufficient for the file discovery logic. As a stopgap, we can pass "."
for the current working directory to flake8, which will force even older
versions to traverse for file discovery.

Note that we're *not* setting the `assert-dom0` target as a dependency,
since dom0 will not have flake8 installed by default. It's reasonable
for the dev env to have it, and we'll make sure the linting checks run
in CI.
Mostly whitespace violations, cleaned up with consistent indentation
throughout. All files under the tests/ directory now pass flake8
linting.

There are a few minor exceptions added, to permit lines longer than 80
characters to aid in readability, e.g. filepaths.

Found one major error, in the decryption tests: two tests sharing the same
name, so there was clobbering going on. Resolved. Hurray, linting!
The Python scripts that handle state monitoring inside the SD Journalist
VM now conform to flake8 linting standards. The changes were minimal.
Permitted a longer-80-char line to preserve readability on a URL.
Single commit for resolution of the E741 violation, which states that
"l" (i.e. lowercase L) should not be used as a variable name, since it
can be mistaken visually for a "1" (i.e. the number one). That's a bit
of a stretch in my mind, but hey, let's trust the linter.

The first version of flake8 including this check is v3.5.0. Older
versions will silently ignore the violation.
There was a bare except in the _reboot function, which would mask errors
of any kind. As stipulated by Flake8 E722, "except" blocks should catch
explicitly declared exceptions. Since this codeback isn't currently used
anywhere—it's commented out in the setUp def—let's remove the
noncompliant try/except block and watch for errors down the road. When
observed, we'll catch the errors by name and handle appropriately.
Using a clean Debian Stretch container image and customizing it slightly
to pull in flake8 via pip. Not currently pinning any pip lib versions,
e.g. via requirements.txt, although we'll surely want to in the future.

Not using any of the FPF-maintained container images for CI [0], since
they all assume Python3, and the Qubes management code is all still
Python2 for the time being.
@conorsch conorsch requested a review from joshuathayer January 31, 2018 00:39
@conorsch conorsch removed the WIP label Jan 31, 2018
@conorsch
Copy link
Contributor Author

Caught two more violations with a more recent version of flake8 in CI. @joshuathayer, I wrote those as separate commits, to make it easy to review. Other than that, changes are purely cosmetic.

@conorsch conorsch mentioned this pull request Jan 31, 2018
4 tasks
@conorsch
Copy link
Contributor Author

Enabled branch protection on master, requiring both formal approvals of PR and CI passing in order to merge. @joshuathayer if the CI requirement is too aggressive for now (e.g. blocking merge of older pending PRs), just holler.

@conorsch
Copy link
Contributor Author

This PR misses all the scripts in the repo, and just modifies the unittest *.py files, due to the implicit optimism regarding file discovery via flake8 .. The additional Python files in the form of scripts can be found using something like:

find -type f -exec file -i {} + | grep -i text/x-python | cut -d: -f1

Will circle back on those and submit a separate PR, to aid in review here. Please proceed with review.

Copy link
Contributor

@joshuathayer joshuathayer left a comment

Choose a reason for hiding this comment

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

Very cool. Changes do seem to be all whitespace-related and tests pass, so :shipit:

Copy link
Contributor

@kushaldas kushaldas left a comment

Choose a reason for hiding this comment

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

Works well. I introduced a few errors and validated 👍

@conorsch
Copy link
Contributor Author

conorsch commented Feb 1, 2018

Thank you for review, @joshuathayer and @kushaldas! Ready to merge, but looks like the CircleCI logic is a bit wonky:

sd-workstation-circleci-status-pending

Hey @msheiny, any bright ideas to resolve? I don't mind temporarily disabling the branch protection in order to merge—the .circleci/config.yml file was introduced in this branch, so it may need to be in master before it works seamlessly.

@msheiny
Copy link
Contributor

msheiny commented Feb 1, 2018

heyy @conorsch quick check did you rename/rebase this PR a few times during the circle CI shake out? im guessing at one point the job name was updated and in github you have it pegged to the previous name. Solution is easy though!

image
Change that checkmark above ^^ 👍

@conorsch
Copy link
Contributor Author

conorsch commented Feb 1, 2018

You rock, @msheiny, that did it! Merging...

@conorsch conorsch merged commit c907d2d into master Feb 1, 2018
@msheiny msheiny deleted the 56-linting-flake8 branch February 1, 2018 22:31
charles-boyd pushed a commit to charles-boyd/securedrop-workstation that referenced this pull request Sep 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants