Skip to content
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

Apply excludes before normalising symlinks #3527

Closed
itoijala-huld opened this issue Jan 27, 2023 · 3 comments · Fixed by #3846
Closed

Apply excludes before normalising symlinks #3527

itoijala-huld opened this issue Jan 27, 2023 · 3 comments · Fixed by #3846
Labels
C: file collection Related to file collection (e.g. gitignore & cache) or file discovery and all of its configuration. T: enhancement New feature or request

Comments

@itoijala-huld
Copy link

Is your feature request related to a problem? Please describe.

Our project contains symlinks like this:

project
+- a
   +- b -> ../x/y
   +- other files
+- x
   +- y
      +- lots of files

We would like to avoid black spending time formatting/complaining about the same files twice, so we make the excludes regex match /a/b/.
This doesn't help because the excludes are evaluated after normalising the path to /x/y/.
We cannot put that in the excludes because we do want to format the files.

Describe the solution you'd like

Excludes could be evaluated before normalising the path, or at least before evaluating symlinks.

Describe alternatives you've considered

Perhaps it would be best to evaluate excludes both before and after normalising the path.
There is also a use case for the way it is now, if we did want to exclude the files completely without listing all paths to them in the excludes.

@itoijala-huld itoijala-huld added the T: enhancement New feature or request label Jan 27, 2023
@cooperlees
Copy link
Collaborator

This is a tough one to get right. I wonder if we could just simplify it add a config option (in pyproject.toml) to not follow symlink at all? I feel that would help your use case here. Thoughts?

@cooperlees cooperlees added the C: file collection Related to file collection (e.g. gitignore & cache) or file discovery and all of its configuration. label Jan 28, 2023
@itoijala-huld
Copy link
Author

Given the fact that symlinks pointing outside the project are rejected already, not following symlinks at all would be the easiest option. There should be no need to follow symlinks since black has no need to get the module hierarchy right (one file at a time).

Even without following symlinks, it should be possible to use the current configuration options to reach any file within the project.

@hauntsaninja
Copy link
Collaborator

hauntsaninja commented Jul 9, 2023

I'm in favour of this, at least for the gitignore excludes; I was surprised this was the current behaviour when making #3751

hauntsaninja added a commit to hauntsaninja/black that referenced this issue Aug 19, 2023
This means, for instance, that a gitignored symlink cannot affect your
formatting. Fixes psf#3527, fixes psf#3826
hauntsaninja added a commit to hauntsaninja/black that referenced this issue Aug 19, 2023
This means, for instance, that a gitignored symlink cannot affect your
formatting. Fixes psf#3527, fixes psf#3826
JelleZijlstra pushed a commit that referenced this issue Sep 7, 2023
This means, for instance, that a gitignored symlink cannot affect your
formatting. Fixes #3527, fixes #3826
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: file collection Related to file collection (e.g. gitignore & cache) or file discovery and all of its configuration. T: enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants