Marcel Telka
2022-11-05 27f6d6d1fa9d5d945af9630fddf5100ee585376e
pyproject.mk: add build dependencies from project metadata to REQUIRED_PACKAGES

1 files modified
39 ■■■■ changed files
make-rules/pyproject.mk 39 ●●●● patch | view | raw | blame | history
make-rules/pyproject.mk
@@ -67,14 +67,6 @@
# Special transforms needed only until we drop support for Python 3.7
PUBLISH_TRANSFORMS +=    $(WS_TOP)/transforms/python-bootstrap
# We need pyproject_installer to bootstrap other projects, but it is not needed
# (and cannot be needed) for its own bootstrap.
ifneq ($(strip $(COMPONENT_NAME)),pyproject_installer)
# Once we obsolete Python 3.7 this should be changed to
# PYTHON_USERLAND_REQUIRED_PACKAGES and '-39' suffix should be removed
USERLAND_REQUIRED_PACKAGES += library/python/pyproject_installer-39
endif
else
COMPONENT_BUILD_CMD =        $(PYTHON) -m build
COMPONENT_BUILD_ARGS =
@@ -98,3 +90,34 @@
        $(RM) -r $(PROTO_DIR)/$(PYTHON_LIB) ; \
        $(MV) $(PROTO_DIR)/$(PYTHON_DIR)/site-packages $(PROTO_DIR)/$(PYTHON_LIB) ; \
    fi ;
# Add build dependencies from project metadata to REQUIRED_PACKAGES
REQUIRED_PACKAGES_RESOLVED += $(BUILD_DIR)/META.depend.res
$(BUILD_DIR)/META.depend.res: $(SOURCE_DIR)/.prep
    $(MKDIR) $(BUILD_DIR)
    # PYTHON_ENV is needed here to have the PYTHONPATH set properly when we
    # bootstrap the pyproject_installer bootstrapper.
    #
    # To make the package names comparable we normalize them here by
    # following the PyPA Core metadata specifications and PEP 503.
    #
    # Once we obsolete Python 3.7 we should change $(PYTHON.3.9) to $(PYTHON) here
    $(PYTHON_ENV) $(PYTHON.3.9) -c ' \
            from pathlib import Path; \
            from pyproject_installer.build_cmd._build import parse_build_system_spec; \
            [print(x) for x in parse_build_system_spec(Path("'$(SOURCE_DIR)'"))["requires"]]' \
        | $(GSED) -e $$'s/^[ \t]*''\([a-zA-Z0-9]\([a-zA-Z0-9._-]*[a-zA-Z0-9]\)\{0,1\}\).*/\1/' \
        | tr [A-Z] [a-z] | $(GSED) -e 's/[.-_]\{1,\}/-/g' \
        | $(GSED) -e 's/.*/depend type=require fmri=pkg:\/library\/python\/&-$$(PYV)/' \
        > $@
# We need pyproject_installer for two purposes:
# - to detect build dependencies for all Python projects, and
# - to bootstrap some other Python projects.
# The pyproject_installer is not needed (and cannot be needed) for its own
# build.
ifneq ($(strip $(COMPONENT_NAME)),pyproject_installer)
# Once we obsolete Python 3.7 this should be changed to
# PYTHON_USERLAND_REQUIRED_PACKAGES and '-39' suffix should be removed
USERLAND_REQUIRED_PACKAGES += library/python/pyproject_installer-39
endif