Commit d369900
authored
Fix intermittent ruff I001 error for _version import (#1460)
Add # isort: skip comment to the _version import in
cuda_pathfinder/cuda/pathfinder/__init__.py to prevent ruff from
inconsistently reordering the import based on whether _version.py exists.
Problem:
Ruff's import sorting (I001) behavior is inconsistent when imports
cannot be resolved. The _version.py file is generated by setuptools-scm
during the build process, so its existence depends on build state:
- When _version.py EXISTS (after a build):
Ruff can resolve the import and wants to sort it alphabetically.
Since _version comes after _headers alphabetically, ruff expects
the import order: _dynamic_libs, _headers, _version.
- When _version.py DOESN'T EXIST (after git clean -fdx or fresh clone):
Ruff cannot resolve the import and may skip checking it entirely,
especially if cached as "unresolvable". This leads to inconsistent
behavior where the same code passes or fails depending on build state.
Root Cause:
Ruff caches import resolution results. If the cache has stale data
where _version.py didn't exist, ruff may skip checking that import.
When the cache is refreshed or _version.py exists, ruff resolves it
and wants to sort it, triggering I001 errors inconsistently.
Solution:
Add # isort: skip comment to explicitly tell ruff to skip sorting
this import, regardless of file existence or cache state. This ensures
consistent behavior in all scenarios:
- After builds (when _version.py exists)
- After git clean (when _version.py doesn't exist)
- With fresh clones
- With stale ruff cache
The import is placed after the other imports (where it logically
belongs alphabetically) with the skip directive to prevent ruff from
moving it.1 parent 67b18e2 commit d369900
1 file changed
+2
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
7 | | - | |
8 | 6 | | |
9 | 7 | | |
10 | 8 | | |
| |||
14 | 12 | | |
15 | 13 | | |
16 | 14 | | |
| 15 | + | |
| 16 | + | |
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| |||
0 commit comments