Skip to content

Migrate to ruff from black/blackdoc/isort/flake8 - #6341

Merged
gen740 merged 12 commits into
optuna:masterfrom
sawa3030:add/ruff
Nov 21, 2025
Merged

gen740 merged 12 commits into
optuna:masterfrom
sawa3030:add/ruff

Conversation

@sawa3030

@sawa3030 sawa3030 commented Nov 14, 2025 •

Copy link
Copy Markdown
Contributor

Motivation

Adopt Ruff and drop Black / Blackdoc / isort / Flake8.

Summary of Changes

  • Add Ruff configuration to pyproject.toml and remove settings for Black, Blackdoc, isort, and Flake8.
  • Update format.sh, .pre-commit-config.yaml, and CONTRIBUTING.md to use Ruff.
  • Update CI jobs (check and check-optional) to run Ruff.
  • Apply minimal code changes where Ruff’s rules differ from the previous toolchain.

Notes

  • Some minor formatter differences are temporarily ignored via [tool.ruff.format]. This is because Ruff’s behavior is not 100% identical to Black/Blackdoc.
  • To keep this PR focused, we’re not addressing all remaining nits. We’ll track and clean these up in a follow-up issue/PR.

@sawa3030
sawa3030 marked this pull request as ready for review November 14, 2025 06:52
@c-bata c-bata added the code-fix Change that does not change the behavior, such as code refactoring. label Nov 14, 2025

@gen740 gen740 left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you for the PR!

I have a question.

Is that OK to remove blackdoc? ruff cannot substitute blackdoc.

@c-bata

c-bata commented Nov 20, 2025

Copy link
Copy Markdown
Member

Is that OK to remove blackdoc?

Yes, that’s ok. We previously encountered some issues with blackdoc (though I don’t remeber the exact details), and we had discussed removing it back then.

@not522

not522 commented Nov 20, 2025

Copy link
Copy Markdown
Member

Is that OK to remove blackdoc? ruff cannot substitute blackdoc.

In my understanding, ruff checks docstrings if docstring-code-format = true.

@sawa3030

Copy link
Copy Markdown
Contributor Author

Thank you for the discussion. From my testing, Ruff’s docstring formatter does not recognize .. testcode:: directives as Python code to format (ref: the official documentation: https://docs.astral.sh/ruff/formatter/#docstring-formatting). If we use code blocks inside the .. testcode:: directive like here, Ruff does format them, but then the Sphinx doctests fail (example: https://github.com/optuna/optuna/actions/runs/19525035471/job/55896143443?pr=6341).

Given these findings, I think it might be reasonable to drop blackdoc for now and wait until Ruff can better support Sphinx-style doctest blocks. If there is any better ideas, I would really appreciate your suggestions.

@c-bata

c-bata commented Nov 20, 2025

Copy link
Copy Markdown
Member

@not522 Could you review this PR?

@not522 not522 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM!

@not522 not522 removed their assignment Nov 21, 2025

@gen740 gen740 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM!

@gen740
gen740 merged commit 844e68f into optuna:master Nov 21, 2025
@gen740 gen740 added this to the v4.7.0 milestone Nov 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

code-fix Change that does not change the behavior, such as code refactoring.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants