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

Black reformats entire virtual environment when named env with pathspec==0.10.0 #3256

Closed
jnhyperion opened this issue Sep 5, 2022 · 8 comments
Labels
C: file collection Related to file collection (e.g. gitignore & cache) or file discovery and all of its configuration. C: packaging Installation and packaging of Black T: bug Something isn't working

Comments

@jnhyperion
Copy link
Contributor

jnhyperion commented Sep 5, 2022

Describe the bug

When using black and virtualenv, black try to reformat entire virtual env folder, which cause heavy process execution and hang very long.

To Reproduce
For example, take this code:

mkdir myfolder

cd myfolder

virtualenv env

source env/bin/activate

pip install black

pip list

Package           Version
----------------- -------
black             22.8.0
click             8.1.3
mypy-extensions   0.4.3
pathspec          0.10.0
pip               22.2.2
platformdirs      2.5.2
setuptools        63.4.3
tomli             2.0.1
typing_extensions 4.3.0
wheel             0.37.1

black . --check --diff

then black will try to check all the env folder.

this issue is caused by the library pathspec 0.10.0, and black does not lock the version, looks like pathspec already fix the bug in 0.10.1.

but for black, does it need to lock, or force skip this buggy pathspec version, to avoid this fatal error

@jnhyperion jnhyperion added the T: bug Something isn't working label Sep 5, 2022
@JelleZijlstra
Copy link
Collaborator

If you tell Black to format everything in a directory, it will; it can't magically determine that the folder contains a virtual env. We exclude a few common names for virtual envs by default, but env is not among them. You can use the --exclude or --extend-exclude option to exclude directories.

Can you clarify what you think the bug is in pathspec?

@ichard26
Copy link
Collaborator

ichard26 commented Sep 5, 2022

Black doesn't actually include env in its default excludes, I think it's probably a good idea to include it even if it's a less common virtual environment name. Not sure why upgrading pathspec would change black's behaviour, it shouldn't be coming into play here as there's no .gitignore file anywhere.

Are there situations where excluding env by default would be a problem? @JelleZijlstra

@JelleZijlstra
Copy link
Collaborator

env is a perfectly plausible name for a folder containing actual code that you want to be formatted. It would be an unpleasant experience for a user to find out that Black silently skips a directory they want to get formatted.

@jnhyperion
Copy link
Contributor Author

jnhyperion commented Sep 5, 2022

in the virtual env folder env, it will automatically contains .gitignore

# created by virtualenv automatically
*

which I think will be recogonized by black right?

in my case, if I upgrade pathspec to 0.10.1, this issue will disappear.

the bug is here: cpburnz/python-pathspec#62

@ichard26
Copy link
Collaborator

ichard26 commented Sep 5, 2022

cpburnz/python-pathspec#62 ahhh I see, sounds like we should ask upstream to yank this version since it might cause a lot of grief.

@ionite34
Copy link
Contributor

ionite34 commented Sep 5, 2022

The env directory not ignored issue seems to only occur with pathspec version 0.10.0, and not in 0.9.0 nor the newest 0.10.1 version. Probably related to cpburnz/python-pathspec#62

@ichard26
Copy link
Collaborator

ichard26 commented Sep 5, 2022

I've asked upstream to yank pathspec 0.10.0, let's see if they're open to it, otherwise, I'd be open to banning the faulty version on Black's end.

@ichard26 ichard26 added the C: packaging Installation and packaging of Black label Sep 5, 2022
@ichard26 ichard26 changed the title black try to reformat entire virtual env folder Black reformats entire virtual environment when named env with pathspec==0.10.0 Sep 5, 2022
@ichard26 ichard26 added C: file collection Related to file collection (e.g. gitignore & cache) or file discovery and all of its configuration. S: blocked A decision or another issue needs to be made/resolved before this can be worked on (more). and removed S: blocked A decision or another issue needs to be made/resolved before this can be worked on (more). labels Sep 5, 2022
@ichard26
Copy link
Collaborator

ichard26 commented Sep 5, 2022

And pathspec 0.10.0 has been yanked: https://pypi.org/project/pathspec/0.10.0/

@ichard26 ichard26 closed this as completed Sep 5, 2022
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. C: packaging Installation and packaging of Black T: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants