-
Notifications
You must be signed in to change notification settings - Fork 224
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
Use ruff format to ensure UNIX line endings in Python files #2770
Conversation
Automatically convert line endings in Python files to `\n` (UNIX style). Requires using beta version of Ruff formatter in v0.1.2. Also sorting ruff sections in pyproject.toml alphabetically.
Some deviations between the black and ruff linters on where to place inline comments.
/format |
See example commit at 22b194c triggered by #2770 (comment) where the CRLF line-endings were converted to LF endings. |
There are some warnings about tab-indentation (W191) from running
See also upstream issue at astral-sh/ruff#8185, these warnings might go away with astral-sh/ruff#8196 🤞 |
If I understand it correctly,
|
Ah ok, I was under the impression that Btw, I could only get the UNIX line formatting to work with Edit: It seems like there is some thought towards unifying the linter and formatter in one command - astral-sh/ruff#8232. Gonna mark this as draft first. |
Instead of waiting for the upstream change about linter/formatter, maybe we should go ahead and follow the current ruff documentation and use |
Run the linter `ruff check`, then the formatter `ruff format`.
Ok, done in 6076a50. Now we run the linter
|
@@ -99,14 +99,17 @@ select = [ | |||
] |
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.
See https://docs.astral.sh/ruff/configuration/.
select
should be in the [tool.ruff.lint]
section and [tool.ruff.per-file-ignores]
should be [tool.ruff.lint.per-file-ignores]
.
I think it also make sense to sort the section by the following order:
[tool.ruff]
[tool.ruff.lint]
[tool.ruff.lint.per-file-ignores]
[tool.ruff.format]
# tool-specific configurations
[tool.ruff.isort]
[tool.ruff.pycodestyle]
We probably also want to require ruff>=0.1.3.
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.
Hmm, did they change the TOML config settings recently? I see pycodestyle is now under tool.ruff.lint.pycodestyle
, and isort is under tool.ruff.lint.isort
. Let me fix these up.
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.
Done in 8c58089.
Oh, and just on this, we could remove |
Most of ruff's lint rules are now under tool.ruff.lint, so rearranging things a bit.
Sounds good to me. I also removed 'CI' from the PR title, because the changes are not directly related to CI. |
Description of proposed changes
Automatically convert line endings in Python files to
\n
(UNIX style). Requires using beta version of Ruff formatter in v0.1.2, see https://astral.sh/blog/the-ruff-formatter.We've actually been using
dos2unix
to do the line ending checks since #736, but not to do the actual formatting, probably becausedos2unix
is a little trickier to install on Windows (?). Usingruff
though is a little easier since we can install it with pip/conda-forge.Caveats:
ruff
looks at, and not non-Python files like the .rst, .yml, .md filesPartially addresses #736 (comment)
Reminders
make format
andmake check
to make sure the code follows the style guide.doc/api/index.rst
.Slash Commands
You can write slash commands (
/command
) in the first line of a comment to performspecific operations. Supported slash commands are:
/format
: automatically format and lint the code/test-gmt-dev
: run full tests on the latest GMT development version