From db02f748058d72f15c9ecf8b09991df4302e1716 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Bidoul?= Date: Thu, 18 Jan 2024 16:48:23 +0100 Subject: [PATCH 1/4] Factor out listing of addons to test. --- bin/oca_list_addons_to_test | 17 +++++++++++++++++ bin/oca_run_tests | 6 +----- 2 files changed, 18 insertions(+), 5 deletions(-) create mode 100755 bin/oca_list_addons_to_test diff --git a/bin/oca_list_addons_to_test b/bin/oca_list_addons_to_test new file mode 100755 index 0000000..544b64e --- /dev/null +++ b/bin/oca_list_addons_to_test @@ -0,0 +1,17 @@ +#!/bin/bash + +# +# Print addons to test, comma separated. +# Take INCLUDE and EXCLUDE variables into account. +# Do not list addons that are not installable. +# + +set -ex + +if [ -n "${INCLUDE}" ]; then + ADDONS=$(manifestoo --select-include "${INCLUDE}" --select-exclude "${EXCLUDE}" list --separator=,) +else + ADDONS=$(manifestoo --select-addons-dir ${ADDONS_DIR} --select-exclude "${EXCLUDE}" list --separator=,) +fi + +echo $ADDONS diff --git a/bin/oca_run_tests b/bin/oca_run_tests index 02823c2..728187c 100755 --- a/bin/oca_run_tests +++ b/bin/oca_run_tests @@ -8,11 +8,7 @@ set -ex oca_wait_for_postgres -if [ -n "${INCLUDE}" ]; then - ADDONS=$(manifestoo --select-include "${INCLUDE}" --select-exclude "${EXCLUDE}" list --separator=,) -else - ADDONS=$(manifestoo --select-addons-dir ${ADDONS_DIR} --select-exclude "${EXCLUDE}" list --separator=,) -fi +ADDONS=$(oca_list_addons_to_test) if [ -z "$ADDONS" ]; then exit 0 fi From 66b7aa6655c34781773990898db0e8297046fd74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Bidoul?= Date: Thu, 18 Jan 2024 16:48:51 +0100 Subject: [PATCH 2/4] Add script to list addons to test as pip requirements --- bin/oca_list_addons_to_test_as_reqs | 49 +++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100755 bin/oca_list_addons_to_test_as_reqs diff --git a/bin/oca_list_addons_to_test_as_reqs b/bin/oca_list_addons_to_test_as_reqs new file mode 100755 index 0000000..de705b2 --- /dev/null +++ b/bin/oca_list_addons_to_test_as_reqs @@ -0,0 +1,49 @@ +#!/usr/bin/env python + +# +# Print addons to test as pip requirements pointing to local directories. +# There is an option to make them editable or file URLs. +# + +import argparse +import os +import subprocess +from pathlib import Path + + +def _make_addon_dist_name(name: str) -> str: + odoo_series = int(os.getenv("ODOO_VERSION").partition(".")[0]) + return f"odoo{odoo_series if odoo_series < 15 else ''}-addon-{name}" + + +def _make_addon_req(path: Path, editable: bool) -> str: + if editable: + return f"-e {path.resolve().as_uri()}#egg={_make_addon_dist_name(path.name)}" + return f"{_make_addon_dist_name(path.name)} @ {path.resolve().as_uri()}" + + +def _list_addons_to_test(): + return ( + subprocess.check_output(["oca_list_addons_to_test"], universal_newlines=True) + .strip() + .split(",") + ) + + +parser = argparse.ArgumentParser() +parser.add_argument( + "--editable", + action="store_true", + help="Path to addons dir", +) +args = parser.parse_args() + +addons_dir = Path(os.getenv("ADDONS_DIR", ".")) +for addon_name in _list_addons_to_test(): + pyproject_path = addons_dir / addon_name / "pyproject.toml" + if pyproject_path.exists(): + print(_make_addon_req(pyproject_path.parent, args.editable)) + else: + setuppy_path = addons_dir / "setup" / addon_name / "setup.py" + if setuppy_path.exists(): + print(_make_addon_req(setuppy_path.parent, args.editable)) From 77a490c6ee30339895246fed2959b11ea453e3ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Bidoul?= Date: Thu, 18 Jan 2024 16:51:26 +0100 Subject: [PATCH 3/4] Handle circular dependencies between repos When an addon on the branch being tested is also a dependency of another addon of the same repo, be sure to install the one from the current checkout, by adding constraints to the command that install dependencies. --- bin/oca_install_addons | 18 +++++++++++++----- bin/oca_list_addons_to_test_as_reqs | 19 ++++++++++++++----- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/bin/oca_install_addons b/bin/oca_install_addons index a63cd41..88d8ec0 100755 --- a/bin/oca_install_addons +++ b/bin/oca_install_addons @@ -25,12 +25,21 @@ env SETUPTOOLS_ODOO_POST_VERSION_STRATEGY_OVERRIDE=none \ --ignore-build-errors \ ${ADDONS_DIR}/*/pyproject.toml ${ADDONS_DIR}/setup/*/setup.py \ >> test-requirements.txt - -# Install addons in current repo in editable mode, so coverage will see them. cat test-requirements.txt -pip install -r test-requirements.txt + +# To be sure to install addons from this repo if they are dependencies of dependencies, +# we create a constraints file with local directory references to the addons to test. +oca_list_addons_to_test_as_reqs >> test-constraints.txt +cat test-constraints.txt + +# show pip config pip config list -pip list + +# Install dependencies of addons to test. +pip install -r test-requirements.txt -c test-constraints.txt + +# show what we have installed +pip freeze # Add ADDONS_DIR to addons_path. echo "addons_path=${ADDONS_PATH},${ADDONS_DIR}" >> ${ODOO_RC} @@ -42,4 +51,3 @@ if [ -n "$deps" ]; then # Install 'deb' external dependencies of all Odoo addons found in path. DEBIAN_FRONTEND=noninteractive apt-get install -qq --no-install-recommends ${deps} fi - diff --git a/bin/oca_list_addons_to_test_as_reqs b/bin/oca_list_addons_to_test_as_reqs index de705b2..bf9f286 100755 --- a/bin/oca_list_addons_to_test_as_reqs +++ b/bin/oca_list_addons_to_test_as_reqs @@ -11,15 +11,24 @@ import subprocess from pathlib import Path -def _make_addon_dist_name(name: str) -> str: +def _make_addon_dist_name(name): odoo_series = int(os.getenv("ODOO_VERSION").partition(".")[0]) - return f"odoo{odoo_series if odoo_series < 15 else ''}-addon-{name}" + return "odoo{odoo_series}-addon-{name}".format( + name=name, + odoo_series=odoo_series if odoo_series < 15 else "", + ) -def _make_addon_req(path: Path, editable: bool) -> str: +def _make_addon_req(path, editable): + addon_uri = path.resolve().as_uri() + addon_dist_name = _make_addon_dist_name(path.name) if editable: - return f"-e {path.resolve().as_uri()}#egg={_make_addon_dist_name(path.name)}" - return f"{_make_addon_dist_name(path.name)} @ {path.resolve().as_uri()}" + return "-e {addon_uri}#egg={addon_dist_name}".format( + addon_uri=addon_uri, addon_dist_name=addon_dist_name + ) + return "{addon_dist_name} @ {addon_uri}".format( + addon_dist_name=addon_dist_name, addon_uri=addon_uri + ) def _list_addons_to_test(): From 08c850e4196c6265e9f51fe0d97cbe7bf1e8c003 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Bidoul?= Date: Thu, 18 Jan 2024 20:09:20 +0100 Subject: [PATCH 4/4] Python 3.5 is really old... --- bin/oca_install_addons | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/bin/oca_install_addons b/bin/oca_install_addons index 88d8ec0..dc1aae6 100755 --- a/bin/oca_install_addons +++ b/bin/oca_install_addons @@ -29,7 +29,13 @@ cat test-requirements.txt # To be sure to install addons from this repo if they are dependencies of dependencies, # we create a constraints file with local directory references to the addons to test. -oca_list_addons_to_test_as_reqs >> test-constraints.txt +if python -c 'import sys; sys.exit(sys.version_info < (3,6))' ; then + # python >= 3.6 + oca_list_addons_to_test_as_reqs >> test-constraints.txt +else + # old python where pip does not support URL constraints + touch test-constraints.txt +fi cat test-constraints.txt # show pip config