Skip to content

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

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

Migrate to ruff from black/blackdoc/isort/flake8#6341
gen740 merged 12 commits intooptuna:masterfrom
sawa3030:add/ruff

Conversation

@sawa3030
Copy link
Copy Markdown
Collaborator

@sawa3030 sawa3030 commented Nov 14, 2025

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
Copy link
Copy Markdown
Member

@gen740 gen740 left a comment

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
Copy link
Copy Markdown
Member

c-bata commented Nov 20, 2025

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
Copy link
Copy Markdown
Member

not522 commented Nov 20, 2025

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
Collaborator 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
Copy link
Copy Markdown
Member

c-bata commented Nov 20, 2025

@not522 Could you review this PR?

Copy link
Copy Markdown
Member

@not522 not522 left a comment

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
Copy link
Copy Markdown
Member

@gen740 gen740 left a comment

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
22 checks passed
@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