-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Folder with module name detected as source leads to false I001
error
#10519
Comments
I001
error
We could consider requiring an |
I see how a folder that is now correctly categorized as a source folder might not have an If a source folder is required to contain any If somebody could point me to the relevant source code, I could try and work on a PR. |
Shouldn't the removal of the wandb directory be enough to invalidate the module categorization cache? The fact that you need to manually remove the cache to get the correct results also seems wrong. |
Diagnostics are cached on a per-file basis, where the "file" is the file in which the diagnostic is present. Changing other files on the filesystem doesn't invalidate the cache. Changing the settings will also invalidate the cache. So if you add |
Say you were using a third party package in your requirements, but decided later to vendor it to make changes, turning it into a first party package. Then unless caches were manually cleaned you would get incorrect results from the isort check. Even worse, they could be inconsistent with CI checks, which can cause a lot of confusion. We ran into an issue like this today, and had to turn off caching as a result. |
Honestly, I think this should be a separate issue about caching. It is only related in the sense that caching must somehow also handle the detection of third party folders. But if you propose improvements in the caching logic, I think it would make sense to do this separately from this issue (detection of source folders). |
We're looking into changing how we cache data as part of our multifile analysis work. It will allow us to invalidate caches based on dependencies. |
This issue affects the expected sorting of imports in Python and hence (incorrectly) triggers a
I001
error.When there is a folder that has the same name as a module, it is (possibly incorrectly) identified as
SourceMatch
. Ruff then categorizes the module asKnown(FirstParty)
and adapts the expected sorting accordingly.This happens commonly, but not exclusively, when using the wandb library because it creates a
wandb
folder, as discovered in ChartBoost/ruff-action#20.To reproduce the issue, create a Python file with these imports (I called it
test.py
):In the initial scenario, there is a
wandb
directory:Running Ruff to check the import sorting:
The checks pass,
wandb
has been categorized asKnown(FirstParty)
Now remove the
wandb
directory:Running the same Ruff check triggers a
I001
error on the same file, categorizingwandb
asKnown(ThirdParty)
; the module categorization is cached, so I remove the.ruff_cache
directory first to reproduce the error:This is now the expected sorting that is generated when calling
ruff --fix
call above:This configuration option fixes the issue properly (see ChartBoost/ruff-action#20 (comment)):
However, it is difficult for users to identify the issue and fix the configuration accordingly. I think a better solution would be to have a more robust source directory detection.
A heuristics like checking for
__init__.py
or generally the presence of*.py
as a condition file might be a solid starting point for Python.The text was updated successfully, but these errors were encountered: