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

Flake8 to ruff #2630

Merged
merged 8 commits into from
Jan 27, 2023
Merged

Flake8 to ruff #2630

merged 8 commits into from
Jan 27, 2023

Conversation

Saransh-cpp
Copy link
Member

Description

Tried ruff locally, and it really is super fast!

I also tried migrating some of the metadata to pyproject.toml, but I ended up with a lot of errors (given that pyproject.toml support is still very new and maybe in the beta phase in setuptools.)

Some false alarm examples that are being ignored using pyproject.toml -

pybamm/parameters/__init__.py:5:5: F401 `.process_parameter_data.process_3D_data_csv` imported but unused

pybamm/solvers/jax_bdf_solver.py:293:9: E741 Ambiguous variable name: `I`

tests/__init__.py:15:101: E501 Line too long (106 > 100 characters)  # not a false alarm, but the import names can get lengthy sometimes in the __init__ files

pybamm/__init__.py:61:1: F403 `from .expression_tree.symbol import *` used; unable to detect undefined names

pybamm/__init__.py:235:1: E402 Module level import not at top of file

Fixes #2623

Type of change

Please add a line in the relevant section of CHANGELOG.md to document the change (include PR #) - note reverse order of PR #s. If necessary, also add to the list of breaking changes.

  • New feature (non-breaking change which adds functionality)
  • Optimization (back-end change that speeds up the code)
  • Bug fix (non-breaking change which fixes an issue)

Key checklist:

  • No style issues: $ flake8
  • All tests pass: $ python run-tests.py --unit
  • The documentation builds: $ cd docs and then $ make clean; make html

You can run all three at once, using $ python run-tests.py --quick.

Further checks:

  • Code is commented, particularly in hard-to-understand areas
  • Tests added that prove fix is effective or that feature works

@Saransh-cpp
Copy link
Member Author

At the moment, ruff only supports pyproject.toml and the CLI for listing down its configuration.

@Saransh-cpp
Copy link
Member Author

PyBaMM does not like pyproject.toml at all, and ruff does not like tox.ini. I have switched formatting to pre-commit, which means that pre-commit will automatically handle everything related to ruff -

saransh@Saranshs-MacBook-Air PyBaMM % pre-commit run --all-files 
prettier.................................................................Passed
black....................................................................Passed
ruff.....................................................................Passed

(will run automatically whenever a commit is created locally)

However, if someone wants to only run ruff and not the other pre-commits, they will have to run it in the following way (so that ruff follows the specified configuration) -

pre-commit run ruff

CONTRIBUTING.md Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Jan 27, 2023

Codecov Report

Base: 99.69% // Head: 99.69% // Decreases project coverage by -0.01% ⚠️

Coverage data is based on head (3359e13) compared to base (932a133).
Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #2630      +/-   ##
===========================================
- Coverage    99.69%   99.69%   -0.01%     
===========================================
  Files          271      271              
  Lines        19571    19570       -1     
===========================================
- Hits         19511    19510       -1     
  Misses          60       60              
Impacted Files Coverage Δ
pybamm/__init__.py 100.00% <ø> (ø)
pybamm/input/parameters/lead_acid/Sulzer2019.py 100.00% <ø> (ø)
pybamm/input/parameters/lithium_ion/Ai2020.py 100.00% <ø> (ø)
...i2020/graphite_entropy_Enertech_Ai2020_function.py 100.00% <ø> (ø)
pybamm/util.py 100.00% <ø> (ø)
pybamm/discretisations/discretisation.py 99.78% <100.00%> (ø)
pybamm/solvers/casadi_solver.py 99.66% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Member

@valentinsulzer valentinsulzer left a comment

Choose a reason for hiding this comment

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

Thanks @Saransh-cpp , that was fast! I think this way with .pre-commit-config.yaml is a good compromise. Approval from me but will wait a bit to see if @priyanshuone6 has any suggestions

Copy link
Member

@priyanshuone6 priyanshuone6 left a comment

Choose a reason for hiding this comment

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

Looks good! It's nice that it has an 88 character limit by default, and we don’t need to specify every time.

@valentinsulzer valentinsulzer merged commit 29ff828 into develop Jan 27, 2023
@valentinsulzer valentinsulzer deleted the flake8-to-ruff branch January 27, 2023 16:46
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.

Switch linting to ruff
3 participants