-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
[RFC] [python-package] use black
for formatting Python code?
#6304
Comments
@jmoralez @guolinke @shiyu1994 @borchero what do you think? If you support this, I'll start on it in the next few days. |
Big fan, I've always stumbled over not having this when contributing here 😄 I would also propose to leverage https://pre-commit.com/ to run |
Since we're already using ruff it may be easier to just adopt its formatter, it's supposed to be the same as black but faster, so we can avoid an extra dependency. |
Hey cool! I didn't know I'm good with trying that instead of I care less about the particular tool than I do just having some standard that's automatically enforced and that's easy to get compliant with via autoformatting. I think the argument "hey we already have
I know I'd been opposed to this in the past so it's probably mostly my fault that LightGBM doesn't already use I'm open to trying it! I wouldn't want it to become the thing that runs all of the project's linting... it's nice that the But I'm open to at least starting with the cheap, highly-portable, fast tools in a pre-commit run --all-files To be sure the |
I support the pre-commit as well, it's very easy to get linter errors (especially from isort) and that would help a lot. |
I'm also using black and pre-commit in other projects. I think we can try to use them in LightGBM as well. |
There's also https://github.com/pre-commit/action which runs One more comment on |
Thanks for that! For now I'd rather run Each additional third-party action we pull in is another source of possible security issues, another thing that requires updating, etc.
Open to that too! I'll put up a first PR in the next day or two that we can look at, which adds the config and CI changes and just targets a subset of files (like |
Just adding what you said last time about replacing isort with ruff (full comment):
so I think you can expect some errors when changing it but I'm in favor of the change if they're not controversial. |
Ah thanks for remembering that @jmoralez ! I'd forgotten about that from when we added I'll start with |
Summary
I think that
black
(psf/black) should be used in the project to standardize the formatting of the project's Python code.Motivation
Over the next few months, I'd like to invest in making it easier for other people to contribute to LightGBM. I'm hoping that more use of linters will help with that.
I think that standardizing the formatting of the code and enforcing that standard automatically with
black
helps with that in the following ways:black
is so widely used)The project contains a lot of Python code:
python-package/
= thelightgbm
Python librarytests/
= unit testshelpers/
= utility scripts for maintaining the projectexamples/
= Python scripts and Jupyter notebooks showing how to use the projectProposed Approach
I'd like to sequence this work in the following way (one PR per point below):
pyproject.toml
forblack
, setting max line length to120
(to minimize), and set up checks in CI, but only apply + enforceblack
formatting on code inhelpers/*
anddocs/*
examples/*
andtests/*
python-package/*
.git-blame-ignore-revs
file so those re-formatting commits are ignored ingit blame
(and in the GitHub blame view)References
black
documentation: https://github.com/psf/blackThe text was updated successfully, but these errors were encountered: