psf / black

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

[RFE] Support gitignore-like include/exclude patterns #541

Open behnam opened 6 years ago

behnam commented 6 years ago

When putting include/exclude rules into pyproject.toml file...

1) It's mentally easier to think about each pattern separately and not as a whole regex,

2) Glob/Gitignore-like patterns are easier to read and write, and

3) Using gitignore-like patterns allows easier comparison with the ignore file of the SCM.

Famously, hg started with regex patterns for its path patterns, but later enabled glob/gitignore-like patterns. http://hgbook.red-bean.com/read/file-names-and-pattern-matching.html

Cargo already accepts a list of glob/gitignore patterns. https://doc.rust-lang.org/stable/cargo/reference/manifest.html#the-exclude-and-include-fields-optional (We're in the middle of transition from glob patterns to gitignore-like ones. More here: https://github.com/rust-lang/cargo/issues/4268)

(Gitignore patterns are a superset of glob patterns, adding a couple of rules on top of glob.)

With that, I like to propose support for gitignore-like (or at least glob) patterns in Black's include and exclude entries in pyproject.toml.

To keep it backwards-compatible, it can so that then the values are string, the old behavior is preserved (at least for now), and if the value is a list, they are treated as gitignore-like patterns, similar to Cargo.

What do you think?

ghost commented 5 years ago

Yes, please. We need something nicer than one long regex.

ambv commented 4 years ago

I like this idea. @jgirardet, you could do this on top of your .gitignore support work. What do you think?

wasdee commented 3 years ago

A gentle voice from 2021. I love this idea. so we are looking for a pr, right?