Skip to content

Do not use gitignore if explicitly passing excludes#2170

Merged
ambv merged 2 commits into
psf:masterfrom
ktbarrett:change-gitignore
May 7, 2021
Merged

Do not use gitignore if explicitly passing excludes#2170
ambv merged 2 commits into
psf:masterfrom
ktbarrett:change-gitignore

Conversation

@ktbarrett

Copy link
Copy Markdown
Contributor

Closes #2164.

Changes behavior of how .gitignore is handled. With this change, the rules in .gitignore are only used as a fallback if no exclusion rule is explicitly passed on the command line or in pyproject.toml. Previously they were used regardless if explicit exclusion rules were specified, preventing any overriding of .gitignore rules.

Those that depend only on .gitignore for their exclusion rules will not be affected. Those that use both .gitignore and exclude will find that exclude will act more like actually specifying exclude and not just another extra-excludes. If the previous behavior was desired, they should move their rules from exclude to extra-excludes.

@ichard26 ichard26 self-requested a review April 30, 2021 04:43
@ktbarrett

Copy link
Copy Markdown
Contributor Author

If this is deemed "messy" a superior solution might involve making the exclude parameter a callable object that defaults to a function that checks the gitignore and default rules, or just returns match.search bound method.

@ktbarrett

Copy link
Copy Markdown
Contributor Author

Fixed the CHANGE.md issue.

@cooperlees cooperlees left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM and a good outcome from your issue chat.

Please just make the linter happy.

@ichard26 ichard26 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I'm still not 100% happy with the level of disruption this might cause, this does seem like the best solution in terms of costs vs benefit. The semantics should make much more sense after this.

If this is deemed "messy"

Nah, it's fine, I don't like it too much since include used to work the same as exclude and now it doesn't, but the complexity of a callable is not worth it IMO. I'd appreciate a comment describing this behaviour in the code, but other than that, I'll approve this once mine and Cooper's comments have been addressed.

Other than my specific comments, I'd like to see some tests enforcing this functionality / behaviour. I don't want this behaviour to change suddenly. Honestly the fact no test failed from this change makes me feel the existing tests for this logic are not extensive enough.

Thank you!

Comment thread CHANGES.md Outdated
Comment thread src/black/__init__.py
Comment thread src/black/__init__.py Outdated
@ktbarrett

Copy link
Copy Markdown
Contributor Author

I find it odd that the primers all passed last night with the same logic. I'll investigate.

@ichard26

ichard26 commented May 1, 2021

Copy link
Copy Markdown
Collaborator

@ktbarrett looks like tox reformatted their code to the newest version of Black today. In that case, just mark tox as a project with no expected changes:

"tox": {
"cli_arguments": [],
"expect_formatting_changes": true,
"git_clone_url": "https://github.com/tox-dev/tox.git",
"long_checkout": false,
"py_versions": ["all"]
},

edit: yep they did today: tox-dev/tox@a0f0572

@ktbarrett

Copy link
Copy Markdown
Contributor Author

The failing test decided to take >1 hour and then fail, while the rest completed in <2 minutes. I'm not entirely sure what that test is doing? Is it just testing running black more than once on a source does the same thing each time? I'm just going to try it again...

@ktbarrett ktbarrett closed this May 1, 2021
@ktbarrett ktbarrett reopened this May 1, 2021
@ichard26

ichard26 commented May 1, 2021

Copy link
Copy Markdown
Collaborator

Sounds like either bad luck or a hypothesmith bug, but there's like no way this PR is causing that random failure. Anyway, I'll review this sometime soon, probably tomorrow (it's once again night where I am).

Is it just testing running black more than once on a source does the same thing each time

Well it generates valid code and runs Black over it repeatedly. This is called fuzzing and it's actually a good way of finding edge cases (when it works properly and its randominess doesn't screw itself over)

@ambv

ambv commented May 2, 2021

Copy link
Copy Markdown
Collaborator

I'm not a big fan of hiding the default value of --exclude. Now it no longer appears in the tool's --help. See what it did before and re-add it manually to the help text.

@ktbarrett ktbarrett requested a review from ichard26 May 3, 2021 16:30

@ichard26 ichard26 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're getting closer to this becoming ready to merge! Good work! I got some final suggestions / comments but they're nothing major.

p.s. apologies for the wait for my review

Comment thread src/black/__init__.py Outdated
Comment thread src/black/__init__.py Outdated
Comment thread src/black/__init__.py Outdated
Comment thread tests/test_black.py
Comment thread src/black/__init__.py Outdated
@ktbarrett

Copy link
Copy Markdown
Contributor Author

Resolved conflicts.

@ambv ambv merged commit 1fe2efd into psf:master May 7, 2021
@ktbarrett

Copy link
Copy Markdown
Contributor Author

Thanks everyone for the reviews and comments, and for getting this change in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

4 participants