-
Notifications
You must be signed in to change notification settings - Fork 688
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 #2944
Lints all Python files #2944
Conversation
The Makefile "flake8" target is now more comprehensive, using a blacklist approach rather than a whitelist approach to decide which files to lint. This strategy should catch new Python files introduced to the repository, so that CI will lint them even if they're in new directories. Rather than using a find-based approach, as with the "shellcheck" target, we'll run flake8 on the entire repository and trust flake8 to figure out which files it wants to inspect.
The molecule test suite includes some unique tests, and some that were ported from the older `testinfra/` location. The location under molecule/ was not being linted, and that's now fixed.
The vast majority of changes were simply resolving the formatting of comments. One option was to remove the comments entirely, since they're certainly not frequently consulted, but they may yet be of use to maintainers in the future, so reformatted rather than excised.
Minimal usage on this script, but let's clean it up anyway. If it's in the repo and a Python file that we control, it should pass flake8 linting. Added a few "noqa" lines here to permit non-standard imports, which are required due to the use of "config.py" for SecureDrop configuration. Also tacking on changes to the "restore.py" script, which is closely related.
All required logic has been ported to "restore.py", which is still used by the "restore" role.
The Ansible module was pulled in from a separate repository (see #1468), so the poor formatting is a product of lack of linting over there. Since this is an Ansible module, and not a regular Python module, there are a few common exceptions we'll make, specifically: * F401 * E402 * F403 * F405 For reference, see: https://github.com/HewlettPackard/oneview-ansible/blob/3dc8596861b10d16afe57a4d24bf7bd3dc514f3e/TESTING.md
Straightforward. Removed some extraneous imports and placed a comment on its own line to reduce line length.
This file goes back a while. We've never linted it, so even more recent changes weren't flake8 compliant. Now we're up to snuff. Excused the E501 up top because breaking up the filepath file tuple-syntax would only hurt readability.
The "profile_tasks" Ansible callback plugin was added to the repository back in the Ansible 1.x days. It's no longer necessary, since as of Ansible v2 task profiling was merged into core, and can be enabled via a whitelist option for callbacks in ansible.cfg. Removing the plugin should be handled separately, since all the changes in the current push involve strictly flake8 linting.
Minor changes throughout, all of them were reducing line length.
Codecov Report
@@ Coverage Diff @@
## develop #2944 +/- ##
========================================
Coverage 85.24% 85.24%
========================================
Files 32 32
Lines 1952 1952
Branches 218 218
========================================
Hits 1664 1664
Misses 237 237
Partials 51 51 Continue to review full report at Codecov.
|
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 zen cleanup :-) A few non-blocking nits in case you don't have anything better to do during the week-end. But good to merge.
@@ -65,9 +65,10 @@ def playbook_on_stats(self, stats): | |||
) | |||
|
|||
total_seconds = sum([x[1] for x in self.stats.items()]) | |||
print("\nPlaybook finished: {0}, {1} total tasks. {2} elapsed. \n".format( | |||
print("\nPlaybook finished: {0}, {1} total tasks." | |||
"{2} elapsed. \n".format( |
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.
Missing space before {2}.
import gnupg | ||
import subprocess | ||
import config # noqa: ignore=F403 | ||
import gnupg # noqa: ignore=F403 |
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.
Note to self: verified manually re, functools and subprocess do not show in the file because CI does not cover this file.
@@ -96,23 +90,23 @@ def parse_checksums(self): | |||
|
|||
|
|||
def main(): | |||
module = AnsibleModule( | |||
module = AnsibleModule( # noqa E405 |
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.
s/E405/F405/
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 one was doubly bad because it was ignoring all flake8 violations, not merely E405
as it appears. Instead of # noqa F405
, it should be # noqa: F405
to permit just that one violation.
Thank you for the careful, review @dachary. I agree with your recommendations for changes, will push up corresponding fixes shortly! |
@dachary pointed out a few touch-ups. In particular, the change to `ossec_urls.py` was a nice catch, in that the "noqa" line was ignoring *all* flake8 violations, not merely the specific one mentioned. @dachary further pointed out that it wasn't E405, but rather F405, that should have been permitted.
054c4bd
to
1a9ffe4
Compare
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.
There still are a few noqa that miss the trailing : to ignore only the selected violations
Once that's done, it's all good to merge 👍
Again, pointed out by @dachary, there were several instances of "# noqa" improperly disabling *all* flake8 checks, when only a specific check was intended. Resolved by adding colon, i.e. "# noqa:".
Fixed, @dachary! Used this regex to validate:
The above showed zero results. Compare with:
Looks good to me at this point, but please point out anything you think I missed! |
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 for the quick fix ! Good to merge once CI passes (and while I'm asleep presumably ;-)
Poor form on my part, was again omitting *all* flake8 checks, rather than only the ostensibly declared F403.
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.
Restamping
Status
Ready for review.
Description of Changes
Fixes #2933.
Lints the entire repo with
flake8
, omitting only:config.py
(intending specificallysecuredrop/config.py
).venv/
(the virtualenv for prod environments, containing pip-installed libs we don't control)Trimmed out a few unused files, e.g.
install_files/ansible-base/roles/restore/files/0.3_restore.py
, but only if not used anywhere. Additional files can be removed, but would require QA, so opened #2943 to track one example.Testing
make flake8
and confirm it passes.See if you can find any Python files that are not caught by this strategy.
Deployment
Minor: as long as the changes presented are genuinely lint-resolving, and not functional changes, then no concern for prod deployments. CI should catch any egregious mistakes.
Checklist
If you made changes to the app code:
If you made changes to the system configuration:
If you made changes to documentation: