Open ruthlorenz opened 9 months ago
TODO: double check!
installation
mamba install -c conda-forge ruff
Add (or update) a pyproject.toml
file in the root of the project:
[tool.ruff]
[tool.ruff.lint]
# E402: module level import not at top of file
# E501: line too long - let the formatter worry about this
# E731: do not assign a lambda expression, use a def
ignore = [
"E402",
"E501",
"E731",
]
select = [
"F", # Pyflakes
"E", # Pycodestyle
"W", # warnings
"I", # isort
"UP", # Pyupgrade
]
run the tool
Only the "checker"
ruff check --fix .
Only the formatter:
ruff format .
Or both at once:
ruff check --fix .; ruff format .
Comments:
--fix
option first to see what will happenInline lines with code and inline comments will probably not look good -> move the comments on a separate line. For example
if feature > threshold: # the threshold is arbitrary and several should be tested to check stability
pass
would be reformatted to
if (
feature > threshold
): # the threshold is arbitrary and several should be tested to check stability
pass
so it's better to manually change to
# the threshold is arbitrary and several should be tested to check stability
if feature > threshold:
pass
edit: since version 0.6 ruff also checks notebooks
flake8, black, isort.... @mathause will help review