From ee3b59a068a178783e370536142644c57ee54f8d Mon Sep 17 00:00:00 2001 From: Artyom Semidolin <43622365+Artanias@users.noreply.github.com> Date: Sun, 25 Feb 2024 12:25:03 +0300 Subject: [PATCH] build: move build requirements to setup.py --- .github/workflows/check_n_push_image.yml | 3 ++- Makefile | 2 ++ docker/test_ubuntu2004.dockerfile.in | 2 +- setup.py | 23 +++++++++++++++++++---- 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/.github/workflows/check_n_push_image.yml b/.github/workflows/check_n_push_image.yml index 4d36818..e73745e 100644 --- a/.github/workflows/check_n_push_image.yml +++ b/.github/workflows/check_n_push_image.yml @@ -32,8 +32,9 @@ jobs: run: | make substitute-sources pip install $(python3 setup.py --install-requirements) + pip install $(python3 setup.py --build-requirements) pip install --requirement docs/notebooks/requirements.txt - pip install pre-commit==3.4.0 Cython==3.0.8 + pip install pre-commit==3.4.0 make pre-commit docker-build-test-autotest: diff --git a/Makefile b/Makefile index 80fe1de..65bc3e3 100644 --- a/Makefile +++ b/Makefile @@ -32,6 +32,7 @@ DOCKER_SUB_FILES := docker/base_ubuntu2004.dockerfile \ docker/ubuntu2004.dockerfile PYTHON_REQUIRED_LIBS := $(shell python3 setup.py --install-requirements) +PYTHON_BUILD_LIBS := $(shell python3 setup.py --build-requirements) ifeq ($(IS_DEVELOPED), 1) @@ -45,6 +46,7 @@ substitute = @sed \ -e "s|@CODEPLAG_LOG_PATH@|${CODEPLAG_LOG_PATH}|g" \ -e "s|@DEVEL_SUFFIX@|${DEVEL_SUFFIX}|g" \ -e "s|@PYTHON_REQUIRED_LIBS@|${PYTHON_REQUIRED_LIBS}|g" \ + -e "s|@PYTHON_BUILD_LIBS@|${PYTHON_BUILD_LIBS}|g" \ -e "s|@LOGS_PATH@|${LOGS_PATH}|g" \ -e "s|@LIB_PATH@|${LIB_PATH}|g" \ -e "s|@CONFIG_PATH@|${CONFIG_PATH}|g" \ diff --git a/docker/test_ubuntu2004.dockerfile.in b/docker/test_ubuntu2004.dockerfile.in index 2e78319..acaf462 100644 --- a/docker/test_ubuntu2004.dockerfile.in +++ b/docker/test_ubuntu2004.dockerfile.in @@ -3,7 +3,7 @@ FROM @BASE_DOCKER_TAG@ ENV DEBIAN_FRONTEND=noninteractive RUN apt-get install -y debhelper -RUN pip3 install argparse-manpage==3 pytest==7.4.0 pytest-mock==3.11.1 Cython==3.0.8 +RUN pip3 install pytest==7.4.0 pytest-mock==3.11.1 @PYTHON_BUILD_LIBS@ RUN mkdir -p @LOGS_PATH@ # TODO: Move to middle docker file or make another solution diff --git a/setup.py b/setup.py index b44fd43..c54c27b 100644 --- a/setup.py +++ b/setup.py @@ -1,11 +1,15 @@ import os import sys from pathlib import Path +from typing import Tuple -from Cython.Build import cythonize from setuptools import Extension, find_packages, setup -INSTALL_REQUIREMENTS = [ +BUILD_REQUIREMENTS: Tuple[str, ...] = ( + "argparse-manpage==3", + "Cython~=3.0.8", +) +INSTALL_REQUIREMENTS: Tuple[str, ...] = ( "argcomplete~=2.0.0", "numpy~=1.23.5", "pandas~=1.4.3", @@ -20,17 +24,28 @@ "Jinja2~=3.1.2", "cachetools==5.3.1", "gidgethub~=5.3.0", -] +) UTIL_NAME = os.getenv("UTIL_NAME") UTIL_VERSION = os.getenv("UTIL_VERSION") -if "--install-requirements" in sys.argv: +if "--build-requirements" in sys.argv: + print(" ".join(BUILD_REQUIREMENTS)) + sys.exit(0) +elif "--install-requirements" in sys.argv: print(" ".join(INSTALL_REQUIREMENTS)) sys.exit(0) elif UTIL_NAME is None or UTIL_VERSION is None: print("Please provide UTIL_NAME and UTIL_VERSION environment variables.") sys.exit(1) +try: + from Cython.Build import cythonize +except ModuleNotFoundError: + print( + "For the correct build install required build dependencies: " + f"'{' '.join(BUILD_REQUIREMENTS)}'." + ) + sys.exit(1) setup(