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

Standardise ruff config #15558

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Conversation

calumy
Copy link
Contributor

@calumy calumy commented Jan 17, 2025

Summary

Follow up to #15544 and #15544 (review) to move the Ruff config used in scripts into the pyproject.toml in the root directory now that Python scripts are being added outwith the scripts directory.

Only changes required relate to line length. I have updated to split at 88 characters; however, if a noqa would be better in this instance, please let me know, and I can update.

Test Plan

@calumy calumy requested a review from MichaReiser as a code owner January 17, 2025 21:00
@calumy calumy marked this pull request as draft January 17, 2025 21:09
@calumy
Copy link
Contributor Author

calumy commented Jan 17, 2025

The test failure appears to be from the display_default_settings test relying on the pyproject.toml config in the root directory for its default values. I think there are a couple of ways to fix this (potentially more):

  • Update the display_default_settings snapshot to include the now updated settings
  • Update the test to continue to use the default settings by updating the pyproject.toml file used in the test

I would appreciate some guidance on how best to approach a fix.

@AlexWaygood
Copy link
Member

  • Update the display_default_settings snapshot to include the now updated settings

This is what we've done in the past whenever we've updated the pyproject.toml settings :-) it's a bit silly but it's easy

Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

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

Thank you!

pyproject.toml Outdated Show resolved Hide resolved
pyproject.toml Outdated Show resolved Hide resolved
@@ -58,23 +58,44 @@ include = [
]

[tool.ruff]
target-version = "py39"
Copy link
Member

Choose a reason for hiding this comment

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

Some of our scripts require newer Python versions than this, but this seems fine

Copy link
Contributor Author

@calumy calumy Jan 17, 2025

Choose a reason for hiding this comment

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

Most scripts do; however, https://github.com/astral-sh/ruff/blob/main/python/ruff/__main__.py#L17 assumes that less than 3.10 may be used, so I went for the lowest currently supported Python version.

Ref: https://devguide.python.org/versions/

Copy link
Member

Choose a reason for hiding this comment

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

This should be Py38 then.

Suggested change
target-version = "py39"
target-version = "py38"

@AlexWaygood AlexWaygood added the internal An internal refactor or improvement label Jan 17, 2025
@calumy calumy force-pushed the standardise-ruff-config branch from 4bc1471 to 04c99dd Compare January 17, 2025 22:20
@calumy calumy marked this pull request as ready for review January 17, 2025 22:23
Copy link
Contributor

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Formatter (stable)

ℹ️ ecosystem check encountered format errors. (no format changes; 1 project error)

openai/openai-cookbook (error)

warning: Detected debug build without --no-cache.
error: Failed to read examples/Assistants_API_overview_python.ipynb: Expected a Jupyter Notebook, which must be internally stored as JSON, but this file isn't valid JSON: expected `,` or `]` at line 197 column 8

Formatter (preview)

ℹ️ ecosystem check encountered format errors. (no format changes; 1 project error)

openai/openai-cookbook (error)

ruff format --preview

warning: Detected debug build without --no-cache.
error: Failed to read examples/Assistants_API_overview_python.ipynb: Expected a Jupyter Notebook, which must be internally stored as JSON, but this file isn't valid JSON: expected `,` or `]` at line 197 column 8

@@ -72,10 +71,156 @@ file_resolver.project_root = "[BASEPATH]"
linter.exclude = []
linter.project_root = "[BASEPATH]"
linter.rules.enabled = [
unary-prefix-increment-decrement (B002),
Copy link
Member

@MichaReiser MichaReiser Jan 18, 2025

Choose a reason for hiding this comment

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

I think we have to fix this test to be isolated from our own pyproject.toml. It otherwise becomes very annoying because it requires updating whenever we add or remove a rule from any enabled category.

Comment on lines +177 to +178
f"{group.owned_enum_ty}::{node.variant}(node) => "
"node.visit_source_order(visitor),"
Copy link
Member

Choose a reason for hiding this comment

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

Splitting this over multiple line decreases readability. I suggest disabling E501 and keep it as regular string.

extend-exclude = [
"crates/red_knot_vendored/vendor/",
"crates/ruff/resources/",
"crates/ruff_linter/resources/",
"crates/ruff_python_formatter/resources/",
"crates/ruff_python_parser/resources/"
]
line-length = 88
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
line-length = 88

This is the default

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
internal An internal refactor or improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants