-
Notifications
You must be signed in to change notification settings - Fork 29
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
Add and apply formatters and linters to codebase #381
Add and apply formatters and linters to codebase #381
Conversation
@forsyth2 I'll go over this PR in our Monday meeting to provide some more context |
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.
Looks good as far as I can tell from skimming.
- Squash commits, unless you think they're organized logically
- Your refactoring suggestions can be addressed in another pull request. Best not to further complicate this one.
- Make sure the unit tests pass.
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.
Looks good. Your article on pre-commiting is very helpful. As Ryan suggested, we need to make sure all tests pass before merging. At some point, i will consult you about configuring IDE/text editor to use these tools...
@chengzhuzhang I'm glad to hear the article was helpful! Once PRs #383 and #385 are merged, I can run the test suite on this PR. Also I'd be glad to help with your IDE/text editor setup. There is a way to share VSCode workspace settings for the project so that VSCode is automatically configured by opening the file. I can include it in this PR. |
4045ced
to
51ce529
Compare
@forsyth2 @chengzhuzhang this PR is ready for final review. The branch is rebased on the latest master and all of the tools have been applied on those commits. The local test suite and TravisCI build passes. I've included a |
@tomvothecoder Hey Tom, the PR looks good! Regarding to the complete test failure. It looks like the 4 figures in question have pixel difference fraction (although small) larger than the threshold set, so can't be ignored. I think we should visual check the images and maybe to consider to flex the fraction threshold a bit more. Would you point me to the path where the complete test was ran? |
@chengzhuzhang Sorry, already on that. https://github.com/E3SM-Project/e3sm_diags/pull/373/files#diff-535b9e4349bf24011ce127f7ce530fdbbf007e23486b005b29a5cec32c42b8baR441 changed the units. I'm updating the expected images. I also created #386 to explain how to do this. |
Makes sense! The units change caused this. The image checker is absolutely useful! |
98398a9
to
e32d19d
Compare
@chengzhuzhang #388 makes it so the image diffs will automatically generate. https://web.lcrc.anl.gov/public/e3sm/diagnostic_output/ac.forsyth2/image_check_failures_2022_02_22/MERRA2-TMQ-ANN-global_diff.png is an example of what this looks like and how I could tell the issue was the units |
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.
Looks good. If all automated tests and the complete run pass, then this should be good to merge. It would be good to clean up the commits though -- not necessarily squashing into one commit, but at least into logical increments.
Hey @forsyth2 I mis-clicked re-requesting review. Please ignore... |
e32d19d
to
133f182
Compare
- Add configuration files for tools
- 5 files in `/analysis_data_preprocess/` could not be formatted due to parsing error
- Add FIXME for lines that need to be ignored. Some lines include # noqa to avoid flake8 qa - Update .pre-commit-config.yaml to run flake8
- Enable mypy in .pre-commit-config.yaml
- Fix`__init__.py` imports for complete test run - Add `settings.json` VSCode config file - Update line lengths to 88 - Ignore matplotlib and os.environ imports with isort to avoid clashing with existing order - Add flake8 `# noqa` to existing preprocessing files to ignore -- too many issues and old scripts
133f182
to
7328982
Compare
Resolved remaining PR issues, all tests and builds pass, and squashed. Merged! |
…rmatting-and-linting Add and apply formatters and linters to codebase
…rmatting-and-linting Add and apply formatters and linters to codebase
…rmatting-and-linting Add and apply formatters and linters to codebase
Description
This PR adds popular Python QA packages to the developer environment to improve the software's quality and developer workflow.
Summary of Changes
black
flake8
andisort
mypy
pre-commit
pre-commit
hooks: activate conda environment and runpre-commit install
.vscode/settings.json
file to share IDE configurations -- leverage tools and add editor rulerscomplete_run_v_2_3_0.py
due to missing__init__
filespython -m unittest tests/complete_run_v_2_3_0.py
, or it will complain aboutModuleNotFoundError
Why?
These tools will greatly increase the code quality of
e3sm_diags
by enforcing and automating project standards, even as the software scales and the number of contributors grow. For more information on these tools, please read my article: Git Pre-commit: Enforce and Automate Repository Standards at the Commit Level.How?
These tools were applied against the codebase to update the code style and catch PEP8 and static typing issues that were manually fixed/temporarily ignored. Please note, no code logic was changed in the process of formatting and linting so the code should run the exact same as
master
.I've also added the
pre-commit
package, which automates running these tools before everygit commit -m ...
. Docs will be updated in a new PR on how to set uppre-commit
.Example of
pre-commit
running tools on committed files. I didn't commit anything in this case. If a tool fails, then your commit won't go through, it outputs the error(s), and fixes the errors if it has that capability (e.g.black
andisort
). Otherwise if everything passes, your commit will go through as normal.Fixes # (issue)
Type of change
How to Review This PR
Since applying these tools produces diffs in many files, it will take a bit of time for review. As mentioned before, no code logic was changed so it shouldn't be hard to use the GitHub's 'Files Changed' tool to see the styling diffs. Most of the diffs are produced from line-length limit of 88, changing single quotes to double quotes (a
black
convention), andisort
sorting imports.List of Linting and Static Typing Issues Found and Fixed
isort
caught errors forI001
(import order).isort
automatically fixed to follow PEP8 import standard.flake8
caught PEP8 issues listed below:List of PEP8 error codes here
Most these issues have been fixed, except for F841 errors.
I've added
# FIXME
comments above these variables and# noqa
inline comment to make sureflake8
ignores the error.Example in
meridional_mean_2d_driver.py
Next action here is to review
# FIXME
comments and address these issues in a new PR.mypy
caught static type checking issues:error: Module has no attribute ...
error: could not determine type of ...
No overload variant of "__setitem__" of "list" matches argument types "int", "List[Any]"
"object" has no attribute "keys"
Some these issues were fixed, but most of them were ignored.
I've added
# FIXME
comments above these variables and# type: ignore
inline comment to make suremypy
ignores the error.Example in
enso_diags_parameter.py
Next action here is to review
# FIXME
comments and address these issues in a new PR.