Marcel Telka
2022-11-05 c6fba2ed41bcf7e748d6f8708dd642099fae481e
Move Python bootstrap rules to pyproject.mk

1 files added
3 files modified
147 ■■■■■ changed files
components/python/build/python-integrate-project.conf 39 ●●●●● patch | view | raw | blame | history
components/python/pyproject_installer/python-integrate-project.conf 26 ●●●● patch | view | raw | blame | history
make-rules/pyproject.mk 63 ●●●●● patch | view | raw | blame | history
transforms/python-bootstrap 19 ●●●●● patch | view | raw | blame | history
components/python/build/python-integrate-project.conf
@@ -15,49 +15,10 @@
%include-2%
# Since we cannot use the 'build' package to build itself we need to bootstrap.
# To do so we will use pyproject_installer to get PEP 376 compliant
# installation.  The other possible way to bootstrap the 'build' package is
# setup.py, but its results are not PEP 376 compliant.
PYTHON_BOOTSTRAP = yes
# Disable tests because required packages are not available during bootstrap
TEST_STYLE = none
%include-3%
# Use pyproject_installer to build this project
#
# Since pyproject_installer requires Python >= 3.8 we need to defer to default
# setup.py build style for Python 3.7, so we will use pyproject_installer for
# Python 3.9 only.  Once we obsolete Python 3.7 we should set
# COMPONENT_BUILD_CMD and COMPONENT_BUILD_ARGS unconditionally below.
$(BUILD_DIR)/%-3.9/.built:    COMPONENT_BUILD_CMD =        $(PYTHON.3.9) -m pyproject_installer build
$(BUILD_DIR)/%-3.9/.built:    COMPONENT_BUILD_ARGS =
# Use pyproject_installer to install this project
#
# Since pyproject_installer requires Python >= 3.8 we need to defer to default
# setup.py build style for Python 3.7, so we will use pyproject_installer for
# Python 3.9 only.  Once we obsolete Python 3.7 we should set
# COMPONENT_INSTALL_CMD and COMPONENT_INSTALL_ARGS unconditionally below.
$(BUILD_DIR)/%-3.9/.installed:    COMPONENT_INSTALL_CMD =        $(PYTHON.3.9) -m pyproject_installer install
$(BUILD_DIR)/%-3.9/.installed:    COMPONENT_INSTALL_ARGS =
$(BUILD_DIR)/%-3.9/.installed:    COMPONENT_INSTALL_ARGS +=    --destdir $(PROTO_DIR)
# pyproject_installer does not bytecompile after the install.  Since we need
# pyc files we need to force that.
#
# Since pyproject_installer requires Python >= 3.8 we need to defer to default
# setup.py build style for Python 3.7, and so we do not need to compile for
# Python 3.7.  Once we obsolete Python 3.7 we should set
# COMPONENT_POST_INSTALL_ACTION unconditionally below.
$(BUILD_DIR)/%-3.9/.installed:    COMPONENT_POST_INSTALL_ACTION +=    $(PYTHON) -m compileall $(PROTO_DIR)/$(PYTHON_LIB) ;
# We need 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
%hook-manifest%
# drop dist-info for Python 3.7 and egg-info for Python 3.9
printf '<transform file path=usr/lib/python3\\.7/vendor-packages/build-.*\\.dist-info -> drop >\n' >> "$DISTRIBUTION-PYVER.p5m"
printf '<transform file path=usr/lib/python3\\.9/vendor-packages/build-.*-py3\\.9\\.egg-info -> drop >\n' >> "$DISTRIBUTION-PYVER.p5m"
# usr/bin/pyproject-build-3.7 does not use importlib.metadata.  It uses importlib_metadata instead.
printf '<transform file path=usr/bin/pyproject-build-3\\.7$ -> add pkg.depend.bypass-generate .*/importlib/(64/)?metadata.* >\n' >> "$DISTRIBUTION-PYVER.p5m"
components/python/pyproject_installer/python-integrate-project.conf
@@ -14,33 +14,17 @@
#
%include-2%
# The pyproject_installer is small, PEP 517 compliant, self contained Python
# project capable to build and install itself and other projects without
# dependency on non-core Python modules.  It will be used to package full
# featured 'build' and 'installer' projects.
# The pyproject_installer is the bootstrapper so it cannot use any non-core
# Python modules and it needs to be bootstrapped.
PYTHON_BOOTSTRAP = yes
# https://github.com/stanislavlevin/pyproject_installer/issues/13
TEST_STYLE = none
# This project requires Python >= 3.8
# This project requires Python >= 3.8.  Once we add support for new Python
# version (>= 3.8), such version needs to be added to PYTHON_VERSIONS below.
# Once we obsolete Python 3.7 the PYTHON_VERSIONS line should be removed.
PYTHON_VERSIONS = 3.9
%include-3%
# Allow the bootstrapping pyproject_installer to find its own modules
PYTHON_ENV += PYTHONPATH=$(@D)/src
# Special self contained build command for bootstrap
COMPONENT_BUILD_CMD =        $(PYTHON) -m pyproject_installer build
COMPONENT_BUILD_ARGS =
# Special self contained install command for bootstrap
COMPONENT_INSTALL_CMD =        $(PYTHON) -m pyproject_installer install
COMPONENT_INSTALL_ARGS =
COMPONENT_INSTALL_ARGS +=    --destdir $(PROTO_DIR)
# pyproject_installer does not bytecompile after the install.  Since we need
# pyc files we need to force that.
COMPONENT_POST_INSTALL_ACTION +=    $(PYTHON) -m compileall $(PROTO_DIR)/$(PYTHON_LIB) ;
%hook-no-license%
# https://github.com/stanislavlevin/pyproject_installer/issues/13
curl -s "https://raw.githubusercontent.com/stanislavlevin/pyproject_installer/main/LICENSE" > "$DISTRIBUTION.license"
make-rules/pyproject.mk
@@ -17,10 +17,65 @@
PYTHON_BOOTSTRAP ?= no
# Both build and installer Python modules together with versioned
# library/python/build and library/python/installer packages are not available
# during bootstrap.
ifeq ($(strip $(PYTHON_BOOTSTRAP)),no)
ifeq ($(strip $(PYTHON_BOOTSTRAP)),yes)
#
# Both 'build' and 'installer' Python modules used for packaging regular Python
# projects (see below) are not part of core Python, so we need to bootstrap
# them together with their non-core dependencies.
#
# There are basically two ways how to bootstrap such projects:
#
# 1) defer to default 'setup.py' build style for projects that still supports
# it.  The 'setup.py' build style usually does not require anything outside
# core Python modules.  Also, it is likely that the set of projects that needs
# to be bootstrapped (like setuptools) will support the 'setup.py' build style
# for very long time (maybe forever).  Anyway, the main problem with the
# 'setup.py' build style is that its results are not PEP 376 compliant.
#
# 2) use something else, preferably as simple as possible, to do the build.
# Such tool needs to be PEP 376 and PEP 517 compliant and it also must be able
# to build itself without requiring any other non-core Python modules.  We use
# pyproject_installer to do the job.
#
ifeq ($(strip $(COMPONENT_NAME)),pyproject_installer)
# To bootstrap the bootstrapper we need to make sure it finds its own modules
PYTHON_ENV += PYTHONPATH=$(@D)/src
endif
# Since pyproject_installer requires Python >= 3.8 we need to defer to default
# setup.py build style for Python 3.7, so we will use pyproject_installer for
# Python 3.9 only.  Once we obsolete Python 3.7 we should set
# COMPONENT_BUILD_CMD, COMPONENT_BUILD_ARGS, COMPONENT_INSTALL_CMD, and
# COMPONENT_INSTALL_ARGS unconditionally below and replace $(PYTHON.3.9) by
# $(PYTHON).
$(BUILD_DIR)/%-3.9/.built:    COMPONENT_BUILD_CMD =        $(PYTHON.3.9) -m pyproject_installer build
$(BUILD_DIR)/%-3.9/.built:    COMPONENT_BUILD_ARGS =
$(BUILD_DIR)/%-3.9/.installed:    COMPONENT_INSTALL_CMD =        $(PYTHON.3.9) -m pyproject_installer install
$(BUILD_DIR)/%-3.9/.installed:    COMPONENT_INSTALL_ARGS =
$(BUILD_DIR)/%-3.9/.installed:    COMPONENT_INSTALL_ARGS +=    --destdir $(PROTO_DIR)
# pyproject_installer does not bytecompile after the install.  Since we need
# pyc files we need to force that.
#
# Since pyproject_installer requires Python >= 3.8 we need to defer to default
# setup.py build style for Python 3.7, and so we do not need to compile for
# Python 3.7.  Once we obsolete Python 3.7 we should set
# COMPONENT_POST_INSTALL_ACTION unconditionally below.
$(BUILD_DIR)/%-3.9/.installed:    COMPONENT_POST_INSTALL_ACTION +=    $(PYTHON) -m compileall $(PROTO_DIR)/$(PYTHON_LIB) ;
# 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 =
COMPONENT_BUILD_ARGS +=        --wheel
transforms/python-bootstrap
New file
@@ -0,0 +1,19 @@
#
# This file and its contents are supplied under the terms of the
# Common Development and Distribution License ("CDDL"), version 1.0.
# You may only use this file in accordance with the terms of version
# 1.0 of the CDDL.
#
# A full copy of the text of the CDDL should have accompanied this
# source.  A copy of the CDDL is also available via the Internet at
# http://www.illumos.org/license/CDDL.
#
#
# Copyright 2022 Marcel Telka
#
# Drop dist-info for Python 3.7 and egg-info for Python 3.9
# This is used during bootstrap only until we drop support for Python 3.7.
<transform file path=usr/lib/python3\.7/vendor-packages/[^/]*\.dist-info -> drop >
<transform file path=usr/lib/python3\.9/vendor-packages/[^/]*-py3\.9\.egg-info -> drop >