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

Conflicting behavior of ruff isort rule for same file in different environments #15920

Closed
rashishhume opened this issue Feb 4, 2025 · 3 comments
Labels
isort Related to import sorting question Asking for support or clarification

Comments

@rashishhume
Copy link

rashishhume commented Feb 4, 2025

Description

I've noticed that ruff linter with isort enabled is behaving differently for me when running locally (in a Linux machine with Ubuntu) vs in a Github action runner (running ubuntu-latest).

Locally, its not happy about the lack of line between yaml and RcloneHelper.

$ ruff check --config ./pyproject.toml ./backup.py
backup2.py:5:1: I001 [*] Import block is un-sorted or un-formatted
   |
 3 |   """
 4 |
 5 | / import logging
 6 | | import os
 7 | | from typing import Annotated, List
 8 | |
 9 | | import typer
10 | | import yaml
11 | | from data_backup.rclone_helper import RcloneHelper
   | |__________________________________________________^ I001
12 |
13 |   logging.basicConfig(
   |
   = help: Organize imports

Found 1 error.

In a Github action runner its not happy with a line (ran below via tmate ssh session in the runner)

$ ruff check --config ./tools/data-backup/pyproject.toml ./tools/data-backup/backup.py
tools/data-backup/backup.py:5:1: I001 [*] Import block is un-sorted or un-formatted
   |
 3 |   """
 4 |
 5 | / import logging
 6 | | import os
 7 | | from typing import Annotated, List
 8 | |
 9 | | import typer
10 | | import yaml
11 | |
12 | | from data_backup.rclone_helper import RcloneHelper
   | |__________________________________________________^ I001
13 |
14 |   logging.basicConfig(
   |
   = help: Organize imports

Found 1 error.

My pyproject.toml is:

[tool.ruff]
line-length = 120
indent-width = 4

[tool.ruff.lint]
ignore = ["E203", "E501"]
extend-select = ["I"]

Any thoughts on what might be the issue here ?

@MichaReiser
Copy link
Member

The reason for the difference seems to be that Ruff once categorizes data_backup as first party (locally) and as third-party (GitHub) dependencies and it then tries to group it with the other first/third-party imports. You can run ruff with ruff check --verbose and it should log how imports are categorizes.

Now, the reason why I think Ruff once detects data_backup as first-party locally but not on GitHub is because you run ruff from different directories. Ruff defaults to treat ./ and ./src as first-party and everything else as third-party (see src.

Can you try running ruff in the tools/data-backup directory on GitHub, the same as you do locally and let me know if that helped?

@MichaReiser MichaReiser added question Asking for support or clarification isort Related to import sorting labels Feb 4, 2025
@rashishhume
Copy link
Author

Thanks @MichaReiser. That might be right. I tried changing the dir locally, and I see the same error as Github

$ ruff check --config ./research/tools/data-backup/pyproject.toml ./research/tools/data-backup/backup2.py
research/tools/data-backup/backup2.py:5:1: I001 [*] Import block is un-sorted or un-formatted
   |
 3 |   """
 4 |
 5 | / import logging
 6 | | import os
 7 | | from typing import Annotated, List
 8 | |
 9 | | import typer
10 | | import yaml
11 | |
12 | | from data_backup.rclone_helper import RcloneHelper
   | |__________________________________________________^ I001
13 |
14 |   logging.basicConfig(
   |
   = help: Organize imports

Found 1 error.
[*] 1 fixable with the `--fix` option.

@rashishhume
Copy link
Author

I was able to fix it by simply omitting the --config argument when invoking it in Github

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
isort Related to import sorting question Asking for support or clarification
Projects
None yet
Development

No branches or pull requests

2 participants