RFE: --diff and --recursive
pradyunsg opened this issue · comments
I think the following would be some good enhancements to this tool:
-
--diff
like isort, which prints the suggested changes on stdout, instead of modifying the files.This is great for CI checks where a contributor gets to see the required changes to fix the situation directly.
-
--recursive
option, to specify an entire project directory without globs.This would make CLI invocations easier.
I'll be happy to write PRs for them if @asottile thinks they're reasonable.
The intention is to run the tool through pre-commit which means every tool in the world doesn't have to reimplement:
- file matching (complicated, involves exclusion / inclusion / recursion / etc.)
- dry run / diff / etc.
I don't have an interest in supporting these complicated options in each and every tool, pre-commit run --all-files
does a much better job than any tool could since it only will run against git
tracked files (and the hook metadata configures what is included vs excluded). pre-commit run --all-files --show-diff-on-failure
is the intended CI tool as well, which (as you'd expect) shows a diff.
See also:
- asottile/pyupgrade#46
- asottile/pyupgrade#40
- asottile/reorder-python-imports#45 (aside: reorder-python-imports gained some of these features before pre-commit had better support for this)
Fair enough. :)
TIL --show-diff-on-failure
. Sweet!
You can always use find
:
find . -name '*.py' -not -path "./.venv/*" -exec add-trailing-comma --py36-plus {} +
You can always use
find
:find . -name '*.py' -not -path "./.venv/*" -exec add-trailing-comma --py36-plus {} +
But what about Windows? For example, I have 2 folders: project
and tests
.
In Linux i use find:
add-trailing-comma $(shell find project tests -name "*.py") --exit-zero-even-if-changed --py36-plus
and it's good.
But how it should work in Windows?
I'm sure that the recursive
option is required
on windows you necessarily have both python, bash, and coreutils for git
so there's plenty of options there
My colleagues and I use the same repository, the same environment, and the same Makefile
that describes all the commands for the convenience of running help utilities (tests, linters, formatters). Someone uses Linux, and someone uses Windows. I am sure that many people do exactly the same. In the absence of support for recursion formatting, you have to build large crutches or, in some cases, abandon the tool. Therefore, the function would be extremely useful.
no: #59 (comment)