Skip to content

fix: keep symlink discovery within Git project boundaries - #2719

Open
Yurii201811 wants to merge 3 commits into
PyCQA:mainfrom
Yurii201811:issue/1788
Open

Yurii201811 wants to merge 3 commits into
PyCQA:mainfrom
Yurii201811:issue/1788

Conversation

@Yurii201811

Copy link
Copy Markdown

Description

isort can follow a project symlink and rewrite Python files outside that project. I bound path discovery to the containing Git repository, including explicit file arguments and repositories accessed through a symlinked parent. Internal links and discovery outside Git repositories keep their existing behavior.

The Follow Links documentation and its generator describe the boundary. Direct sort_file calls continue to operate on the supplied file.

Closes #1788.

Validation

  • Frozen uv install; Python 3.14.7 on macOS.
  • ./scripts/test.sh: 681 passed, one skipped, 99% coverage.
  • uv run --with tox-uv tox -e lint: passes all configured checks.
  • Ten discovery tests pass; seven regressions fail against upstream 92c56855, including the CLI modifying an external file.
  • A warmed synthetic scan of 2,000 ordinary files took about 0.078 seconds with both upstream and the fix.
  • The generated Follow Links description matches the documentation; whitespace and staged secret checks pass.

The Linux/Windows and compiled-build CI matrix has not run locally. Symlink tests retain a Windows skip because creating links requires additional privileges.

@ucodery ucodery left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this thoughtful implementation, it seems to fully address the problem for git projects.

Comment thread docs/configuration/options.md Outdated
## Follow Links

If `True` isort will follow symbolic links when doing recursive sorting.
If `True` isort will follow symbolic links during path discovery. Symlinks in a Git repository are followed only when their targets remain inside that repository, including links passed explicitly to the CLI or `find_imports_in_paths`. Symlinks outside Git repositories retain the existing behavior. Direct `sort_file` API calls continue to operate on the exact file supplied.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is good changelog copy, but as user docs the reader won't have any context about historic behaviour, or need to use the API. It should probably read as "for all other repositories, symlinks are always followed"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CHANGELOG should get an entry closer to what this is now, and that entry should specifically call out that this is a potential breaking change to users.

Comment thread scripts/build_config_option_docs.py Outdated
"If `True` isort will follow symbolic links during path discovery. Symlinks in a Git "
"repository are followed only when their targets remain inside that repository, including "
"links passed explicitly to the CLI or `find_imports_in_paths`. Symlinks outside Git "
"repositories retain the existing behavior. Direct `sort_file` API calls continue to operate "

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same copy notes here.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Always ignore symlinks that point outside of the current VCS project

2 participants