Skip to content
Snippets Groups Projects
Commit 5b25b6ab authored by Vincent Hatakeyama's avatar Vincent Hatakeyama
Browse files

:sparkles: On docker_build_copy, when not run localy, do not build.

parent 95175b1d
No related branches found
Tags TAG_7.0.2.0a1
1 merge request!186✨ On docker_build_copy, when not run localy, do not build.
......@@ -53,7 +53,7 @@
image: $TEMP_IMAGE
script:
- python3 -m pip install mypy types-PyYAML types-psycopg2 types-python-dateutil
types-requests
types-requests build twine
- mypy odoo_scripts tests
rules:
- if: $CI_COMMIT_TAG == null
......
......@@ -2,6 +2,11 @@
History
=======
20.2.0
------
docker_build_copy: when not in CI, default to copying packages and let the package be build in the image.
20.1.0
------
......
......@@ -13,5 +13,5 @@
_logger = logging.getLogger(__name__)
__version__ = "2.1.0"
__version__ = "2.2.0"
__date__ = "2020-06-30"
......@@ -17,5 +17,5 @@
__date__ = "2020-06-30"
__updated__ = "2023-02-28"
__updated__ = "2023-03-31"
PYTHON_PACKAGES_DIR = "python_packages"
......@@ -52,8 +52,13 @@
return path.replace(os.path.sep, "-")
def copy():
"""Copy modules for a build"""
def copy(build_package_locally: Optional[bool] = None):
"""Copy modules for a build
:param build_package_locally: build package that have package compile set to True
rather than just copy them. (in CI, build package to reduce artifact size, locally
default to copying them)
"""
c = Config()
modules = [os.path.realpath(module) for module in c.modules]
target = "odoo_modules"
......@@ -84,6 +89,7 @@
copy_paths = set()
packages_to_compile = []
requirements = []
ci_mode = "CI" in os.environ and os.environ["CI"].lower() == "true"
# Try to include the CVS information in target so that setuptools-scm and
# setuptools-odoo work as expected
for package, options in c.python_packages.items():
......@@ -87,7 +93,9 @@
# Try to include the CVS information in target so that setuptools-scm and
# setuptools-odoo work as expected
for package, options in c.python_packages.items():
if options["compile"] in ("True", "true"):
if options["compile"] in ("True", "true") and (
ci_mode or build_package_locally
):
packages_to_compile.append(package)
else:
cvs_parent = package
......@@ -129,6 +137,5 @@
]
_logger.debug(" ".join(cmd))
check_call(cmd)
# The option to ignore the python verion can be an issue with newer syntax.
# In the CI it will work fine, locally, maybe add an option to avoid compiling?
# The option to ignore the python version can be an issue with newer syntax.
if packages_to_compile:
......@@ -134,13 +141,31 @@
if packages_to_compile:
cmd = [
sys.executable,
"-m",
"pip",
"wheel",
"--no-deps",
"-w",
target,
"--ignore-requires-python",
] + packages_to_compile
# try with build if present, fallback to pip wheel otherwise
try:
# build is not usable directly so use a subprocess.
# Disable flake8, this is just to test that the package is installed.
import build # type: ignore[import] # noqa: F401
cmd = [
sys.executable,
"-m",
"build",
"--outdir",
target,
] + packages_to_compile
_logger.debug(" ".join(cmd))
check_call(cmd)
except ImportError:
# pip is not usable directly, it is indicated in its doc to use subprocess
# instead.
cmd = [
sys.executable,
"-m",
"pip",
"wheel",
"--no-deps",
"-w",
target,
"--ignore-requires-python",
] + packages_to_compile
_logger.debug(" ".join(cmd))
check_call(cmd)
......@@ -145,5 +170,15 @@
_logger.debug(" ".join(cmd))
check_call(cmd)
try:
# Disable flake8, this is just to test that the package is installed
import twine # type: ignore[import] # noqa: F401
cmd = [sys.executable, "-m", "twine", "check", f"{target}/*"]
check_call(cmd)
except ImportError:
_logger.warn("No twine, no check done")
for entry in os.listdir(target):
if entry.endswith(".whl"):
requirements.append(os.path.join(".", target, entry))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment