From 1dbd247f97ee3deeb7ba92d19477b2c8c8e9618b Mon Sep 17 00:00:00 2001 From: "Moises Lopez - https://www.vauxoo.com/" Date: Fri, 10 Jan 2025 15:10:48 -0600 Subject: [PATCH] [REF] pre_commit_vauxoo: pylint checks support define python version variables.sh has 'TRAVIS_PYTHON_VERSION' with the python version to use for each project --- src/pre_commit_vauxoo/cfg/.pylintrc | 1 + src/pre_commit_vauxoo/cfg/.pylintrc-optional | 1 + src/pre_commit_vauxoo/cli.py | 7 +++++++ src/pre_commit_vauxoo/pre_commit_vauxoo.py | 9 +++++++++ variables.sh | 1 + 5 files changed, 19 insertions(+) diff --git a/src/pre_commit_vauxoo/cfg/.pylintrc b/src/pre_commit_vauxoo/cfg/.pylintrc index 67f0880..fa2f0f8 100644 --- a/src/pre_commit_vauxoo/cfg/.pylintrc +++ b/src/pre_commit_vauxoo/cfg/.pylintrc @@ -4,6 +4,7 @@ persistent=yes # This extension are not used for this configuration file but are useful to process disable comments based on these ones load-plugins=pylint.extensions.docstyle, pylint.extensions.mccabe, pylint_odoo extension-pkg-whitelist=lxml +# External scripts main replace [ODOOLINT] readme-template-url="https://github.com/OCA/maintainer-tools/blob/master/template/module/README.rst" diff --git a/src/pre_commit_vauxoo/cfg/.pylintrc-optional b/src/pre_commit_vauxoo/cfg/.pylintrc-optional index 87b97a4..495242d 100644 --- a/src/pre_commit_vauxoo/cfg/.pylintrc-optional +++ b/src/pre_commit_vauxoo/cfg/.pylintrc-optional @@ -3,6 +3,7 @@ profile=no ignore=CVS,.git,scenarios,.bzr persistent=yes load-plugins=pylint.extensions.docstyle, pylint.extensions.mccabe, pylint_odoo +# External scripts main replace [ODOOLINT] readme-template-url="https://github.com/OCA/maintainer-tools/blob/master/template/module/README.rst" diff --git a/src/pre_commit_vauxoo/cli.py b/src/pre_commit_vauxoo/cli.py index 7009845..4b21341 100644 --- a/src/pre_commit_vauxoo/cli.py +++ b/src/pre_commit_vauxoo/cli.py @@ -303,6 +303,13 @@ def precommit_hooks_type_callback(ctx, param, value): help="Odoo version used for the repository.", **new_extra_kwargs, ) +@click.option( + "--py-version", + envvar="TRAVIS_PYTHON_VERSION", + type=click.STRING, + help="Python version used for the repository.", + **new_extra_kwargs, +) def main(*args, **kwargs): """pre-commit-vauxoo run pre-commit with custom validations and configuration files""" version = kwargs.pop("version", None) diff --git a/src/pre_commit_vauxoo/pre_commit_vauxoo.py b/src/pre_commit_vauxoo/pre_commit_vauxoo.py index aaaaa81..7a6e059 100644 --- a/src/pre_commit_vauxoo/pre_commit_vauxoo.py +++ b/src/pre_commit_vauxoo/pre_commit_vauxoo.py @@ -77,6 +77,10 @@ def get_uninstallable_modules(src_path) -> set: return results +# copy_cfg_files has too many "for-if" sentences +# because it is a switch-case dummy logic +# TODO: Migrate this method to use configuration files with jinja template +# pylint: disable=too-complex def copy_cfg_files( precommit_config_dir, repo_dirname, @@ -87,6 +91,7 @@ def copy_cfg_files( exclude_autofix, skip_string_normalization, odoo_version, + py_version, ): exclude_lint_regex = "" exclude_autofix_regex = "" @@ -139,6 +144,8 @@ def copy_cfg_files( if fname.startswith(".pylintrc"): if "# External scripts odoo_lint replace" in line and odoo_version: line += "valid-odoo-version=%s\n" % odoo_version + elif py_version and line.startswith("# External scripts main replace"): + line += f"py-version={py_version}\n" fdst.write(line) @@ -184,6 +191,7 @@ def main( install, skip_string_normalization, odoo_version, + py_version, do_exit=True, ): show_version() @@ -215,6 +223,7 @@ def main( exclude_autofix, skip_string_normalization, odoo_version, + py_version, ) _logger.info("Installing pre-commit hooks") cmd = ["pre-commit", "install-hooks", "--color=always"] diff --git a/variables.sh b/variables.sh index 2e351d0..53d5c17 100644 --- a/variables.sh +++ b/variables.sh @@ -3,3 +3,4 @@ export PRECOMMIT_HOOKS_TYPE="all" export EXCLUDE_LINT="resources/module_warnings1,resources/module_uninstallable" export EXCLUDE_AUTOFIX="resources/module_autofix1" export VERSION="16.0" +export TRAVIS_PYTHON_VERSION="3.13"