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).
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,
when ``barcodes_generator_abstract`` and ``l10n_fr_siret`` are installed.
For exemple, here is the content of the ``addons_python_requirements.txt`` file,
when ``barcodes_generator_abstract`` and ``l10n_fr_siret`` are installed (for V16).
```
# 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"]]:
path_version = get_odoo_env_path(ctx, odoo_version)
ensure_file_exists_from_template(
path_version / Path("extra_python_requirements.txt"),
"odoo/extra_python_requirements.txt.j2",
path_version / Path("addons_python_requirements.txt"),
"odoo/addons_python_requirements.txt.j2",
dependencies=result[odoo_version]["python"],
)
ensure_file_exists_from_template(
path_version / Path("extra_debian_requirements.txt"),
"odoo/extra_debian_requirements.txt.j2",
path_version / Path("addons_debian_requirements.txt"),
"odoo/addons_debian_requirements.txt.j2",
dependencies=result[odoo_version]["bin"],
)

View File

@ -152,17 +152,27 @@ def init(
path_version = get_odoo_env_path(ctx, odoo_version)
ensure_folder_exists(path_version)
# Create python requirements file
# Create python requirements files
ensure_file_exists_from_template(
path_version / Path("extra_python_requirements.txt"),
"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={},
)
# Create debian requirements file
# Create debian requirements files
ensure_file_exists_from_template(
path_version / Path("extra_debian_requirements.txt"),
"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={},
)

View File

@ -39,18 +39,22 @@ RUN apt-get update -qq && \
# <OOW> Install Debian packages
COPY extra_debian_requirements.txt /extra_debian_requirements.txt
COPY addons_debian_requirements.txt /addons_debian_requirements.txt
RUN apt-get update -qq \
&& 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 <addons_debian_requirements.txt \
&& rm -rf /var/lib/apt/lists/*
# <OOW> Install Python librairies
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
RUN pip3 install --upgrade pip \
&& 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 /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
ARG LOCAL_USER_ID

View File

@ -39,18 +39,22 @@ RUN apt-get update -qq && \
# <OOW> Install Debian packages
COPY extra_debian_requirements.txt /extra_debian_requirements.txt
COPY addons_debian_requirements.txt /addons_debian_requirements.txt
RUN apt-get update -qq \
&& 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 <addons_debian_requirements.txt \
&& rm -rf /var/lib/apt/lists/*
# <OOW> Install Python librairies
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
RUN pip3 install --upgrade pip \
&& 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 /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
ARG LOCAL_USER_ID

View File

@ -35,18 +35,22 @@ RUN apt-get update -qq && \
# <OOW> Install Debian packages
COPY extra_debian_requirements.txt /extra_debian_requirements.txt
COPY addons_debian_requirements.txt /addons_debian_requirements.txt
RUN apt-get update -qq \
&& 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 <addons_debian_requirements.txt \
&& rm -rf /var/lib/apt/lists/*
# <OOW> Install Python librairies
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
RUN pip3 install --upgrade pip \
&& 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 /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
ARG LOCAL_USER_ID

View File

@ -28,18 +28,22 @@ RUN apt-get update -qq && \
# <OOW> Install Debian packages
COPY extra_debian_requirements.txt /extra_debian_requirements.txt
COPY addons_debian_requirements.txt /addons_debian_requirements.txt
RUN apt-get update -qq \
&& 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 <addons_debian_requirements.txt \
&& rm -rf /var/lib/apt/lists/*
# <OOW> Install Python librairies
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
RUN pip3 install --upgrade pip \
&& 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 /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
ARG LOCAL_USER_ID

View File

@ -28,18 +28,22 @@ RUN apt-get update -qq && \
# <OOW> Install Debian packages
COPY extra_debian_requirements.txt /extra_debian_requirements.txt
COPY addons_debian_requirements.txt /addons_debian_requirements.txt
RUN apt-get update -qq \
&& 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 <addons_debian_requirements.txt \
&& rm -rf /var/lib/apt/lists/*
# <OOW> Install Python librairies
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
RUN pip3 install --upgrade pip \
&& 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 /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
ARG LOCAL_USER_ID

View File

@ -28,18 +28,22 @@ RUN apt-get update -qq && \
# <OOW> Install Debian packages
COPY extra_debian_requirements.txt /extra_debian_requirements.txt
COPY addons_debian_requirements.txt /addons_debian_requirements.txt
RUN apt-get update -qq \
&& 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 <addons_debian_requirements.txt \
&& rm -rf /var/lib/apt/lists/*
# <OOW> Install Python librairies
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
RUN pip3 install --upgrade pip \
&& 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 /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
ARG LOCAL_USER_ID

View File

@ -29,18 +29,22 @@ RUN apt-get update -qq && \
# <OOW> Install Debian packages
COPY extra_debian_requirements.txt /extra_debian_requirements.txt
COPY addons_debian_requirements.txt /addons_debian_requirements.txt
RUN apt-get update -qq \
&& 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 <addons_debian_requirements.txt \
&& rm -rf /var/lib/apt/lists/*
# <OOW> Install Python librairies
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
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 -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
ARG LOCAL_USER_ID

View File

@ -29,18 +29,22 @@ RUN apt-get update -qq && \
# <OOW> Install Debian packages
COPY extra_debian_requirements.txt /extra_debian_requirements.txt
COPY addons_debian_requirements.txt /addons_debian_requirements.txt
RUN apt-get update -qq \
&& 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 <addons_debian_requirements.txt \
&& rm -rf /var/lib/apt/lists/*
# <OOW> Install Python librairies
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
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 -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
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'
odoorpc
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:
continue
manifest_path = (
self.addon_path / self.odoo_module.name / "__manifest__.py"
self.addon_path / self.odoo_module.name / manifest_name
)
if manifest_path.exists():
break
if not manifest_path or not manifest_path.exists():
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", []
)
bin_libs = manifest.get("external_dependencies", {}).get("bin", [])
result["bin"] = bin_libs
# Handle specific replacement in the setup folder
setup_path = (
self.addon_path / "setup" / self.odoo_module.name / "setup.py"
)
if setup_path.exists():
with setup_path.open(mode="r", encoding="utf-8") as f:
setup_content = f.read()
setup_content = (
setup_content.replace("import setuptools", "")
.replace("setuptools.setup(", "{")
.replace("setup_requires=", "'setup_requires':")
.replace("odoo_addon=", "'odoo_addon':")
.replace(")", "}")
)
setup_eval = ast.literal_eval(setup_content)
odoo_addon_value = setup_eval.get("odoo_addon", False)
if type(odoo_addon_value) is dict:
python_replacements = odoo_addon_value.get(
"external_dependencies_override", {}
).get("python", {})
with setup_path.open(mode="r", encoding="utf-8") as f_setup:
tree = ast.parse(source=f_setup.read())
for node in ast.walk(tree):
if (
node.__class__.__name__ == "Dict"
and "external_dependencies_override"
in [k.value for k in node.keys]
):
python_replacements = ast.literal_eval(
ast.unparse(node)
)["external_dependencies_override"]
break
else:
python_replacements = {}
for k, v in python_replacements.items():
if k in python_libs:
python_libs.remove(k)

View File

@ -15,7 +15,7 @@ class TestCliGuessRequirement(unittest.TestCase):
["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(
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