-
Notifications
You must be signed in to change notification settings - Fork 55
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 support for Ruff as a code-formatter #744
base: master
Are you sure you want to change the base?
Conversation
FYI @clintonsteiner @mrfroggg @Svenito support for Ruff as a code re-formatter is soon landing. This branch basically works already, we just need to add tests and documentation and clean up a bit. After that, code reviews would be highly appreciated! I'll invite you as collaborators on the repository just in case you might have time to review. |
91c9c4e
to
7772f5f
Compare
Sounds great! Let me know what I can do to help |
I'd be happy to review, add tests, or add docs. Thank you! |
I have some changes - would like to help. |
7772f5f
to
ad1552a
Compare
Hi @clintonsteiner, thanks for your reply! I just rebased this branch on Note that there's a stack of branches sitting on top of each other, and I'm planning to merge them one by one and rebase the latter ones on
If some of your fixes are about #568 or #738, it's ok for me if you still push them to a PR on top of #744. I can then do the clean-up work and move them up to the correct branch. |
cda86e6
to
c828762
Compare
9a1847d
to
ca1f93f
Compare
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.
Left plenty of reviews, sorry just trying to be helpful
Feel free to ignore them as you disagree with them :)
This will make it easier to add support for pyupgrade.
This will make it easier to add support for pyupgrade.
This allows formatters to exclude based on file path even if we're passing file contents on stdin and using --stdin-filename.
r"|\.tox" | ||
r"|\.svn" | ||
r"|\.venv" | ||
r"|\.vscode" |
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.
Maybe exclude all dot paths: .*
?
" (e.g. `formatter=none`)" | ||
) | ||
message = "Can't find the Black package" | ||
raise DependencyError(message) from exc |
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.
What will happen, if the internals of black will change? e.g.: renaming/moving of parse_pyproject_toml
or re_compile_maybe_verbose
? Think the error message is not really good in this case.
So, what's about to import only black package and then do the real imports?
e.g.:
try:
import black
except ImportError as exc:
logger.warning(
"To re-format code using Black, install it using e.g."
" `pip install 'darker[black]'` or"
" `pip install black`"
)
logger.warning(
"To use a different formatter or no formatter, select it on the"
" command line (e.g. `--formatter=none`) or configuration"
" (e.g. `formatter=none`)"
)
message = "Can't find the Black package"
raise DependencyError(message) from exc
# Black is installed
from black import ( # pylint: disable=import-outside-toplevel
parse_pyproject_toml,
re_compile_maybe_verbose,
)
) | ||
except ImportError as exc: | ||
logger.warning( | ||
"To re-format code using Black, install it using e.g." |
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.
Will this warning will be always displayed to the user?
# Local import so Darker can be run without Black installed. | ||
# No need for error handling, already done in `BlackFormatter.read_config`. | ||
from black import FileMode as Mode # pylint: disable=import-outside-toplevel | ||
from black import TargetVersion # pylint: disable=import-outside-toplevel |
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.
Maybe move all import from black into a own package and handle import error there? So it's guaranteed that the own error message from above will always appear?
Fixes #521
formatter
command line and config option #568formatter
command line and config option #568master