fixup! [ADD] guess requirements feature

This commit is contained in:
Sylvain LE GAL 2024-11-04 20:45:55 +01:00
parent 68bfe19acd
commit 0bfacbd133
19 changed files with 105 additions and 64 deletions

View File

@ -242,8 +242,8 @@ For each module and each version, this command tries to parse the
according ``__manifest__.py`` file (and, if possible the according ``setup.py`` file). according ``__manifest__.py`` file (and, if possible the according ``setup.py`` file).
Finally, it overwrite the requirements.txt files present in each env folder. (python and debian requirements). Finally, it overwrite the requirements.txt files present in each env folder. (python and debian requirements).
For exemple, here is the content of the ``extra_python_requirements.txt`` file, For exemple, here is the content of the ``addons_python_requirements.txt`` file,
when ``barcodes_generator_abstract`` and ``l10n_fr_siret`` are installed. when ``barcodes_generator_abstract`` and ``l10n_fr_siret`` are installed (for V16).
``` ```
# Required by the module(s): barcodes_generator_abstract # Required by the module(s): barcodes_generator_abstract

View File

@ -38,13 +38,13 @@ def guess_requirement(ctx, extra_modules_list):
for odoo_version in [x for x in ctx.obj["config"]["odoo_versions"]]: for odoo_version in [x for x in ctx.obj["config"]["odoo_versions"]]:
path_version = get_odoo_env_path(ctx, odoo_version) path_version = get_odoo_env_path(ctx, odoo_version)
ensure_file_exists_from_template( ensure_file_exists_from_template(
path_version / Path("extra_python_requirements.txt"), path_version / Path("addons_python_requirements.txt"),
"odoo/extra_python_requirements.txt.j2", "odoo/addons_python_requirements.txt.j2",
dependencies=result[odoo_version]["python"], dependencies=result[odoo_version]["python"],
) )
ensure_file_exists_from_template( ensure_file_exists_from_template(
path_version / Path("extra_debian_requirements.txt"), path_version / Path("addons_debian_requirements.txt"),
"odoo/extra_debian_requirements.txt.j2", "odoo/addons_debian_requirements.txt.j2",
dependencies=result[odoo_version]["bin"], dependencies=result[odoo_version]["bin"],
) )

View File

@ -152,17 +152,27 @@ def init(
path_version = get_odoo_env_path(ctx, odoo_version) path_version = get_odoo_env_path(ctx, odoo_version)
ensure_folder_exists(path_version) ensure_folder_exists(path_version)
# Create python requirements file # Create python requirements files
ensure_file_exists_from_template( ensure_file_exists_from_template(
path_version / Path("extra_python_requirements.txt"), path_version / Path("extra_python_requirements.txt"),
"odoo/extra_python_requirements.txt.j2", "odoo/extra_python_requirements.txt.j2",
)
ensure_file_exists_from_template(
path_version / Path("addons_python_requirements.txt"),
"odoo/addons_python_requirements.txt.j2",
dependencies={}, dependencies={},
) )
# Create debian requirements file # Create debian requirements files
ensure_file_exists_from_template( ensure_file_exists_from_template(
path_version / Path("extra_debian_requirements.txt"), path_version / Path("extra_debian_requirements.txt"),
"odoo/extra_debian_requirements.txt.j2", "odoo/extra_debian_requirements.txt.j2",
)
ensure_file_exists_from_template(
path_version / Path("addons_debian_requirements.txt"),
"odoo/addons_debian_requirements.txt.j2",
dependencies={}, dependencies={},
) )

View File

@ -39,18 +39,22 @@ RUN apt-get update -qq && \
# <OOW> Install Debian packages # <OOW> Install Debian packages
COPY extra_debian_requirements.txt /extra_debian_requirements.txt COPY extra_debian_requirements.txt /extra_debian_requirements.txt
COPY addons_debian_requirements.txt /addons_debian_requirements.txt
RUN apt-get update -qq \ RUN apt-get update -qq \
&& apt-get install -y git \ && apt-get install -y git \
&& xargs apt-get install -y --no-install-recommends <extra_debian_requirements.txt \ && xargs apt-get install -y --no-install-recommends <extra_debian_requirements.txt \
&& xargs apt-get install -y --no-install-recommends <addons_debian_requirements.txt \
&& rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*
# <OOW> Install Python librairies # <OOW> Install Python librairies
COPY ./src/odoo/requirements.txt /odoo_python_requirements.txt COPY ./src/odoo/requirements.txt /odoo_python_requirements.txt
COPY addons_python_requirements.txt /addons_python_requirements.txt
COPY extra_python_requirements.txt /extra_python_requirements.txt COPY extra_python_requirements.txt /extra_python_requirements.txt
RUN pip3 install --upgrade pip \ RUN pip3 install --upgrade pip \
&& python3 -m pip install --no-cache-dir setuptools-scm \ && python3 -m pip install --no-cache-dir setuptools-scm \
&& python3 -m pip install --no-cache-dir -r /odoo_python_requirements.txt \ && python3 -m pip install --no-cache-dir -r /odoo_python_requirements.txt \
&& python3 -m pip install --no-cache-dir -r /extra_python_requirements.txt && python3 -m pip install --no-cache-dir -r /extra_python_requirements.txt \
&& python3 -m pip install --no-cache-dir -r /addons_python_requirements.txt
# <OOW> Get local user id and set it to the odoo user # <OOW> Get local user id and set it to the odoo user
ARG LOCAL_USER_ID ARG LOCAL_USER_ID

View File

@ -39,18 +39,22 @@ RUN apt-get update -qq && \
# <OOW> Install Debian packages # <OOW> Install Debian packages
COPY extra_debian_requirements.txt /extra_debian_requirements.txt COPY extra_debian_requirements.txt /extra_debian_requirements.txt
COPY addons_debian_requirements.txt /addons_debian_requirements.txt
RUN apt-get update -qq \ RUN apt-get update -qq \
&& apt-get install -y git \ && apt-get install -y git \
&& xargs apt-get install -y --no-install-recommends <extra_debian_requirements.txt \ && xargs apt-get install -y --no-install-recommends <extra_debian_requirements.txt \
&& xargs apt-get install -y --no-install-recommends <addons_debian_requirements.txt \
&& rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*
# <OOW> Install Python librairies # <OOW> Install Python librairies
COPY ./src/odoo/requirements.txt /odoo_python_requirements.txt COPY ./src/odoo/requirements.txt /odoo_python_requirements.txt
COPY addons_python_requirements.txt /addons_python_requirements.txt
COPY extra_python_requirements.txt /extra_python_requirements.txt COPY extra_python_requirements.txt /extra_python_requirements.txt
RUN pip3 install --upgrade pip \ RUN pip3 install --upgrade pip \
&& python3 -m pip install --no-cache-dir setuptools-scm \ && python3 -m pip install --no-cache-dir setuptools-scm \
&& python3 -m pip install --no-cache-dir -r /odoo_python_requirements.txt \ && python3 -m pip install --no-cache-dir -r /odoo_python_requirements.txt \
&& python3 -m pip install --no-cache-dir -r /extra_python_requirements.txt && python3 -m pip install --no-cache-dir -r /extra_python_requirements.txt \
&& python3 -m pip install --no-cache-dir -r /addons_python_requirements.txt
# <OOW> Get local user id and set it to the odoo user # <OOW> Get local user id and set it to the odoo user
ARG LOCAL_USER_ID ARG LOCAL_USER_ID

View File

@ -35,18 +35,22 @@ RUN apt-get update -qq && \
# <OOW> Install Debian packages # <OOW> Install Debian packages
COPY extra_debian_requirements.txt /extra_debian_requirements.txt COPY extra_debian_requirements.txt /extra_debian_requirements.txt
COPY addons_debian_requirements.txt /addons_debian_requirements.txt
RUN apt-get update -qq \ RUN apt-get update -qq \
&& apt-get install -y git \ && apt-get install -y git \
&& xargs apt-get install -y --no-install-recommends <extra_debian_requirements.txt \ && xargs apt-get install -y --no-install-recommends <extra_debian_requirements.txt \
&& xargs apt-get install -y --no-install-recommends <addons_debian_requirements.txt \
&& rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*
# <OOW> Install Python librairies # <OOW> Install Python librairies
COPY ./src/odoo/requirements.txt /odoo_python_requirements.txt COPY ./src/odoo/requirements.txt /odoo_python_requirements.txt
COPY addons_python_requirements.txt /addons_python_requirements.txt
COPY extra_python_requirements.txt /extra_python_requirements.txt COPY extra_python_requirements.txt /extra_python_requirements.txt
RUN pip3 install --upgrade pip \ RUN pip3 install --upgrade pip \
&& python3 -m pip install --no-cache-dir setuptools-scm \ && python3 -m pip install --no-cache-dir setuptools-scm \
&& python3 -m pip install --no-cache-dir -r /odoo_python_requirements.txt \ && python3 -m pip install --no-cache-dir -r /odoo_python_requirements.txt \
&& python3 -m pip install --no-cache-dir -r /extra_python_requirements.txt && python3 -m pip install --no-cache-dir -r /extra_python_requirements.txt \
&& python3 -m pip install --no-cache-dir -r /addons_python_requirements.txt
# <OOW> Get local user id and set it to the odoo user # <OOW> Get local user id and set it to the odoo user
ARG LOCAL_USER_ID ARG LOCAL_USER_ID

View File

@ -28,18 +28,22 @@ RUN apt-get update -qq && \
# <OOW> Install Debian packages # <OOW> Install Debian packages
COPY extra_debian_requirements.txt /extra_debian_requirements.txt COPY extra_debian_requirements.txt /extra_debian_requirements.txt
COPY addons_debian_requirements.txt /addons_debian_requirements.txt
RUN apt-get update -qq \ RUN apt-get update -qq \
&& apt-get install -y git \ && apt-get install -y git \
&& xargs apt-get install -y --no-install-recommends <extra_debian_requirements.txt \ && xargs apt-get install -y --no-install-recommends <extra_debian_requirements.txt \
&& xargs apt-get install -y --no-install-recommends <addons_debian_requirements.txt \
&& rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*
# <OOW> Install Python librairies # <OOW> Install Python librairies
COPY ./src/odoo/requirements.txt /odoo_python_requirements.txt COPY ./src/odoo/requirements.txt /odoo_python_requirements.txt
COPY addons_python_requirements.txt /addons_python_requirements.txt
COPY extra_python_requirements.txt /extra_python_requirements.txt COPY extra_python_requirements.txt /extra_python_requirements.txt
RUN pip3 install --upgrade pip \ RUN pip3 install --upgrade pip \
&& python3 -m pip install --no-cache-dir setuptools-scm \ && python3 -m pip install --no-cache-dir setuptools-scm \
&& python3 -m pip install --no-cache-dir -r /odoo_python_requirements.txt \ && python3 -m pip install --no-cache-dir -r /odoo_python_requirements.txt \
&& python3 -m pip install --no-cache-dir -r /extra_python_requirements.txt && python3 -m pip install --no-cache-dir -r /extra_python_requirements.txt \
&& python3 -m pip install --no-cache-dir -r /addons_python_requirements.txt
# <OOW> Get local user id and set it to the odoo user # <OOW> Get local user id and set it to the odoo user
ARG LOCAL_USER_ID ARG LOCAL_USER_ID

View File

@ -28,18 +28,22 @@ RUN apt-get update -qq && \
# <OOW> Install Debian packages # <OOW> Install Debian packages
COPY extra_debian_requirements.txt /extra_debian_requirements.txt COPY extra_debian_requirements.txt /extra_debian_requirements.txt
COPY addons_debian_requirements.txt /addons_debian_requirements.txt
RUN apt-get update -qq \ RUN apt-get update -qq \
&& apt-get install -y git \ && apt-get install -y git \
&& xargs apt-get install -y --no-install-recommends <extra_debian_requirements.txt \ && xargs apt-get install -y --no-install-recommends <extra_debian_requirements.txt \
&& xargs apt-get install -y --no-install-recommends <addons_debian_requirements.txt \
&& rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*
# <OOW> Install Python librairies # <OOW> Install Python librairies
COPY ./src/odoo/requirements.txt /odoo_python_requirements.txt COPY ./src/odoo/requirements.txt /odoo_python_requirements.txt
COPY addons_python_requirements.txt /addons_python_requirements.txt
COPY extra_python_requirements.txt /extra_python_requirements.txt COPY extra_python_requirements.txt /extra_python_requirements.txt
RUN pip3 install --upgrade pip \ RUN pip3 install --upgrade pip \
&& python3 -m pip install --no-cache-dir setuptools-scm \ && python3 -m pip install --no-cache-dir setuptools-scm \
&& python3 -m pip install --no-cache-dir -r /odoo_python_requirements.txt \ && python3 -m pip install --no-cache-dir -r /odoo_python_requirements.txt \
&& python3 -m pip install --no-cache-dir -r /extra_python_requirements.txt && python3 -m pip install --no-cache-dir -r /extra_python_requirements.txt \
&& python3 -m pip install --no-cache-dir -r /addons_python_requirements.txt
# <OOW> Get local user id and set it to the odoo user # <OOW> Get local user id and set it to the odoo user
ARG LOCAL_USER_ID ARG LOCAL_USER_ID

View File

@ -28,18 +28,22 @@ RUN apt-get update -qq && \
# <OOW> Install Debian packages # <OOW> Install Debian packages
COPY extra_debian_requirements.txt /extra_debian_requirements.txt COPY extra_debian_requirements.txt /extra_debian_requirements.txt
COPY addons_debian_requirements.txt /addons_debian_requirements.txt
RUN apt-get update -qq \ RUN apt-get update -qq \
&& apt-get install -y git \ && apt-get install -y git \
&& xargs apt-get install -y --no-install-recommends <extra_debian_requirements.txt \ && xargs apt-get install -y --no-install-recommends <extra_debian_requirements.txt \
&& xargs apt-get install -y --no-install-recommends <addons_debian_requirements.txt \
&& rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*
# <OOW> Install Python librairies # <OOW> Install Python librairies
COPY ./src/odoo/requirements.txt /odoo_python_requirements.txt COPY ./src/odoo/requirements.txt /odoo_python_requirements.txt
COPY addons_python_requirements.txt /addons_python_requirements.txt
COPY extra_python_requirements.txt /extra_python_requirements.txt COPY extra_python_requirements.txt /extra_python_requirements.txt
RUN pip3 install --upgrade pip \ RUN pip3 install --upgrade pip \
&& python3 -m pip install --no-cache-dir setuptools-scm \ && python3 -m pip install --no-cache-dir setuptools-scm \
&& python3 -m pip install --no-cache-dir -r /odoo_python_requirements.txt \ && python3 -m pip install --no-cache-dir -r /odoo_python_requirements.txt \
&& python3 -m pip install --no-cache-dir -r /extra_python_requirements.txt && python3 -m pip install --no-cache-dir -r /extra_python_requirements.txt \
&& python3 -m pip install --no-cache-dir -r /addons_python_requirements.txt
# <OOW> Get local user id and set it to the odoo user # <OOW> Get local user id and set it to the odoo user
ARG LOCAL_USER_ID ARG LOCAL_USER_ID

View File

@ -29,18 +29,22 @@ RUN apt-get update -qq && \
# <OOW> Install Debian packages # <OOW> Install Debian packages
COPY extra_debian_requirements.txt /extra_debian_requirements.txt COPY extra_debian_requirements.txt /extra_debian_requirements.txt
COPY addons_debian_requirements.txt /addons_debian_requirements.txt
RUN apt-get update -qq \ RUN apt-get update -qq \
&& apt-get install -y git \ && apt-get install -y git \
&& xargs apt-get install -y --no-install-recommends <extra_debian_requirements.txt \ && xargs apt-get install -y --no-install-recommends <extra_debian_requirements.txt \
&& xargs apt-get install -y --no-install-recommends <addons_debian_requirements.txt \
&& rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*
# <OOW> Install Python librairies # <OOW> Install Python librairies
COPY ./src/odoo/requirements.txt /odoo_python_requirements.txt COPY ./src/odoo/requirements.txt /odoo_python_requirements.txt
COPY addons_python_requirements.txt /addons_python_requirements.txt
COPY extra_python_requirements.txt /extra_python_requirements.txt COPY extra_python_requirements.txt /extra_python_requirements.txt
RUN pip3 install --upgrade pip --break-system-packages \ RUN pip3 install --upgrade pip --break-system-packages \
&& python3 -m pip install --no-cache-dir setuptools-scm --break-system-packages \ && python3 -m pip install --no-cache-dir setuptools-scm --break-system-packages \
&& python3 -m pip install --no-cache-dir -r /odoo_python_requirements.txt --break-system-packages \ && python3 -m pip install --no-cache-dir -r /odoo_python_requirements.txt --break-system-packages \
&& python3 -m pip install --no-cache-dir -r /extra_python_requirements.txt --break-system-packages && python3 -m pip install --no-cache-dir -r /extra_python_requirements.txt --break-system-packages \
&& python3 -m pip install --no-cache-dir -r /addons_python_requirements.txt --break-system-packages
# <OOW> Get local user id and set it to the odoo user # <OOW> Get local user id and set it to the odoo user
ARG LOCAL_USER_ID ARG LOCAL_USER_ID

View File

@ -29,18 +29,22 @@ RUN apt-get update -qq && \
# <OOW> Install Debian packages # <OOW> Install Debian packages
COPY extra_debian_requirements.txt /extra_debian_requirements.txt COPY extra_debian_requirements.txt /extra_debian_requirements.txt
COPY addons_debian_requirements.txt /addons_debian_requirements.txt
RUN apt-get update -qq \ RUN apt-get update -qq \
&& apt-get install -y git \ && apt-get install -y git \
&& xargs apt-get install -y --no-install-recommends <extra_debian_requirements.txt \ && xargs apt-get install -y --no-install-recommends <extra_debian_requirements.txt \
&& xargs apt-get install -y --no-install-recommends <addons_debian_requirements.txt \
&& rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*
# <OOW> Install Python librairies # <OOW> Install Python librairies
COPY ./src/odoo/requirements.txt /odoo_python_requirements.txt COPY ./src/odoo/requirements.txt /odoo_python_requirements.txt
COPY addons_python_requirements.txt /addons_python_requirements.txt
COPY extra_python_requirements.txt /extra_python_requirements.txt COPY extra_python_requirements.txt /extra_python_requirements.txt
RUN pip3 install --upgrade pip --break-system-packages \ RUN pip3 install --upgrade pip --break-system-packages \
&& python3 -m pip install --no-cache-dir setuptools-scm --break-system-packages \ && python3 -m pip install --no-cache-dir setuptools-scm --break-system-packages \
&& python3 -m pip install --no-cache-dir -r /odoo_python_requirements.txt --break-system-packages \ && python3 -m pip install --no-cache-dir -r /odoo_python_requirements.txt --break-system-packages \
&& python3 -m pip install --no-cache-dir -r /extra_python_requirements.txt --break-system-packages && python3 -m pip install --no-cache-dir -r /extra_python_requirements.txt --break-system-packages \
&& python3 -m pip install --no-cache-dir -r /addons_python_requirements.txt --break-system-packages
# <OOW> Get local user id and set it to the odoo user # <OOW> Get local user id and set it to the odoo user
ARG LOCAL_USER_ID ARG LOCAL_USER_ID

View File

@ -0,0 +1,8 @@
# Do NOT edit manually. Changes here will be overwritten by the command 'guess-requirement'
{%- for bin_lib, module_list in dependencies.items() %}
# Required by the module(s): {{ ','.join(module_list) }}
{{ bin_lib }}
{%- endfor %}

View File

@ -0,0 +1,8 @@
# Do NOT edit manually. Changes here will be overwritten by the command 'guess-requirement'
{%- for python_lib, module_list in dependencies.items() %}
# Required by the module(s): {{ ','.join(module_list) }}
{{ python_lib }}
{%- endfor %}

View File

@ -1,6 +0,0 @@
{% for bin_lib, module_list in dependencies.items() %}
# Required by the module(s): {{ ','.join(module_list) }}
{{ bin_lib }}
{% endfor %}

View File

@ -7,10 +7,3 @@ git+https://github.com/OCA/openupgradelib@master#egg=openupgradelib
# dependencies of the module OCA/server-tools 'upgrade_analysis' # dependencies of the module OCA/server-tools 'upgrade_analysis'
odoorpc odoorpc
mako mako
{%- for python_lib, module_list in dependencies.items() %}
# Required by the module(s): {{ ','.join(module_list) }}
{{ python_lib }}
{%- endfor %}

View File

@ -544,38 +544,42 @@ class OdooModuleVersion(object):
if not self.odoo_module.name or not self.addon_path: if not self.odoo_module.name or not self.addon_path:
continue continue
manifest_path = ( manifest_path = (
self.addon_path / self.odoo_module.name / "__manifest__.py" self.addon_path / self.odoo_module.name / manifest_name
) )
if manifest_path.exists(): if manifest_path.exists():
break break
if not manifest_path or not manifest_path.exists(): if not manifest_path or not manifest_path.exists():
return result return result
manifest = ast.literal_eval(open(manifest_path).read())
with manifest_path.open(mode="r", encoding="utf-8") as f_manifest:
manifest = ast.literal_eval(f_manifest.read())
python_libs = manifest.get("external_dependencies", {}).get( python_libs = manifest.get("external_dependencies", {}).get(
"python", [] "python", []
) )
bin_libs = manifest.get("external_dependencies", {}).get("bin", []) bin_libs = manifest.get("external_dependencies", {}).get("bin", [])
result["bin"] = bin_libs result["bin"] = bin_libs
# Handle specific replacement in the setup folder # Handle specific replacement in the setup folder
setup_path = ( setup_path = (
self.addon_path / "setup" / self.odoo_module.name / "setup.py" self.addon_path / "setup" / self.odoo_module.name / "setup.py"
) )
if setup_path.exists(): if setup_path.exists():
with setup_path.open(mode="r", encoding="utf-8") as f: with setup_path.open(mode="r", encoding="utf-8") as f_setup:
setup_content = f.read() tree = ast.parse(source=f_setup.read())
setup_content = (
setup_content.replace("import setuptools", "") for node in ast.walk(tree):
.replace("setuptools.setup(", "{") if (
.replace("setup_requires=", "'setup_requires':") node.__class__.__name__ == "Dict"
.replace("odoo_addon=", "'odoo_addon':") and "external_dependencies_override"
.replace(")", "}") in [k.value for k in node.keys]
) ):
setup_eval = ast.literal_eval(setup_content) python_replacements = ast.literal_eval(
odoo_addon_value = setup_eval.get("odoo_addon", False) ast.unparse(node)
if type(odoo_addon_value) is dict: )["external_dependencies_override"]
python_replacements = odoo_addon_value.get( break
"external_dependencies_override", {} else:
).get("python", {}) python_replacements = {}
for k, v in python_replacements.items(): for k, v in python_replacements.items():
if k in python_libs: if k in python_libs:
python_libs.remove(k) python_libs.remove(k)

View File

@ -15,7 +15,7 @@ class TestCliGuessRequirement(unittest.TestCase):
["guess-requirement", "--extra-modules=sentry"], ["guess-requirement", "--extra-modules=sentry"],
) )
relative_path = Path("src/env_14.0/extra_python_requirements.txt") relative_path = Path("src/env_14.0/addons_python_requirements.txt")
assert filecmp.cmp( assert filecmp.cmp(
relative_path, relative_path,

View File

@ -0,0 +1,4 @@
# Do NOT edit manually. Changes here will be overwritten by the command 'guess-requirement'
# Required by the module(s): sentry
sentry_sdk<=1.9.0

View File

@ -1,12 +0,0 @@
# Mandatory library used in all odoo-openupgrade-wizard
# Note: As the openupgradelib is not allways up to date in pypi,
# we use the github master url.
git+https://github.com/OCA/openupgradelib@master#egg=openupgradelib
# Library used to run generate-module-analysis command
# dependencies of the module OCA/server-tools 'upgrade_analysis'
odoorpc
mako
# Required by the module(s): sentry
sentry_sdk<=1.9.0