astral-sh / rye

a Hassle-Free Python Experience
https://rye.astral.sh
MIT License
13.78k stars 468 forks source link

"rye lint --fix" fails #1414

Open pcarinhas opened 1 week ago

pcarinhas commented 1 week ago

Steps to Reproduce

  1. Install new rye : in this case 0.41.0
  2. Create new project: a. source "$HOME/.rye/env" b. cd /tmp/ c. rye init junk; cd junk
  3. edit src/junk/init.py and add a useless import like "import pytz"
  4. Execute rye lint: a. rye lint b. rye lint --fix

Expected Result

Rye should both:

  1. recognize the error and offer "rye lint --fix" as an option (it does not)
  2. When specify --fix, it should fix the problem, which it does not.

Actual Result

:/tmp/junk]: rye lint
src/junk/__init__.py:1:8: F401 `pytx` imported but unused
  |
1 | import pytx
  |        ^^^^ F401
2 |
3 | def main() -> int:
  |
  = help: Remove unused import: `pytx`

Found 1 error.

and

:/tmp/junk]: rye lint --fix
src/junk/__init__.py:1:8: F401 `pytx` imported but unused
  |
1 | import pytx
  |        ^^^^ F401
2 |
3 | def main() -> int:
  |
  = help: Remove unused import: `pytx`

Found 1 error.

Version Info

:/tmp/junk]: rye --version rye 0.41.0 commit: 0.41.0 (10d691d16 2024-09-29) platform: linux (x86_64) self-python: cpython@3.12.6 symlink support: true uv enabled: true

Stacktrace

No response

pcarinhas commented 1 week ago

Also, running with -v:

:/tmp/junk]: rye lint --fix -v
[2024-10-13][15:42:25][ruff::resolve][DEBUG] Using Ruff default settings
[2024-10-13][15:42:25][ignore::walk][DEBUG] ignoring /tmp/junk/.venv: Ignore(IgnoreMatch(Gitignore(Glob { from: Some("/tmp/junk/.gitignore"), original: ".venv", actual: "**/.venv", is_whitelist: false, is_only_dir: false })))
[2024-10-13][15:42:25][ruff_workspace::resolver][DEBUG] Ignored path via `exclude`: "/tmp/junk/.ruff_cache"
[2024-10-13][15:42:25][ruff_workspace::resolver][DEBUG] Included path via `include`: "/tmp/junk/src/junk/__init__.py"
[2024-10-13][15:42:25][ruff_workspace::resolver][DEBUG] Included path via `include`: "/tmp/junk/pyproject.toml"
[2024-10-13][15:42:25][ruff_workspace::resolver][DEBUG] Ignored path via `exclude`: "/tmp/junk/.git"
[2024-10-13][15:42:25][ruff::commands::check][DEBUG] Identified files to lint in: 5.755612ms
[2024-10-13][15:42:25][ruff::diagnostics][DEBUG] Checking: /tmp/junk/src/junk/__init__.py
[2024-10-13][15:42:25][ruff::diagnostics][DEBUG] Checking: /tmp/junk/pyproject.toml
[2024-10-13][15:42:25][ruff_linter::rules::isort::categorize][DEBUG] Categorized 'pytz' as Known(ThirdParty) (NoMatch)
[2024-10-13][15:42:25][ruff::commands::check][DEBUG] Checked 2 files in: 371.453µs
src/junk/__init__.py:1:8: F401 `pytz` imported but unused
  |
1 | import pytz
  |        ^^^^ F401
2 |
3 | def hello() -> str:
  |
  = help: Remove unused import: `pytz`

Found 1 error.
pcarinhas commented 1 week ago

I tried using ruff directly from the .rye distribution and it also fails. So this may be a ruff issue:

~/.rye/self/bin]: ./ruff check --fix --fixable "F401" /tmp/junk/
/tmp/junk/src/junk/__init__.py:1:8: F401 `goodies` imported but unused
  |
1 | import goodies
  |        ^^^^^^^ F401
  |
  = help: Remove unused import: `goodies`

Found 1 error.

This also fails if I remove the --fixable option too.

InSyncWithFoo commented 4 days ago

This is probably by design; fixes for F401 in __init__.py files are unsafe.