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

Reformat and lint files with black and flake8 #168

Merged
merged 15 commits into from
Sep 7, 2020
Merged

Reformat and lint files with black and flake8 #168

merged 15 commits into from
Sep 7, 2020

Conversation

graeme-a-stewart
Copy link
Member

A bit of an overdue clean-up of all of the Python scripts.

  • All the scripts have been formatted with black
  • All of the scripts have been checked against flake8

The scripts were also checked against pylint, and many issues from there fixed. However, it's exceedling strict and there are even some formatting decisions where pylint and black disagree, so that without specific exceptions added to the scripts the two checks can't agree. Most of the scripts test at 9/10 (or better) with pylint. We should endevour to keep the scripts good against pylint without enforcing it.

A GitHub action was added to run flake8 as part of the CI.

Fixes #157

Graeme A Stewart added 7 commits September 4, 2020 21:12
Format with black; fix many, many defects identified with pylint
Python prefers snake_case for script and module names
and this fixes pylint complaining about this
black target will reformat all Python scripts
flake8 will run linter on all Python scripts
Passes flake8 (required) and most of pylint (recommended)
Pass flake8 (required) and most of pylint (recommended)
black should be used for formatting
scripts must be error free with flake8
@graeme-a-stewart graeme-a-stewart added the work in progress Further development needed before this pull request can be accepted label Sep 5, 2020
Graeme A Stewart and others added 7 commits September 7, 2020 16:17
pylint checks pushed an implementation where most code was inside the main() function,
however this caused a problem with unittest that will only run
tests in the global namespace,
but use of globals is rather nasty

This reimplementaion keeps the argument parsing and test case
generation in a main-ish function,
but returns the test case and then
invokes unittest.main()
which is a much nicer implementation
Only need to run flake8 on one platform
The urlopen() call in these tests is to the http server that was setup by the
unittest itself, so we know that it's ok
This was an accident, but it proved that the flake8 GH action
works as we want!
@graeme-a-stewart graeme-a-stewart added enhancement New feature or request tests Issues to do with tests and removed work in progress Further development needed before this pull request can be accepted labels Sep 7, 2020
@graeme-a-stewart
Copy link
Member Author

Hi @amete - this should be good to go now.

All the scripts have been reformatted and small translation bugs are fixed
The new flake8 test works fine, if you look at https://github.com/HSF/prmon/runs/1082295343 then you'll see it failed for a small style violation

Copy link
Collaborator

@amete amete left a comment

Choose a reason for hiding this comment

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

Thanks a lot for this @graeme-a-stewart! The python code looks quite a bit cleaner now. All tests pass (locally as well). I ran the plotting script over a test file and the output looks good (i.e. no change). I'm merging now.

@amete amete merged commit 9d2decb into master Sep 7, 2020
@amete amete deleted the black-flake8 branch September 7, 2020 18:32
@amete amete mentioned this pull request Sep 7, 2020
@graeme-a-stewart graeme-a-stewart added this to the v2.1 milestone Sep 8, 2020
@amete amete restored the black-flake8 branch January 27, 2022 15:51
@amete amete deleted the black-flake8 branch January 27, 2022 15:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request tests Issues to do with tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Python code linter and formatter
2 participants