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
Read shebangs to discover python files #930
Conversation
caveat: I haven't looked at the code yet. My main concern with this idea is the performance hit when crawling large directories of non-python code |
On *nix systems we could check executable files only. |
@zsol: I've just checked the difference on some internal repo. I don't see much overhead on the repo with more than 10.5k files where there were ~150 python files to reformat. Without this patch: 22.3s (avg over the 3 runs) Moreover, this feature has been set as optional with an appropriate warning in help. @emdej: it could produce inconsistent results on exotic platforms like Windows. |
I see one other problem with the current code -- it doesn't handle |
At least |
I do not think that we should encourage usage of such explicit path with defaults. |
fwiw, when run using |
|
sure :) was just offering some potential prior art |
Yeah, that caught me out, I was surprised when |
a4a4c29
to
b8b2b50
Compare
I've just rebased the patch on the upstream and resolved conflicts. Please let me know if you're going to consider pulling this or not. |
I see that there are problems after the rebase with the new tests. I will have a look at that tomorrow. |
|
I think that we can safely extend the default regex to include |
da9d976
to
b2be34c
Compare
Thanks for your work on this. However, I don't think we're willing to slow down traversal for all users who are not putting Python code in non-.py files. For this use case pre-commit or something similar is a decent workaround. |
At work we've often found ourselves manually adding python scripts without
.py
extensions toblack
calls because they were placed in various locations in repositories that weren't strictly python projects. Such special handling is error-prone and we've come to the conclusion that sinceblack
offers python file discovery (includes/excludes) when the directory is provided, it could be extended to also check shebangs.Thanks to @D0han for the support!