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

Not ignoring files even though it is excluded in Black config #146

Closed
roniemartinez opened this issue May 29, 2021 · 7 comments · Fixed by #171
Closed

Not ignoring files even though it is excluded in Black config #146

roniemartinez opened this issue May 29, 2021 · 7 comments · Fixed by #171
Labels
enhancement New feature or request

Comments

@roniemartinez
Copy link
Collaborator

So here's a sample config for Black and setup.py is ignored by Black when you run it.

[tool.black]
extend-exclude = '''
# A regex preceded with ^/ will apply only to files and directories
# in the root of the project.
^/setup.py

However, darker is not respecting this configuration and still reformats setup.py

Additional detail: darker is set in Pycharm's File Watcher so it keeps reformatting excluded files.

@akaihola
Copy link
Owner

akaihola commented Jun 9, 2021

Hi @roniemartinez, thanks a lot for your report!

I'm wondering how Darker should behave if I'm using it to run e.g. Black, isort, Pylint and Mypy on my repository, and there's a Black exclude configured in [tool.black]. Should Darker still apply isort, Pylint and Mypy, and just skip Black reformatting for matching files?

@akaihola akaihola added the enhancement New feature or request label Jun 9, 2021
@roniemartinez
Copy link
Collaborator Author

Hi @akaihola

Yes, it should still apply isort, Pylint and Mypy and skip Black. If Mypy has exclude, Darker should also consider it.

@akaihola
Copy link
Owner

That makes sense. On the technical side, these different tools are invoked differently by Darker, and in the case of Black, we bypass command line handling and file selection, and just submit the contents of the Python source code directly to black.format_str(). So we'll have to either figure out how to

  • invoke Black's configuration parsing and file selection first, or
  • reimplement enough of Black's configuration parsing in Darker, or
  • invoke the Black main program with suitable arguments instead.

I don't now remember exactly why I ended up calling directly into Black internals, but there was a good reason at that time for sure. At least it doesn't harm performance since Python+Black don't need to be bootstrapped separately for each file.

@roniemartinez
Copy link
Collaborator Author

invoke Black's configuration parsing and file selection first

I guess the first option makes more sense because Darker is already reading Black's configuration in read_black_config() and the src path is also available.

config = parse_pyproject_toml(value)

@akaihola
Copy link
Owner

Thanks @roniemartinez, I'll definitely look into this in the near future. Or feel free to contribute a patch as well!

@akaihola
Copy link
Owner

@roniemartinez would you like to review #171? Can I invite you as a collaborator on this project?

@roniemartinez
Copy link
Collaborator Author

@akaihola Thank you so much for the effort.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants