-
Notifications
You must be signed in to change notification settings - Fork 56
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
Add a --diff option to match black behavior. #4
Conversation
This allows for example to use darker as a formatter for vscode with minimal changes as vscode sends the --quiet and --diff flags to the formatter. "python.formatting.provider": "black", "python.formatting.blackPath": "/path/to/darker"
A bit ugly of an implementation, mainly to know if you would be ok with it. I was also happy to find this project as I was really unhappy with inserting/removing |
Also just deprecated darken and point to darken now. |
Hey @Carreau this is a great contribution! I've started to review – please expect a couple of suggestions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There you go, just a few minor notes to keep the code style consistent and skip some unnecessary operations.
Do you think you could add a simple test case for the --diff
option?
Yes, of course, I mainly wanted to test the waters. I'll cleanup, and I'll also see if I can make it work with isort, which I'm not sure it does now. |
Also add type hint for `print_diff` parameter.
Without the quite flag it prints out a "Fixing" line. Suppressing that will make `--diff` tests cleaner.
Also adding tests for other options as well.
We may later choose to enable it again, but for now let's keep apostrophes intact in literal strings.
The lines are already in `chosen_lines`.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Carreau, I sat down and addressed my own review items. I hope you didn't have unpushed changes for those...
--diff
indeed doesn't yet work together with --isort
– I made that combination raise a NotIimplementedError
for now. Let's implement that in a separate PR if needed.
- `--isort` and `--diff` now work together - diff original unmodified and user-edited versions of files in the Git directory using Python's difflib, not by parsing `git diff` output - process each edited file individually - only run `isort` for edited files - write back `isort` modifications together with `black` modifications, and skip writing if there are errors - remove code that became unused - avoid extra conversions between source code as a string and a list of line strings - add some tests for previously untested functions
Allow `--isort --diff`
This allows for example to use darker as a formatter for vscode with
minimal changes as vscode sends the --quiet and --diff flags to the
formatter.