Skip to content

Commit d369900

Browse files
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

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

cuda_pathfinder/cuda/pathfinder/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33

44
"""cuda.pathfinder public APIs"""
55

6-
from cuda.pathfinder._version import __version__ # noqa: F401
7-
86
from cuda.pathfinder._dynamic_libs.load_dl_common import DynamicLibNotFoundError as DynamicLibNotFoundError
97
from cuda.pathfinder._dynamic_libs.load_dl_common import LoadedDL as LoadedDL
108
from cuda.pathfinder._dynamic_libs.load_nvidia_dynamic_lib import load_nvidia_dynamic_lib as load_nvidia_dynamic_lib
@@ -14,6 +12,8 @@
1412
from cuda.pathfinder._headers.find_nvidia_headers import find_nvidia_header_directory as find_nvidia_header_directory
1513
from cuda.pathfinder._headers.supported_nvidia_headers import SUPPORTED_HEADERS_CTK as _SUPPORTED_HEADERS_CTK
1614

15+
from cuda.pathfinder._version import __version__ # isort: skip # noqa: F401
16+
1717
# Indirections to help Sphinx find the docstrings.
1818
#: Mapping from short CUDA Toolkit (CTK) library names to their canonical
1919
#: header basenames (used to validate a discovered include directory).

0 commit comments

Comments
 (0)