Skip to content
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

[ci] enable ruff-format on some files, add pre-commit config #6308

Merged
merged 8 commits into from
Feb 15, 2024

Conversation

jameslamb
Copy link
Collaborator

Contributes to #6304.

  • adds auto-formatting of Python code with ruff format
  • moves enforcement of that formatting, ruff linter checks, and isort into a pre-commit config
  • updates CONTRIBUTING.md with information on how to do that

Notes for Reviewers

The versions of tools I added in .pre-commit-config.yaml are the latest released versions available.

As discussed over in #6304, in this PR I've omitted the directories with a lot of Python code (examples/, python-package/, and tests/). So we can focus on the types of changes that'll be made and just see a few small examples in other code.

Also as described in #6304, I'll add the commit from this PR (and the others that reformat the code) in a .git-blame-ignore-revs file once we're done with this work.

Copy link
Collaborator

@borchero borchero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks reasonable to me! Thanks for setting this up :)

@jmoralez
Copy link
Collaborator

I think having two pyproject.toml files is a bit confusing. If we're going to replace isort with ruff in the future it may be worth to define a ruff.toml and a temporal .isort.cfg instead. WDYT?

@jameslamb
Copy link
Collaborator Author

I think having two pyproject.toml files is a bit confusing. If we're going to replace isort with ruff in the future it may be worth to define a ruff.toml and a temporal .isort.cfg instead. WDYT?

I don't agree that it's confusing.

  • project-wide configuration at the top-level pyproject.toml
  • details for building the lightgbm Python package in python-package/pyproject.toml

I'd prefer to not have a proliferation of tool-specific config files at the root of the repo. And I like having it at the root of the repo so that if you just call ruff check or isort or mypy or whatever directly from the root of the repo (not using pre-commit), you'll still automatically pick up the configuration used in CI.

However, I feel most strongly about not having the tool-specific config files. So if you don't like having multiple pyproject.toml, would you support adding stuff like this in .pre-commit-config.yaml?

 args: ["--config", "python-package/pyproject.toml"]

And moving the configuration back into there?

@jmoralez
Copy link
Collaborator

would you support adding stuff like this in .pre-commit-config.yaml?
args: ["--config", "python-package/pyproject.toml"]
And moving the configuration back into there?

Yes, I think that's clearer

@jameslamb
Copy link
Collaborator Author

Alright no problem, I'm good with that! Just pushed a commit moving the settings back into python-package/pyproject.toml and telling pre-commit to look there for configuration.

Copy link
Collaborator

@jmoralez jmoralez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@jameslamb jameslamb merged commit 6330d62 into master Feb 15, 2024
43 checks passed
@jameslamb jameslamb deleted the ci/ruff-formatting branch February 15, 2024 04:17
Copy link

This pull request has been automatically locked since there has not been any recent activity since it was closed.
To start a new related discussion, open a new issue at https://github.com/microsoft/LightGBM/issues including a reference to this.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 20, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants