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

adopt ruff #353

Closed
wants to merge 1 commit into from
Closed

adopt ruff #353

wants to merge 1 commit into from

Conversation

bjlittle
Copy link
Member

@bjlittle bjlittle commented Apr 18, 2023

🚀 Pull Request

Description

This PR adopts ruff and drops the explicit use of isort and flake8.

Running ruff across the codebase rediscovers a whole collections of exceptions that clearly have been missed for flake8 et al compliance.

@rcomer
Copy link
Member

rcomer commented Apr 18, 2023

Lots of style changes here. Is it worth adding a .git-blame-ignore-revs?

only_use_cftime_datetimes=only_use_cftime_datetimes,
only_use_python_datetimes=only_use_python_datetimes,
)
has_half_seconds = np.logical_and(time_units == "seconds", time_values % 1.0 == 0.5)
Copy link
Member

Choose a reason for hiding this comment

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

Seems like ruff is overriding black here. Maybe we shouldn't use both?

cf-units/pyproject.toml

Lines 48 to 49 in cf4d66d

[tool.black]
line-length = 79

Copy link
Member

@rcomer rcomer Apr 18, 2023

Choose a reason for hiding this comment

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

Actually it looks like a lot of the changes in this PR are just increasing the allowed line length. Maybe it would be better to tell ruff to keep to 79 characters. I've no objection in general to an 88 character limit, but it might be good to separate concerns of tool choices vs style choices. Line limit could be increased as a follow-up PR.

Copy link
Member

Choose a reason for hiding this comment

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

Looks like you just need a couple of lines in the pyproject.toml to reduce the character limit

[tool.ruff]

line-length = 79

I'd be interested to see how much smaller that makes the diff, and it might help inform the discussion at SciTools/iris#5254. Looks like a lot of the other changes are introducing f-strings to replace old-style string formatting, which seems fair enough.

Copy link
Member

Choose a reason for hiding this comment

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

Seems like ruff is overriding black here. Maybe we shouldn't use both?

cf-units/pyproject.toml

Lines 48 to 49 in cf4d66d

[tool.black]
line-length = 79

I've have wondered before whether we are using overlapping tools. I think there is scope for black to disagree with flake8 ?

Copy link
Member

Choose a reason for hiding this comment

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

Ruff docs say they are compatible with black provided the line lengths are set the same.
https://beta.ruff.rs/docs/faq/#is-ruff-compatible-with-black

"calendar": unit.calendar,
"only_use_cftime_datetimes": only_use_cftime_datetimes,
"only_use_python_datetimes": only_use_python_datetimes,
}
Copy link
Member

Choose a reason for hiding this comment

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

I'm curious about why this is the preferred form for specifying a dictionary.

Copy link
Member

Choose a reason for hiding this comment

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

Huh. Maybe this is why

In [5]: %timeit x = {"a":1, "b":2}
70.2 ns ± 1.32 ns per loop (mean ± std. dev. of 7 runs, 10,000,000 loops each)

In [6]: %timeit x = dict(a=1, b=2)
119 ns ± 2.61 ns per loop (mean ± std. dev. of 7 runs, 10,000,000 loops each)

@trexfeathers
Copy link
Collaborator

I really didn't want to get involved here but based on @rcomer's comments I think we need a team discussion. I think we can all agree that we don't want inconsistency between our repos, so adopting ruff for cf-units would therefore create an implicit goal to use it for all our repos, and that's a big decision.

@bjlittle bjlittle closed this Apr 18, 2023
)
raise TypeError(emsg)
Copy link
Member

Choose a reason for hiding this comment

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

This refactor seems more clever than black 🤔

rcomer added a commit to rcomer/cf-units that referenced this pull request May 3, 2023
@rcomer rcomer mentioned this pull request May 3, 2023
rcomer added a commit to rcomer/cf-units that referenced this pull request Nov 13, 2023
rcomer added a commit to rcomer/cf-units that referenced this pull request Feb 26, 2024
rcomer added a commit to rcomer/cf-units that referenced this pull request May 8, 2024
stephenworsley added a commit that referenced this pull request Sep 25, 2024
* config changes from #353

* keep existing line length and import sort order

* remove flake8 config

* Drop black; update ruff version and add formatter

* ruff autofixes

* ruff formatter fix

* ruff 'unsafe' autofixes

* Ruth fixes for unsafe fixes

* re-run ruff formatter

* Manually address E501 and B018

* point to astral-sh organisation; tidy some broken strings

* review actions

* update ruff-pre-commit version

* fix pyproject.toml

* fix pyproject.toml

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* ruff fixes

* fix parantheses

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* more lint fixes

* linting + pre-commit fixes

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* linting + pre-commit fixes

* fix test

* revert ruff fix

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* ignore generated code

* remove redundant ignore

---------

Co-authored-by: stephen.worsley <stephen.worsley@metoffice.gov.uk>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: stephenworsley <49274989+stephenworsley@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants