-
-
Notifications
You must be signed in to change notification settings - Fork 503
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
Add config for ruff #36503
Closed
Closed
Add config for ruff #36503
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
6283126
Add config for ruff
tobiasdiez 3a3a5ed
Merge branch 'develop' into ruff-vscode
tobiasdiez 8523cc6
Merge branch 'develop' into ruff-vscode
tobiasdiez 48ba573
Merge branch 'develop' into ruff-vscode
tobiasdiez 1170198
Merge branch 'develop' into ruff-vscode
tobiasdiez 8c1c34d
Merge branch 'develop' into ruff-vscode
tobiasdiez 11d563c
Merge branch 'develop' into ruff-vscode
tobiasdiez 4314ba5
Merge branch 'develop' into ruff-vscode
tobiasdiez 259f429
Put select and ignore in `lint` section to silence deprecation warning
tobiasdiez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[tool.ruff] | ||
# Assume Python 3.9 | ||
target-version = "py39" | ||
|
||
select = [ | ||
"E", # pycodestyle errors - https://docs.astral.sh/ruff/rules/#error-e | ||
"F", # pyflakes - https://docs.astral.sh/ruff/rules/#pyflakes-f | ||
"I", # isort - https://docs.astral.sh/ruff/rules/#isort-i | ||
"PL", # pylint - https://docs.astral.sh/ruff/rules/#pylint-pl | ||
] | ||
ignore = [ | ||
"E501", # Line too long - hard to avoid in doctests, and better handled by black. | ||
] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, no pyproject.toml in SAGE_ROOT.
SAGE_ROOT is not a Python package.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It applies to all python code (e.g. also the one in pkgs), so should be in the root. It's also quite common that the pyproject config is in the root, but the actual code in a subfolder. eg https://github.com/scipy/scipy/blob/main/pyproject.toml or https://github.com/pandas-dev/pandas/blob/main/pyproject.toml
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, that's not how the Sage repository is structured. Again, SAGE_ROOT is not the source directory of a Python package (distribution)... which is why there is no setup.py, no pyproject.toml, no setup.cfg, etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How is that different from scipy?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The source directory of the Python distribution package scipy (per PEP 518, PEP 621, the location of the
pyproject.toml
file) is the root of its repository https://github.com/scipy/scipy/tree/mainThe source directory of the Python distribution package sagemath-standard is not the root of the repository https://github.com/sagemath/sage (= SAGE_ROOT), but rather
src/
. As I know that you know, this is where you findsrc/pyproject.toml
,src/setup.py
, etc.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's the very idea of pyproject.toml. It marks the top of a Python distribution package (= project). That's what "py" and "project" refer to in the name of this file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copying the config 4 times is already too much for my taste. Thanks for the suggestion, but I'll not implement it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So do ruff.toml, as I explained.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've tried that but couldn't make it work reliable. For some files it just doesn't seem to work (although, I agree, that the docs claim that ruff.toml and pyproject.toml are equivalent). As a starter, you need to put the config in the root so that it applies to all python files in all directories. Moreover, it sometimes just didn't apply the config when reformatting a file - not sure if it's a problem with ruff or vscode, or something else. My guess is that the somewhat strange directory layout with a pyproject.toml in src is resulting in hick ups.
Since the config in the root pyproject.toml worked exellently for me, I stopped investigating. The added pyproject.toml in the root doesn't cause any other issues, is helpful in other contexts as well (eg #37446) and
pip install .
will work correctly with #36524.Sorry, should have let you know before you invested the time to prepare #37452.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a very narrow viewpoint. Multiple tools support non-distribution/non-package scenarios via
pyproject.toml
, see eg https://python-poetry.org/docs/basic-usage#operating-modes. In https://discuss.python.org/t/projects-that-arent-meant-to-generate-a-wheel-and-pyproject-toml/29684/5 a Cpython core developer addressed the concern that pyproject.toml indicates that code which will be installed as a distribution as follows:In the same thread, another Cpython core developer answers the question "if a project (in the broadest possible sense of the term) is not intended to be built into a wheel, is pyproject.toml an appropriate place to store project-level configuration?" with
According to this viewpoint, since I don't add a
project
section, thepyproject.toml
in the root does not function as a indicator for a distribution package and it's perfectly fine to add tool configs there.