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

--include= and --exclude= #270

Closed
ambv opened this issue May 29, 2018 · 2 comments
Closed

--include= and --exclude= #270

ambv opened this issue May 29, 2018 · 2 comments
Assignees
Labels
T: enhancement New feature or request T: style What do we want Blackened code to look like?

Comments

@ambv
Copy link
Collaborator

ambv commented May 29, 2018

I always steered people towards find | grep -E | grep -Ev | xargs black to do custom file matching. But that doesn't work on Windows. We need support for --include= and --exclude= within Black.

They hold regular expressions. The former is "what gets included on recursive searches", the latter "what gets dropped on recursive searches". You can pass multiple --include and multiple --exclude. Checks for --exclude are done first, checks for --include later.

--include= would have a default that is now stores in PYTHON_EXTENSIONS (".pyi?$" in regex form)
--exclude= would have a default that is now stored in BLACKLISTED_DIRECTORIES

This functionality is required by pypa/pip#5425.

@ambv ambv added T: enhancement New feature or request T: style What do we want Blackened code to look like? labels May 29, 2018
@autophagy
Copy link
Member

@ambv I have couple of implementation detail questions about this:

  • This regex should be applied on the entire path when considering whether to include/exclude something, correct? Not just the name (as is currently done with the includes). So one could pass test\/secrets to --exclude and it would drop files/test/secrets/* but not files/test/notsecrets/?
  • I'm wondering how to handle directories in the regexes. Initially, I though something like build\/ would be fine, but pathlib strips trailing slashes from the path. I'd prefer to do it this way, since \/build doesn't always work (if its a directory at the root of wherever black is searching from, the path will just be ('build') - do you think it be sensible to just append a '/' to the path when applying the regex if the child is a directory?

@ambv
Copy link
Collaborator Author

ambv commented May 30, 2018

Re 1: Agreed.

Re 2: Yes, your suggestion is good to append / when we discover entry.is_dir() :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T: enhancement New feature or request T: style What do we want Blackened code to look like?
Projects
None yet
Development

No branches or pull requests

2 participants