Home

Awesome

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:

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.0.34
        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

Checks PO

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 DISABLE, -d DISABLE Disable the checker with the given 'check-name', separated by commas.
 --enable ENABLE, -e ENABLE Enable the checker with the given 'check-name', separated by commas. Default: All checks are enabled by default
 --config 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 DISABLE, -d DISABLE Disable the checker with the given 'check-name', separated by commas.
 --enable ENABLE, -e ENABLE Enable the checker with the given 'check-name', separated by commas. Default: All checks are enabled by default
 --config 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.