diff --git a/copier.yml b/copier.yml index b1b3f6e..944eadf 100644 --- a/copier.yml +++ b/copier.yml @@ -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: [] diff --git a/src/.pre-commit-config.yaml.jinja b/src/.pre-commit-config.yaml.jinja index 9062656..2af295e 100644 --- a/src/.pre-commit-config.yaml.jinja +++ b/src/.pre-commit-config.yaml.jinja @@ -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: @@ -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: @@ -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: @@ -189,6 +194,7 @@ repos: args: - --settings=. exclude: /__init__\.py$ + {%- endif %} - repo: https://github.com/acsone/setuptools-odoo rev: {{ repo_rev.setuptools_odoo }} hooks: @@ -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: diff --git a/src/{% if odoo_version > 12 %}.isort.cfg{% endif %} b/src/{% if odoo_version > 12 and not use_ruff %}.isort.cfg{% endif %} similarity index 100% rename from src/{% if odoo_version > 12 %}.isort.cfg{% endif %} rename to src/{% if odoo_version > 12 and not use_ruff %}.isort.cfg{% endif %} diff --git a/src/{% if odoo_version >= 13 %}.flake8{% endif %} b/src/{% if odoo_version >= 13 and not use_ruff %}.flake8{% endif %} similarity index 100% rename from src/{% if odoo_version >= 13 %}.flake8{% endif %} rename to src/{% if odoo_version >= 13 and not use_ruff %}.flake8{% endif %} diff --git a/src/{% if use_ruff %}.ruff.toml{% endif%}.jinja b/src/{% if use_ruff %}.ruff.toml{% endif%}.jinja new file mode 100644 index 0000000..c490cd3 --- /dev/null +++ b/src/{% if use_ruff %}.ruff.toml{% endif%}.jinja @@ -0,0 +1,34 @@ +{%- 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"]