Skip to main content

Build Status codecov version wheel supported-versions commits-since code-style-black

odoo-pre-commit-hooks

OCA's custom pre-commit hooks for Odoo modules

Installation

You don't need to install it directly only configure your ".pre-commit-config.yaml" file

You even can install it directly:

  • Installing from pypi:

    • pip install -U oca-odoo-pre-commit-hooks
  • Installing from github:

    • pip install --force-reinstall -U git+https://github.com/OCA/odoo-pre-commit-hooks.git@main

Usage pre-commit-config.yaml

Add to your ".pre-commit-config.yaml" configuration file the following input

    - repo: https://github.com/OCA/odoo-pre-commit-hooks
        rev: v0.1.0
        hooks:
        - id: oca-checks-odoo-module
        - id: oca-checks-po
          args: ["--fix"]

Usage directly the entry points

If you install directly the package use the entry point:

oca-checks-odoo-module --help
oca-checks-po --help

Skip one xml-check for only one file

If you need to skip one check in one particular XML file you can use the follow comment

<?xml version="1.0" encoding="utf-8"?>
<!-- oca-hooks:disable=xml-check-to-skip -->
<odoo>
...
</odoo>
<?xml version="1.0" encoding="utf-8"?>
<!-- oca-hooks:disable=xml-check-to-skip,
                       xml-check-to-skip2 -->
<odoo>
...
</odoo>

The position of the comment it is not relative to the line that throw the check

It disable the entire file

Configuration

Behavior can be configured through several methods and as of now only consists of enabling/disabling checks.

Enabling or Disabling Checks

Each available hook consists of multiple checks which can be enabled/disabled using any of the following methods (ordered by priority):

  1. As an argument e.g., oca-checks-odoo --enable=check-to-enable --disable=check-to-disable1,check-to-disable2
  2. Using environment variables OCA_HOOKS_ENABLE or OCA_HOOKS_DISABLE e.g., export OCA_HOOKS_ENABLE=check1,check2
  3. A configuration file. The path to it can be specified with the argument --config. Alternatively a file named .oca_hooks.cfg will be looked for (by default) in the following locations (in order):
    1. Current working directory
    2. Repo's root
    3. User's home

Using a Configuration File

To enable or disable checks using a configuration file, add a disable or enable key under the MESSAGES_CONTROL section. For example:

[MESSAGES_CONTROL]
enable=check-enable1,check-enable2
disable=check-to-disable

As stated before, each source has a certain priority. This means that if the environment variable OCA_HOOKS_ENABLE=check1 exists, the configuration file above would not have any effect when it comes to enabling checks, and the only enabled check will be check1.

However, if OCA_HOOKS_DISABLE is not set, the configuration file will still have an effect and check-to-disable will be disabled.

Checks

  • Check manifest-syntax-error Check if the manifest file has syntax error

  • Check csv-duplicate-record-id duplicate CSV "id" AKA xmlid but for CSV files

  • Check csv-syntax-error Check syntax error for CSV files declared in the manifest

  • Check xml-deprecated-data-node Deprecated node inside xml node

  • Check xml-deprecated-openerp-node deprecated xml node

  • Check xml-deprecated-qweb-directive for use of deprecated QWeb directives t-*-options

  • Check xml-not-valid-char-link The resource in in src/href contains a not valid character.

  • Check xml-oe-structure-missing-id

Ensure all tags with class 'oe_structure' have an ID. For more information on the rationale, see: https://github.com/OCA/odoo-pre-commit-hooks/issues/27

  • Check xml-redundant-module-name

If the module is called "module_a" and the xmlid is <record id="module_a.xmlid_name1" ...

The "module_a." is redundant it could be replaced to only <record id="xmlid_name1" ...

  • Check xml-dangerous-filter-wo-user Check dangerous filter without a user assigned.

  • Check xml-create-user-wo-reset-password records of user without context="{'no_reset_password': True}" This context avoid send email and mail log warning

  • Check xml-view-dangerous-replace-low-priority in ir.ui.view

    ...
  • Check xml-deprecated-tree-attribute The tree-view declaration is using a deprecated attribute.

  • Check xml-record-missing-id Generated when a tag has no id.

  • Check xml-duplicate-record-id

If a module has duplicated record_id AKA xml_ids file1.xml <record id="xmlid_name1" file2.xml <record id="xmlid_name1"

  • Check xml-duplicate-fields in all record nodes <record id="xmlid_name1"... <field name="field_name1"... <field name="field_name1"...

  • Check xml-syntax-error Check syntax of XML files declared in the Odoo manifest

  • Check xml-dangerous-qweb-replace-low-priority Dangerous qweb view defined with low priority

  • Check xml-duplicate-template-id Triggered when two templates share the same ID

  • Check xml-xpath-translatable-item check xpath nodes using contains(text(), 'Text translatable') Since that the text could be translated so it is a mutable value. It could raise ValueError exception if the language is changed.

Checks PO

  • Check po-requires-module Translation entry requires comment #. module: MODULE

  • Check po-python-parse-printf Check if msgid is using str variables like %s So translation msgstr must be the same number of variables too

  • Check po-python-parse-format Check if msgid is using str variables like {} So translation msgstr must be the same number of variables too

  • Check po-duplicate-message-definition (message-id) in all entries of PO files

  • Check po-duplicate-model-definition Verify that no entries share the same 'model:' tag

  • Check po-pretty-format Check the following:

  1. Entries sorted alphabetically
  2. Lines are wrapped at 78 columns (same as Odoo)
  3. Clear msgstr when it is the same as msgid
  • Check po-syntax-error Check syntax of PO files from i18n* folders

Help

usage: oca-checks-odoo-module [-h] [--no-verbose] [--no-exit] [--disable DISABLE] [--enable ENABLE] [--config CONFIG] [--list-msgs] [--fix] [files_or_modules ...]

positional arguments:
 files_or_modules Odoo __manifest__.py paths or Odoo module paths.

options:
 -h, --help show this help message and exit
 --no-verbose If enabled so disable verbose mode.
 --no-exit If enabled so it will not call exit.
 --disable, -d DISABLE Disable the checker with the given 'check-name', separated by commas.
 --enable, -e ENABLE Enable the checker with the given 'check-name', separated by commas. Default: All checks are enabled by default
 --config, -c CONFIG Path to a configuration file (default: .oca_hooks.cfg)
 --list-msgs List all currently enabled messages.
 --fix Automatically fix files when possible

Help PO

usage: oca-checks-po [-h] [--no-verbose] [--no-exit] [--disable DISABLE] [--enable ENABLE] [--config CONFIG] [--list-msgs] [--fix] [po_files ...]

positional arguments:
 po_files PO files.

options:
 -h, --help show this help message and exit
 --no-verbose If enabled so disable verbose mode.
 --no-exit If enabled so it will not call exit.
 --disable, -d DISABLE Disable the checker with the given 'check-name', separated by commas.
 --enable, -e ENABLE Enable the checker with the given 'check-name', separated by commas. Default: All checks are enabled by default
 --config, -c CONFIG Path to a configuration file (default: .oca_hooks.cfg)
 --list-msgs List all currently enabled messages.
 --fix Automatically fix files when possible

Examples

Examples PO

Licenses

This repository is licensed under AGPL-3.0.


OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use.

CHANGES

v0.1.0

  • [REF] checks_odoo_module_po: Remove special char incompatible with windows codecs (#117)
  • [REF] README: Update readme with new py3.13 version
  • [REF] setup.py: Deprecate py3.8-

v0.0.35

  • [FIX] po-pretty-format: Allow original=translated term for "i18n_extra" folder (#113)

v0.0.34

  • [IMP] *: Display the duplicated lines (#111)
  • [REF] tox.ini: Add compatibility with new pyttest (#112)
  • [IMP] csv-duplicate-record-id: show the actual record id
  • [IMP] xml-duplicate-record-id: show the actual record id

v0.0.33

  • [IMP] check_odoo_module_po: extract line number from error message (#108)
  • [IMP] Better error output (#106)

v0.0.32

v0.0.31

  • [REF] setup: Add py3.12 support info (#98)
  • [REF] .github: Update actions version, fix cache and update lints (#97)
  • [REF] tests: Fixing windows po autofix unitest (#96)

v0.0.30

  • CI improvements (#93)
  • [REF] setup: Enable py311 classifier (#87)

v0.0.29

  • IMP] add xml-duplicate-template-id message (#82)
  • [FIX] lints (#86)
  • [ADD] po-duplicate-model-definition check (#85)
  • [REF] Don't filter out messages, move is_message_enabled (#83)
  • [IMP] add xml-record-missing-id (#84)

v0.0.28

  • [FIX] oe-structure-missing-id: change constraints, add docs (#81)

v0.0.27

  • [REF] improve xpath expressions (#80)

v0.0.26

  • [IMP] Improve XPath expressions, compile them only once, fix false negative, add profiling tests (#79)
  • [ADD] pretty-format-po check (#76)
  • [IMP] add xml-oe-structure-missing-id check (#78)
  • [REF] tests: Generate immutable readme (without extra spaces)
  • [IMP] README: Added a section on configuration

v0.0.25

  • [REF] requirements.txt: Update polib to fix issues and improves (#72)

v0.0.24

  • [FIX] pre-commit: Fix isort hook - RuntimeError The Poetry configuration is invalid (#71)

v0.0.23

  • [FIX] Correct documentation (#69)

v0.0.22

  • [IMP] Help msg for "xml-view-dangerous-replace-low-priority" (#68)
  • Wrote documentation for proposed refactoring (#66)
  • [FIX] ci: update flake8 repo URL, tox.ini and gh actions .yml (#65)
  • [REF] hooks: Add support for `` (#62)

v0.0.21

  • [REF] duplicate-xml-fields: Only applies to direct record's children (#58)

v0.0.20

  • [FIX] xml-xpath-translatable-item: Fix false negative calling a method o.amount_to_text() (#57)

v0.0.19

  • [FIX] setup: Add missing "requirements.txt" file to package (#441) (#55)

v0.0.18

  • [FIX] checks_odoo_module: Support glob expression for "qweb" manifest data section (#54)
  • [IMP] oca_pre_commit_hooks: Add --list-msgs option (#53)
  • [REF] oca_pre_commit_hooks: Silent subprocess git error (#52)

v0.0.17

  • [IMP] oca_pre_commit_hooks: Support enable/disable from ENV (#38) (#49)

v0.0.16

  • [ADD] xml-xpath-translatable-item: Add new check to identify mutable item used from xpath (#50)

v0.0.15

  • [FIX] oca_pre_commit_hooks: Fix exit_status false error (#48)

v0.0.14

  • [IMP] oca_pre_commit_hooks: Support for config file (#41)

v0.0.13

  • [REF] pylint_odoo: Remove TODO comments (#47)
  • [REF] requirements: Remove unused libraries and pre-commit hooks (#45)
  • [REF] xml-deprecated-data-node: Use the data node sourceline instead of odoo node (#43)
  • [IMP] oca_pre_commit_hooks: Support disable XML checks from disable comments (#42)
  • [REF] README: Fix name of pypi package (#35)
  • [REF] oca_pre_commit_hooks: cli_po, cli: Add cli_po and cli global (#36)
  • [REF] setup: Match requires-python = ">=3.7" from pre-commit
  • [REF] CI: Enable py3.11

v0.0.12

  • [REF] checks_odoo_module_xml: Allow duplicated fields with 'groups' (#32)
  • [REF] CI: Enable tox with parallels + codecov compatibility (#33)

v0.0.11

  • [REF] codecov: Enable codecov again
  • [REM] missing-readme: Check add to pylint-odoo
  • [REF] TOX: Strip names, remove no-cover, compatible with parallels option (#24)
  • [REF] lint: Adapt lints for py packages instead of odoo module (#23)

v0.0.10

  • [REF] README: Update README and fix mutable results auto-generating it (#22)
  • [REF] checks_odoo_module_po: Run on modified PO files only (#21)
  • [REF] manifest: Skip duplicated data files (#20)

v0.0.9

  • [FIX] README: Fix regex to replace autogenerated content (#18)
  • [REF] README: Detect from CI if README needs to be updated (#17)

v0.0.8

  • [REF] README: Add examples of checks section and script to auto-generate it (#16)
  • [REF] README: Add help section and script to auto-generate it (#15)

v0.0.7

  • [REF] checks: name_checks changed to name-checks (#14)
  • [REF] oca_pre_commit_hooks: Use shorter path in messages (#13)
  • [FIX] pre-commit-hooks.yaml: Run checks even if the manifest was not changed
  • [REF] test: Remove TODO comments already fixed

v0.0.6

  • [FIX] oca_pre_commit_hooks: Fix checks if it has syntax error (#8)

v0.0.5

  • [REF] oca_pre_commit_hooks: Small improvements (#7)

v0.0.4

  • [IMP] oca_pre_commit_hooks: Enable feature to 'enable' checks (#6)
  • [IMP] oca_pre_commit_hooks: Add entrypoint arguments to disable checks (#5)

v0.0.3

  • [REF] README: Remove deprecated CI build

v0.0.2

  • [REF] CI: Re-use tox to run pre-commit in the CI with same caches and packages
  • [ADD] .pre-commit-hooks.yaml: Compatible with pre-commit-hooks to use as hook id directly

v0.0.1

  • [ADD] Migrate pylint-odoo checks (not related to python) to pre-commit hooks (#2)
  • Initialize

Metadata

Release files for oca-odoo-pre-commit-hooks 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for oca-odoo-pre-commit-hooks 0.1.0
File Size Uploaded Provenance Actions
oca_odoo_pre_commit_hooks-0.1.0.tar.gz 52.0 kB Without provenance Details for oca_odoo_pre_commit_hooks-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for oca-odoo-pre-commit-hooks 0.1.0
File Interpreter ABI Platform Actions
oca_odoo_pre_commit_hooks-0.1.0-py3-none-any.whl Python 3 none any Details for oca_odoo_pre_commit_hooks-0.1.0-py3-none-any.whl

Total release size: 93.7 kB

Release files / oca_odoo_pre_commit_hooks-0.1.0.tar.gz

Download URL oca_odoo_pre_commit_hooks-0.1.0.tar.gz
Size 52.0 kB
Tags Source
SHA-256 checksum
How to use checksums
ab44a05c42bdc6a64e0902573f8169b7ad5803e8a085ed86d8456086d26bd474
BLAKE2b-256 checksum
How to use checksums
9b983c332591ac93aea79945fbb091170b6a017a4b3bdd72cf6ac85e7095fb6f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.1

Release files / oca_odoo_pre_commit_hooks-0.1.0-py3-none-any.whl

Download URL oca_odoo_pre_commit_hooks-0.1.0-py3-none-any.whl
Size 41.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d789d58d9b5dbd94d69a3470800d41544e841172f642353dffbda73cb2d315f9
BLAKE2b-256 checksum
How to use checksums
04c8fdd80ea76d82e05fb5017fb1cc9a8d754ef4a5766595cac335f45f2f716c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.1

Security for oca-odoo-pre-commit-hooks 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page