-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Code Flag Options #2259
Code Flag Options #2259
Conversation
Properly handles the diff, color, and fast option when black is run with the `--code` option. Signed-off-by: Hassan Abouelela <[email protected]>
Adds test for the CLI `--code` option. Signed-off-by: Hassan Abouelela <[email protected]>
Updates the docs to remove the warning about the code options bug, and adds a changelog entry. Signed-off-by: Hassan Abouelela <[email protected]>
6fb6ca1
to
1d0faae
Compare
I've fixed the linting issues now, could someone rerun the workflows. |
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.
Wow, great tests here! Thanks for your contribution.
Signed-off-by: Hassan Abouelela <[email protected]>
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.
Thanks for working on this fix! I got some feedback but nothing truly blocking (except for possibly a Windows bug).
Great tests btw!
Wraps the output stream for windows to fix the color option when using diff. Signed-off-by: Hassan Abouelela <[email protected]>
Switches to a plain assert instead of unittest's self.assertEqual in the `--code` option tests. Signed-off-by: Hassan Abouelela <[email protected]>
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.
This time I did a hands-on review / test and this still isn't quite right. The error message when formatting fails isn't right. For normal cases, this is handled by the Report
class. Check out the difference between these cases:
--code
:
STDIN:
It honestly might be better to generalize reformat_one
to handle the --code
case too.
Thanks for being patient with me!
Thanks for the feedback, and I totally agree. Originally I wanted to maintain the whole “thrown together, mainly for testing” behavior, but as the PR has progressed, the feature has become quite bloated, and repeated a lot of the same code from the other functions. I’ll see what I can do to formalize this flag a bit more. |
Switches the code option to use the STDIN formatter instead of manually formatting the input, to add support for other flags, and properly handle the output. Signed-off-by: Hassan Abouelela <[email protected]>
Updated the code to use the STDIN formatter. As a note for maintainers: we should probably squash/rebase this PR before merging. Most of the commits prior to switching to the STDIN formatter are irrelevant. |
We always squash merge, fyi. Also, could you fix the merge conflict in CHANGES.md? |
# Conflicts: # CHANGES.md
Thanks, good to know. The conflicts have been fixed. |
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.
Thanks, this looks significantly cleaner
Just tried this out locally and decided that it's better to make There might also be a discrepancy regarding whether |
OK, there's indeed a problem with pyproject.toml:
I think the correct behavior is to pick up the pyproject.toml. That way, users can run The reason for the discrepancy is that in |
Signed-off-by: Hassan Abouelela <[email protected]>
Changes the find project root function to look in the current directory instead of system root when no sources are passed. Signed-off-by: Hassan Abouelela <[email protected]>
Changes the find project root function to look in the current directory instead of system root when no sources are passed. Signed-off-by: Hassan Abouelela <[email protected]>
Changes the assertions made on mock calls to work with python version earlier than 3.8. Signed-off-by: Hassan Abouelela <[email protected]>
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.
I am happy with the final product for the most part. The only thing I'd dock against this patch is the general awkwardness of using format_stdin_to_stdout
in reformat_code
, but this is already quite complex so I'd rather refactor this (and other parts of the "main called to formatting will start" pathway) in a separate PR.
Thank you so much for your contribution! This project is only possible by contributions like these 🖤. You're awesome, @HassanAbouelela! Congratulations on your first PR for psf/black. It's great to be able to get rid of that documentation warning for once and all. Also thanks for playing a role in the very nice welcome to Python Discord.
P.S. since you seem to be *the* person who manages to break all of our development workflows, it would be even more awesome if you could provide some feedback on your experience contributing here, we got a lot to learn (especially in the Windows department) so yeah. More details in #2238.
This needs the |
Oh fun! Probably automatiable although that will make it harder to cleanly separate the logic into own repo when I eventually do that. Good catch! |
5de8c5f - Just pushed it. |
Closes #2104, closes #1801.
Fixes a bug in the
--code
flag which would ignore options such as--diff
,--check
, and--fast
.This PR implements the fix described in the issue. It also adds tests for this fix.