Skip to content

Commit

Permalink
Merge pull request #52 from sbidoul/pyproject-dependencies
Browse files Browse the repository at this point in the history
Use a standard-based way to get dependencies
  • Loading branch information
sbidoul authored Oct 21, 2023
2 parents ce29b09 + ff05e78 commit 2201e9c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 16 deletions.
7 changes: 4 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,10 @@ RUN pipx install --pip-args="--no-cache-dir" "virtualenv$virtualenv_constraint"
# We use manifestoo to check licenses, development status and list addons and dependencies
RUN pipx install --pip-args="--no-cache-dir" "manifestoo>=0.3.1"

# Install setuptools-odoo-get-requirements and setuptools-odoo-makedefault helper
# scripts.
RUN pipx install --pip-args="--no-cache-dir" "setuptools-odoo>=3.0.7"
# Install pyproject-dependencies helper scripts.
ARG build_deps="setuptools-odoo wheel whool"
RUN pipx install --pip-args="--no-cache-dir" pyproject-dependencies
RUN pipx inject --pip-args="--no-cache-dir" pyproject-dependencies $build_deps

# Make a virtualenv for Odoo so we isolate from system python dependencies and
# make sure addons we test declare all their python dependencies properly
Expand Down
18 changes: 15 additions & 3 deletions bin/oca_install_addons
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,26 @@
#
# 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 and/or setuptools could improve.
# 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)
setuptools-odoo-get-requirements --include-addons --addons-dir ${ADDONS_DIR} >> test-requirements.txt
# (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

# Install addons in current repo in editable mode, so coverage will see them.
cat test-requirements.txt
Expand Down
22 changes: 12 additions & 10 deletions tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import shutil
import subprocess
import tempfile
import textwrap
from pathlib import Path

ODOO_VENV = "/opt/odoo-venv"
Expand Down Expand Up @@ -44,6 +45,7 @@ def make_addons_dir(test_addons):
Adjust the addons version to match the Odoo version being tested.
Rename __manifest__.py to __openerp__.py for older Odoo versions.
Add pyproject.toml.
"""
with tempfile.TemporaryDirectory() as tmpdir:
tmppath = Path(tmpdir)
Expand All @@ -56,6 +58,16 @@ def make_addons_dir(test_addons):
manifest_path.write_text(repr(manifest))
if odoo_version_info < (10, 0):
manifest_path.rename(manifest_path.parent / "__openerp__.py")
pyproject_toml_path = tmppath / addon_name / "pyproject.toml"
pyproject_toml_path.write_text(
textwrap.dedent(
"""\
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
"""
)
)
yield tmppath


Expand All @@ -64,16 +76,6 @@ def install_test_addons(test_addons):
with preserve_odoo_rc(), preserve_odoo_venv(), make_addons_dir(
test_addons
) as addons_dir:
subprocess.check_call(
[
"setuptools-odoo-make-default",
"-d",
".",
"--odoo-version-override",
os.environ["ODOO_VERSION"],
],
cwd=addons_dir,
)
subprocess.check_call(["oca_install_addons"], cwd=addons_dir)
yield addons_dir

Expand Down

0 comments on commit 2201e9c

Please sign in to comment.