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

Ruff: smaller steps #364

Merged
merged 34 commits into from
Sep 25, 2024
Merged

Ruff: smaller steps #364

merged 34 commits into from
Sep 25, 2024

Conversation

rcomer
Copy link
Member

@rcomer rcomer commented May 3, 2023

🚀 Pull Request

Description

SciTools/iris#353 proposed introducing ruff to cf-units for linting, but also changed some style choices (max line length and import sort order). IMO this made it difficult to spot what effect ruff was having on the code. This PR breaks it down so hopefully it's easier to see what's going on:

  • First commit takes the config file changes from Define test structure iris#353
  • Second commit reinstates the previous style choices in the config
  • Third commit shows ruff's autofixes. The majority of these modernise the string formatting, but there are also
    • removals of things that became redundant when we dropped python2
    • change dictionary creation from dict(...) to {...} - maybe for speed?
    • change if thing == None to if thing is None - I'm surprised flake8 didn't catch that one

CI will fail with remaining problems that ruff found:

  • Some of our comment lines are longer than 79 characters
  • In the tests we touch an object's attribute but don't get hold of it and use it after, which seems to be correct in context but the linter can't tell that

@bjlittle
Copy link
Member

bjlittle commented May 3, 2023

@rcomer Thanks for this 🚀

I was waiting for SciTools/iris#5254 to conclude, then reopen SciTools/iris#353, but totally happy to replace it with this 👍

@rcomer
Copy link
Member Author

rcomer commented Nov 13, 2023

Rebased, updated the ruff version and replaced black with ruff's formatter.

Swapping black for ruff's formatter only affects one line, shown in the most recent commit.

We now have more failures and fewer autofixes from main ruff. I think because some fixes that were previously done automatically are now marked "unsafe" so we would need to manually opt in (see https://astral.sh/blog/ruff-v0.1.0#respecting-fix-safety).

@rcomer rcomer marked this pull request as ready for review November 14, 2023 17:06
@rcomer
Copy link
Member Author

rcomer commented Nov 14, 2023

I applied the "unsafe" fixes but then tweaked a few that didn't look quite right to me. Also tidied up the remaining errors so I think this is now ready for review.

Unlike most of my branches, the individual commits here may be meaningful enough to review individually.

@pp-mo
Copy link
Member

pp-mo commented Nov 15, 2023

@SciTools/peloton would you be interested in taking this on, @tkknight ?
We think you expressed interest in getting this one in before the Iris one, and that @bjlittle is unlikely to find time right now.

pelson
pelson previously approved these changes Feb 25, 2024
Copy link
Member

@pelson pelson left a comment

Choose a reason for hiding this comment

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

Looks like a good improvement to me.

(I doubt I will get a chance to follow-up, but hopefully my review moves the PR forwards 😉

cf_units/__init__.py Show resolved Hide resolved
cf_units/__init__.py Show resolved Hide resolved
cf_units/tests/integration/parse/test_parse.py Outdated Show resolved Hide resolved
cf_units/tests/integration/parse/test_parse.py Outdated Show resolved Hide resolved
cf_units/tests/test_coding_standards.py Outdated Show resolved Hide resolved
cf_units/util.py Show resolved Hide resolved
pyproject.toml Show resolved Hide resolved
Copy link
Member Author

@rcomer rcomer left a comment

Choose a reason for hiding this comment

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

Thanks @pelson - great to hear from you again! I will follow up more when I am back on my work machine.

cf_units/__init__.py Show resolved Hide resolved
cf_units/tests/test_coding_standards.py Outdated Show resolved Hide resolved
pyproject.toml Show resolved Hide resolved
@rcomer
Copy link
Member Author

rcomer commented Feb 26, 2024

New commit dismissed an approving review. Not seen that before 😕

pyproject.toml Outdated Show resolved Hide resolved
pelson
pelson previously approved these changes Feb 27, 2024
@bjlittle bjlittle self-assigned this Feb 28, 2024
Copy link
Contributor

@stephenworsley stephenworsley left a comment

Choose a reason for hiding this comment

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

Since it's taken us a while to get to this PR, the versions here have become a bit stale. We should have time to focus on cf-units this week, so if you respin this PR with newer versions and resolve merge conflicts, we ought to be able to get this reviewed and merged in.

pyproject.toml Outdated Show resolved Hide resolved
.pre-commit-config.yaml Outdated Show resolved Hide resolved
@rcomer
Copy link
Member Author

rcomer commented Sep 24, 2024

Hi @stephenworsley thanks for taking a look. I’m afraid I do not know if I will get to this this week. If anyone wants to push to my branch to get it through sooner, please do.

stephenworsley and others added 20 commits September 24, 2024 14:01
* main:
  [pre-commit.ci] pre-commit autoupdate (SciTools#425)
  Adopt cython3 (require >=3) (SciTools#460)
  Add repo-review (SciTools#456)
  Fully support Python 3.12 (SciTools#461)
  Bump peter-evans/create-pull-request from 6.0.4 to 7.0.5 (SciTools#459)
  Fix for bad git path in GHA macos instances. (SciTools#464)
  test macos wheels (SciTools#458)
  Bump pypa/cibuildwheel from 2.20.0 to 2.21.1 (SciTools#457)
  Fixes for CI wheels (SciTools#455)
  Dependabot check weekly. (SciTools#439)

# Conflicts:
#	.pre-commit-config.yaml
#	cf_units/tests/test_coding_standards.py
#	pyproject.toml
* rcomer/ruff:
  [pre-commit.ci] auto fixes from pre-commit.com hooks
* rcomer/ruff:
  [pre-commit.ci] auto fixes from pre-commit.com hooks
* rcomer/ruff:
  [pre-commit.ci] auto fixes from pre-commit.com hooks

# Conflicts:
#	cf_units/tests/test_coding_standards.py
* rcomer/ruff:
  [pre-commit.ci] auto fixes from pre-commit.com hooks
Copy link

@ESadek-MO ESadek-MO left a comment

Choose a reason for hiding this comment

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

I'm happy with your changes @stephenworsley, I'll leave you to check the rest of the PR.

Copy link
Contributor

@stephenworsley stephenworsley left a comment

Choose a reason for hiding this comment

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

I believe this should be good now.

@stephenworsley stephenworsley merged commit d758886 into SciTools:main Sep 25, 2024
14 checks passed
@rcomer rcomer deleted the ruff branch September 25, 2024 19:46
stephenworsley added a commit to stephenworsley/cf-units that referenced this pull request Sep 27, 2024
* main:
  [DOCS] Update docstring for date2num (module function) (SciTools#483)
  Modernise setup scripts (SciTools#484)
  Make antlr optional (SciTools#423)
  Ruff: smaller steps (SciTools#364)
  Updated docstring for num2date. (SciTools#467)
  updated conda lock files (SciTools#479)
  Revert to 00:03 Mondays for lockfile updates. (SciTools#480)
  New trigger time for GMT. (SciTools#478)
  Check lockfile updates @ 3pm daily (temporary for testing). (SciTools#477)
  Fixlocks (SciTools#470)

# Conflicts:
#	pyproject.toml
#	requirements/cf-units.yml
#	requirements/locks/py310-lock-linux-64.txt
#	requirements/locks/py310-lock-osx-64.txt
#	requirements/locks/py310-lock-win-64.txt
#	requirements/locks/py311-lock-linux-64.txt
#	requirements/locks/py311-lock-osx-64.txt
#	requirements/locks/py311-lock-win-64.txt
#	requirements/locks/py312-lock-linux-64.txt
#	requirements/locks/py312-lock-osx-64.txt
#	requirements/locks/py312-lock-win-64.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

7 participants