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

chore: replace black, isort, absolufy-imports with ruff #328

Merged
merged 3 commits into from
Jul 18, 2024
Merged

chore: replace black, isort, absolufy-imports with ruff #328

merged 3 commits into from
Jul 18, 2024

Conversation

afuetterer
Copy link
Contributor

@afuetterer afuetterer commented Jul 17, 2024

PyPSA already uses ruff via pre-commit:
https://github.com/PyPSA/PyPSA/blob/master/.pre-commit-config.yaml

I replaced the tooling.

There are a few issues.

$ ruff check --statistics
202     UP007   [*] non-pep604-annotation
 93     UP006   [*] non-pep585-annotation
 82     F821    [ ] undefined-name
 22     F401    [ ] unused-import
 21     NPY002  [ ] numpy-legacy-random
 21     UP035   [ ] deprecated-import
 12     I001    [*] unsorted-imports
  8     W291    [*] trailing-whitespace
  6     E703    [*] useless-semicolon
  4     E712    [*] true-false-comparison
  3     F841    [*] unused-variable
  1     F601    [ ] multi-value-repeated-key-literal

@afuetterer
Copy link
Contributor Author

I think this step can go as well:

- name: Lint with flake8

Copy link

codecov bot commented Jul 17, 2024

Codecov Report

Attention: Patch coverage is 96.06299% with 5 lines in your changes missing coverage. Please review.

Project coverage is 86.00%. Comparing base (c6564a8) to head (dd0e54e).
Report is 5 commits behind head on master.

Files Patch % Lines
linopy/solvers.py 66.66% 2 Missing ⚠️
linopy/constraints.py 87.50% 0 Missing and 1 partial ⚠️
linopy/remote.py 0.00% 1 Missing ⚠️
linopy/variables.py 97.22% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #328      +/-   ##
==========================================
+ Coverage   85.95%   86.00%   +0.04%     
==========================================
  Files          17       17              
  Lines        4202     4209       +7     
  Branches      988      989       +1     
==========================================
+ Hits         3612     3620       +8     
+ Misses        431      430       -1     
  Partials      159      159              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@FabianHofmann
Copy link
Collaborator

Great! Still some issues in the benchmark folder with pre-commit https://results.pre-commit.ci/run/github/350276805/1721223837.ZE-YcKwTRuaSNDuB4ykaXA, we can either ignore that folder or quickly fix these

@FabianHofmann
Copy link
Collaborator

I think this step can go as well:

- name: Lint with flake8

sure

@afuetterer
Copy link
Contributor Author

Great! Still some issues in the benchmark folder with pre-commit https://results.pre-commit.ci/run/github/350276805/1721223837.ZE-YcKwTRuaSNDuB4ykaXA, we can either ignore that folder or quickly fix these

Maybe ignore F821 (snakemake is undefined)?

@FabianHofmann
Copy link
Collaborator

Great! Still some issues in the benchmark folder with pre-commit https://results.pre-commit.ci/run/github/350276805/1721223837.ZE-YcKwTRuaSNDuB4ykaXA, we can either ignore that folder or quickly fix these

Maybe ignore F821 (snakemake is undefined)?

sure!

@afuetterer
Copy link
Contributor Author

afuetterer commented Jul 17, 2024

$ ruff check --statistics
21      NPY002  numpy-legacy-random
 5      F821    undefined-name
 1      F401    unused-import
 1      F601    multi-value-repeated-key-literal

@afuetterer
Copy link
Contributor Author

Which scip is relevant in this test? They can't both be used. Is this a typo?

"scip": {"time_limit": 1},
"xpress": {"maxtime": 1},
"highs": {"time_limit": 1},
"scip": {"limits/time": 1},

@FabianHofmann
Copy link
Collaborator

Which scip is relevant in this test? They can't both be used. Is this a typo?

"scip": {"time_limit": 1},
"xpress": {"maxtime": 1},
"highs": {"time_limit": 1},
"scip": {"limits/time": 1},

oh honestly, only one (ideally the correct one ;) ) should be used

@afuetterer
Copy link
Contributor Author

Fabian Hofmann committed on Sep 19, 2023. :)
I guess the second (came later), will be the correct one.

@afuetterer
Copy link
Contributor Author

$ ruff check --statistics
5       F821    undefined-name
1       F401    unused-import
1       F601    multi-value-repeated-key-literal

@lkstrp
Copy link
Member

lkstrp commented Jul 18, 2024

Could you also add a .git-blame-ignore-revs, similar as in PyPSA?
You can get a list of all pre-commit hashes via:

git log --pretty=format:'%H' --regexp-ignore-case --grep="auto fixes from pre-commit.com hooks"

And maybe don't squash this, so we keep those ruff changes separated.

The F841 leftovers I would just skip with a #noqa.

F401 I would just fix by adding it to __all__. Or is linopy.monkey_patch_xarray needed in the external API @FabianHofmann ?

@FabianHofmann
Copy link
Collaborator

F401 I would just fix by adding it to __all__. Or is linopy.monkey_patch_xarray needed in the external API @FabianHofmann ?

You mean whether the user should be able to import it? No, that not, but the module should internally be run when importing linopy. (hope I got your point)

@lkstrp
Copy link
Member

lkstrp commented Jul 18, 2024

Makes sense. Then it's a #noqa as well

@afuetterer
Copy link
Contributor Author

Alright.

I will squash all ruff commits and add the one commit to .git-blame-ignore-revs?

So, you get 3 commits to merge, 1 commit adds the rule, 1 commit applies the rules and changes a lot of files, 1 commit adds the .git-blame-ignore-revs. Is that correct?

@FabianHofmann
Copy link
Collaborator

@afuetterer great work as always! just some minor things remaining where pre-commit complains, should be a quick thing to do, perhaps @lkstrp can also do it :)

@afuetterer
Copy link
Contributor Author

Let me fix it quickly.

@afuetterer
Copy link
Contributor Author

$ ruff check --statistics
2       F841    [*] unused-variable

ruff wants to remove the m in
m = n.lopf(solver_options=SOLVER_PARAMS, pyomo=False, solver_name=SOLVER).

@lkstrp
Copy link
Member

lkstrp commented Jul 18, 2024

$ ruff check --statistics
2       F841    [*] unused-variable

ruff wants to remove the m in m = n.lopf(solver_options=SOLVER_PARAMS, pyomo=False, solver_name=SOLVER).

Just add #noqa as well. They are needed for the benchmarks and it's better than inflating pyproject.toml.

As always, thanks a lot @afuetterer !

@afuetterer
Copy link
Contributor Author

This should be it.

Copy link
Member

@lkstrp lkstrp left a comment

Choose a reason for hiding this comment

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

Beautiful!

@lkstrp lkstrp merged commit f252fde into PyPSA:master Jul 18, 2024
16 checks passed
@afuetterer afuetterer deleted the ruff branch July 18, 2024 13:21
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.

3 participants