ghex: update to 46.1
[oi-userland.git] / make-rules / pyproject.mk
blob50ade2a20767a56a7820b6824f1d2b6ac7c9f409
2 # This file and its contents are supplied under the terms of the
3 # Common Development and Distribution License ("CDDL"), version 1.0.
4 # You may only use this file in accordance with the terms of version
5 # 1.0 of the CDDL.
7 # A full copy of the text of the CDDL should have accompanied this
8 # source. A copy of the CDDL is also available via the Internet at
9 # http://www.illumos.org/license/CDDL.
13 # Copyright 2022 Marcel Telka
16 include $(WS_MAKE_RULES)/setup.py.mk
18 ifeq ($(strip $(PYTHON_BOOTSTRAP)),yes)
19 # To bootstrap the bootstrapper we need to make sure it finds its own modules
20 ifeq ($(strip $(COMPONENT_NAME)),pyproject_installer)
21 PYTHON_ENV += PYTHONPATH=$(@D)/src
22 endif
24 COMPONENT_BUILD_CMD = $(PYTHON) -m pyproject_installer build
25 COMPONENT_BUILD_ARGS =
27 COMPONENT_INSTALL_CMD = $(PYTHON) -m pyproject_installer install
28 COMPONENT_INSTALL_ARGS =
29 COMPONENT_INSTALL_ARGS += --destdir $(PROTO_DIR)
31 # pyproject_installer does not bytecompile after the install. Since we need
32 # pyc files we need to force that.
33 COMPONENT_POST_INSTALL_ACTION += \
34 $(PYTHON) -m compileall $(PROTO_DIR)/$(PYTHON_DIR)/site-packages $(PROTO_DIR)/$(PYTHON_LIB) ;
35 else
36 COMPONENT_BUILD_CMD = $(PYTHON) -m build
37 COMPONENT_BUILD_ARGS =
38 COMPONENT_BUILD_ARGS += --wheel
39 COMPONENT_BUILD_ARGS += --no-isolation
41 COMPONENT_INSTALL_CMD = $(PYTHON) -m installer
42 COMPONENT_INSTALL_ARGS =
43 COMPONENT_INSTALL_ARGS += --destdir $(PROTO_DIR)
44 COMPONENT_INSTALL_ARGS += $(@D)/dist/*.whl
46 USERLAND_REQUIRED_PACKAGES.python += library/python/build
47 USERLAND_REQUIRED_PACKAGES.python += library/python/installer
48 endif
50 # Move all modules from default site-packages directory to vendor-packages
51 # directory where we place modules shipped by the OS but not included in the
52 # core Python distribution.
53 COMPONENT_POST_INSTALL_ACTION += \
54 if [ -d $(PROTO_DIR)/$(PYTHON_DIR)/site-packages ] ; then \
55 $(RM) -r $(PROTO_DIR)/$(PYTHON_LIB) ; \
56 $(MV) $(PROTO_DIR)/$(PYTHON_DIR)/site-packages $(PROTO_DIR)/$(PYTHON_LIB) ; \
57 fi ;
59 # Generate raw lists of hatch, pdm, pipenv, and poetry test dependencies per Python version
60 COMPONENT_POST_INSTALL_ACTION += \
61 cd $(@D)$(COMPONENT_SUBDIR:%=/%) ; \
62 cfg=$(BUILD_DIR)/pyproject_deps-$(PYTHON_VERSION).json ; \
63 $(RM) $$cfg ; \
64 for p in $(TEST_REQUIREMENTS_HATCH) ; do \
65 $(PYTHON) -m pyproject_installer deps --depsconfig $$cfg add hatch_$$p hatch pyproject.toml $$p ; \
66 done ; \
67 for p in $(TEST_REQUIREMENTS_PDM) ; do \
68 $(PYTHON) -m pyproject_installer deps --depsconfig $$cfg add pdm_$$p pdm $$p ; \
69 done ; \
70 for p in $(TEST_REQUIREMENTS_PIPENV) ; do \
71 $(PYTHON) -m pyproject_installer deps --depsconfig $$cfg add pipenv_$$p pipenv Pipfile $$p ; \
72 done ; \
73 for p in $(TEST_REQUIREMENTS_POETRY) ; do \
74 $(PYTHON) -m pyproject_installer deps --depsconfig $$cfg add poetry_$$p poetry $$p ; \
75 done ; \
76 if [ -f $$cfg ] ; then \
77 $(PYTHON) -m pyproject_installer deps --depsconfig $$cfg sync ; \
78 $(PYTHON) -m pyproject_installer deps --depsconfig $$cfg eval --depformat '$$nname' \
79 >> $(@D)/.depend-test ; \
80 fi ;
82 # Add build dependencies from project metadata to REQUIRED_PACKAGES
83 REQUIRED_PACKAGES_RESOLVED += $(BUILD_DIR)/META.depend.res
84 $(BUILD_DIR)/META.depend.res: $(SOURCE_DIR)/.prep
85 $(MKDIR) $(BUILD_DIR)
86 # PYTHON_ENV is needed four times here to have the PYTHONPATH set
87 # properly when we bootstrap the pyproject_installer bootstrapper.
88 $(PYTHON_ENV) $(PYTHON) -m pyproject_installer deps --depsconfig $(BUILD_DIR)/pyproject_deps.json add build_pep517 pep517
89 $(PYTHON_ENV) $(PYTHON) -m pyproject_installer deps --depsconfig $(BUILD_DIR)/pyproject_deps.json add build_pep518 pep518
90 cd $(SOURCE_DIR) ; $(PYTHON_ENV) $(PYTHON) -m pyproject_installer deps --depsconfig $(BUILD_DIR)/pyproject_deps.json sync
91 $(PYTHON_ENV) $(PYTHON) -m pyproject_installer deps --depsconfig $(BUILD_DIR)/pyproject_deps.json eval --depformat '$$nname' \
92 | $(GSED) -e 's/.*/depend type=require fmri=pkg:\/library\/python\/&-$$(PYV)/' \
93 > $@
94 # PYTHON_ENV (see above) needs BITS
95 $(BUILD_DIR)/META.depend.res: BITS = $(PREFERRED_BITS)
97 # We need pyproject_installer for two purposes:
98 # - to detect build dependencies for all Python projects, and
99 # - to bootstrap some other Python projects.
100 # The pyproject_installer is not needed (and cannot be needed) for its own
101 # build.
102 ifneq ($(strip $(COMPONENT_NAME)),pyproject_installer)
103 USERLAND_REQUIRED_PACKAGES.python += library/python/pyproject-installer
104 endif