From 5dd8687f55fea15a43d585a0d048840fdb13bbb9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Bidoul?= <stephane.bidoul@gmail.com>
Date: Fri, 19 Jan 2024 11:57:22 +0100
Subject: [PATCH] Refactor oca_install_addons

Extract logic in a separate script to make it easier to swap the implementation
---
 bin/oca_install_addons                       | 59 +-------------------
 bin/oca_install_addons__deps_and_addons_path | 59 ++++++++++++++++++++
 2 files changed, 60 insertions(+), 58 deletions(-)
 create mode 100755 bin/oca_install_addons__deps_and_addons_path

diff --git a/bin/oca_install_addons b/bin/oca_install_addons
index dc1aae6..d1ea37c 100755
--- a/bin/oca_install_addons
+++ b/bin/oca_install_addons
@@ -1,59 +1,2 @@
 #!/bin/bash
-
-#
-# Install dependencies of addons to test, and add addons to test to Odoo's addons_path.
-#
-# An alternative technique would be to install all addons with `pip install --editable`
-# but it is relatively slow in repos with a large number of addons. This is an area
-# where pip could improve.
-#
-
-set -ex
-shopt -s nullglob  # in case there is setup.py nor pyproject.toml
-
-# Compute and install direct dependencies of installable addons in $ADDONS_DIR
-# (this includes addons, python external dependencies and odoo itself).
-# The environment variables are for better perfomance as we are interested in
-# the dependencies metadata only, and not the exact versions.
-# --no-isolation is for performance. The Dockerfile has setuptools-odoo and whool
-# preinstalled in the same environment as pyproject-dependencies.
-# --ignore-build-errors is needed to avoid errors with uninstallable addons.
-env SETUPTOOLS_ODOO_POST_VERSION_STRATEGY_OVERRIDE=none \
-    WHOOL_POST_VERSION_STRATEGY_OVERRIDE=none \
-    pyproject-dependencies \
-      --no-isolation \
-      --ignore-build-errors \
-      ${ADDONS_DIR}/*/pyproject.toml ${ADDONS_DIR}/setup/*/setup.py \
-      >> test-requirements.txt
-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.
-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
-pip config 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}
-cat ${ODOO_RC}
-
-deps=$(oca_list_external_dependencies deb)
-if [ -n "$deps" ]; then
-    apt-get update -qq
-    # Install 'deb' external dependencies of all Odoo addons found in path.
-    DEBIAN_FRONTEND=noninteractive apt-get install -qq --no-install-recommends ${deps}
-fi
+oca_install_addons__deps_and_addons_path
diff --git a/bin/oca_install_addons__deps_and_addons_path b/bin/oca_install_addons__deps_and_addons_path
new file mode 100755
index 0000000..dc1aae6
--- /dev/null
+++ b/bin/oca_install_addons__deps_and_addons_path
@@ -0,0 +1,59 @@
+#!/bin/bash
+
+#
+# Install dependencies of addons to test, and add addons to test to Odoo's addons_path.
+#
+# An alternative technique would be to install all addons with `pip install --editable`
+# but it is relatively slow in repos with a large number of addons. This is an area
+# where pip could improve.
+#
+
+set -ex
+shopt -s nullglob  # in case there is setup.py nor pyproject.toml
+
+# Compute and install direct dependencies of installable addons in $ADDONS_DIR
+# (this includes addons, python external dependencies and odoo itself).
+# The environment variables are for better perfomance as we are interested in
+# the dependencies metadata only, and not the exact versions.
+# --no-isolation is for performance. The Dockerfile has setuptools-odoo and whool
+# preinstalled in the same environment as pyproject-dependencies.
+# --ignore-build-errors is needed to avoid errors with uninstallable addons.
+env SETUPTOOLS_ODOO_POST_VERSION_STRATEGY_OVERRIDE=none \
+    WHOOL_POST_VERSION_STRATEGY_OVERRIDE=none \
+    pyproject-dependencies \
+      --no-isolation \
+      --ignore-build-errors \
+      ${ADDONS_DIR}/*/pyproject.toml ${ADDONS_DIR}/setup/*/setup.py \
+      >> test-requirements.txt
+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.
+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
+pip config 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}
+cat ${ODOO_RC}
+
+deps=$(oca_list_external_dependencies deb)
+if [ -n "$deps" ]; then
+    apt-get update -qq
+    # Install 'deb' external dependencies of all Odoo addons found in path.
+    DEBIAN_FRONTEND=noninteractive apt-get install -qq --no-install-recommends ${deps}
+fi