psf / black

The uncompromising Python code formatter
https://black.readthedocs.io/en/stable/
MIT License
38.28k stars 2.42k forks source link

Add an option to dereference symlinks #3395

Open calliecameron opened 1 year ago

calliecameron commented 1 year ago

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

I'm trying to integrate black into a bazel project, run as a bazel test, to check python formatting at precommit. For sandboxing reasons, bazel tests don't run on the source files directly, but on a special output directory with symlinks to the source files. However, black skips symlinks, so it skips all the files and reports success, without actually having checked any of the files.

Describe the solution you'd like

A new option, so that black treats a symlink /a/b that points to file /b/a as a regular file /a/b. Since this is an unusual situation, it would make sense for the option to be off by default, so the existing behaviour doesn't change.

As far as I can see, bazel only creates symlinks to files, not directories, so I have no opinion on how directory symlinks are treated.

Describe alternatives you've considered

Not checking formatting at precommit.

Additional context

Bazel output directory format: https://bazel.build/remote/output-directories

felix-hilden commented 1 year ago

Thanks for the suggestion! I'm not sure why the decision was made originally, but this use case does sound reasonable.

cristifalcas commented 6 months ago

I have the same issue, latest versions (23 and 24) don't work with bazel because of this issue. I don't understand why black tries to guess a root project, but can we make this optional?