Skip to content

Commit

Permalink
Use ruff instead of black, isort, flake8, autoflake, pyupgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
sbidoul committed Oct 28, 2023
1 parent 659c987 commit 097c8f1
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ __pycache__/
*.py[cod]
/.venv
/.pytest_cache
/.ruff_cache

# C extensions
*.so
Expand Down
12 changes: 12 additions & 0 deletions copier.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,18 @@ generate_requirements_txt:
Generate requirements.txt from addons manifests and optional overrides in setup.py
files.

use_ruff:
default: no
type: bool
help: Use ruff and ruff-format instead of flake8, autoflake, pyupgrade, isort, black.
when: "{{ odoo_version >= 14.0 }}"

additional_ruff_rules:
type: yaml
default: []
help: List of additional ruff rules to enable.
when: "{{ use_ruff }}"

rebel_module_groups:
type: yaml
default: []
Expand Down
16 changes: 16 additions & 0 deletions src/.pre-commit-config.yaml.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ repos:
hooks:
- id: oca-checks-odoo-module
- id: oca-checks-po
{%- if not use_ruff %}
- repo: https://github.com/myint/autoflake
rev: {{ repo_rev.autoflake }}
hooks:
Expand All @@ -135,6 +136,7 @@ repos:
rev: {{ repo_rev.black }}
hooks:
- id: black
{%- endif %}
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v{{ repo_rev.prettier }}
hooks:
Expand Down Expand Up @@ -176,11 +178,14 @@ repos:
- id: check-xml
- id: mixed-line-ending
args: ["--fix=lf"]
{%- if not use_ruff or odoo_version < 15.0 %} # ruff doesn't support python 3.6
- repo: https://github.com/asottile/pyupgrade
rev: {{ repo_rev.pyupgrade }}
hooks:
- id: pyupgrade
args: ["--keep-percent-format"]
{%- endif %}
{%- if not use_ruff %}
- repo: https://github.com/PyCQA/isort
rev: {{ repo_rev.isort }}
hooks:
Expand All @@ -189,6 +194,7 @@ repos:
args:
- --settings=.
exclude: /__init__\.py$
{%- endif %}
- repo: https://github.com/acsone/setuptools-odoo
rev: {{ repo_rev.setuptools_odoo }}
hooks:
Expand All @@ -201,12 +207,22 @@ repos:
- --header
- "# generated from manifests external_dependencies"
{%- endif %}
{%- if not use_ruff %}
- repo: https://github.com/PyCQA/flake8
rev: {{ repo_rev.flake8 }}
hooks:
- id: flake8
name: flake8
additional_dependencies: ["flake8-bugbear=={{ repo_rev.flake8_bugbear }}"]
{%- endif %}
{%- if use_ruff %}
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.3
hooks:
- id: ruff
args: [ --fix, --exit-non-zero-on-fix ]
- id: ruff-format
{%- endif %}
- repo: https://github.com/OCA/pylint-odoo
rev: {{ repo_rev.pylint_odoo }}
hooks:
Expand Down
37 changes: 37 additions & 0 deletions src/{% if use_ruff %}.ruff.toml{% endif%}.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{%- if odoo_version >= 16.0 %}
target-version = "py310"
{%- elif odoo_version >= 15.0 %}
target-version = "py38"
{%- endif %}
fix = true

[lint]
extend-select = [
"B",
"C90",
"I", # isort
{%- if odoo_version >= 15.0 %}
"UP", # pyupgrade
{%- endif %}
{%- for rule in additional_ruff_rules %}
"{{ rule }}",
{%- endfor %}
]
exclude = ["setup/*"]

[format]
exclude = ["setup/*"]

[per-file-ignores]
"__init__.py" = ["F401", "I001"] # ignore unused and unsorted imports in __init__.py
"__manifest__.py" = ["B018"] # useless expression

[isort]
section-order = ["future", "standard-library", "third-party", "odoo", "odoo-addons", "first-party", "local-folder"]

[isort.sections]
"odoo" = ["odoo"]
"odoo-addons" = ["odoo.addons"]

[mccabe]
max-complexity = 16

0 comments on commit 097c8f1

Please sign in to comment.