Fix intermittent ruff I001 error for pathfinder _version import
#1460
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add
# isort: skipcomment to the_versionimport incuda_pathfinder/cuda/pathfinder/__init__.pyto prevent ruff from inconsistently reordering the import based on whether_version.pyexists.Problem
Ruff's import sorting (I001) behavior is inconsistent when imports cannot be resolved. The
_version.pyfile is generated bysetuptools-scmduring the build process, so its existence depends on build state:When
_version.pyEXISTS (after a build):Ruff can resolve the import and wants to sort it alphabetically. Since
_versioncomes after_headersalphabetically, ruff expects the import order:_dynamic_libs,_headers,_version.When
_version.pyDOESN'T EXIST (aftergit clean -fdxor 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.pydidn't exist, ruff may skip checking that import. When the cache is refreshed or_version.pyexists, ruff resolves it and wants to sort it, triggering I001 errors inconsistently.Example (before this PR):
Solution
Add
# isort: skipcomment to explicitly tell ruff to skip sorting this import, regardless of file existence or cache state. This ensures consistent behavior in all scenarios:_version.pyexists)git clean(when_version.pydoesn't exist)The import is placed after the other imports (where it logically belongs alphabetically) with the skip directive to prevent ruff from moving it.
Changes
_versionimport from top of file to after_headersimports# isort: skipcomment to prevent ruff from reordering the importNote: This PR was extracted from PR #1454