Skip to contentSkip to conversation

package/pkg-python.mk: refactor setup-type variables

Buildroot Applied Arnout Vandecappelle via buildroot 3 participants 22 messages Sep 30, 2023 – Nov 26, 2023

lore
Share & tools
lore
#0 lore raw

Most of the python-package infrastructure consists of a big conditional tree that sets various variables based on the package's setup type. Initially, this was quite OK, but since we have 7 different setup types now, some of which share some variables with others, it's becoming quite complicated and hard to read.

This patch series refactors it so that the inner-python-package doesn't dispatch the setup type through a conditional tree, but instead does it with variable indirection, i.e. by using variables like
$(PKG_PYTHON_$($(PKG)_SETUP_TYPE_UPPER)_ENV)

The rist two patches are simple cleanups, removing variables that are not really needed.

The third patch is a preparatory one that splits the build commands for target and host builds. This is necessary because we need to use different variables for the two, i.e. HOST_PKG_PYTHON_* for host build.

The fourth and fifth patch each replace one variable from the conditional tree with an indirectly addressed one.

The following three patches are needed because the ninth patch removes the PKG_PYTHON_*_OPTS variables, which were used in 3 packages. It is in fact not strictly needed to remove those variables, but IMHO they don't add sufficient value to keep them. I think it's better to handle the few special cases explicitly.

The ninth patch replaces the remaining variables from the conditional tree with indirectly addressed ones. The conditional tree is now empty, and the error handling that was in there is made more explicit.

The tenth patch edits the documentation to remove the references to the PKG_PYTHON_*_OPTS variables that were removed in the previous patch.

This series adds lines rather than removing lines. That is because things are made more explicit, introducing per-setup-type variables where previously several setup types were (partially) reusing the pep517 variables. There are also some additional lines because of more line splitting.

To test this series, I built all the python packages with one specific toolchain configuration, and I ran all runtime tests for python packages. One package failed to build: host-python-sip. It also fails on master. For the runtime tests, 14 of them failed, all of them also fail on master.

The following changes since commit 7906272c39744e26ed73028725787aa3a4441c54:

package/python-rtoml: migrate to setuptools-rust infrastructure (2023-09-29 22:02:31 +0200)

are available in the Git repository at:

[email protected]:arnout/buildroot.git pkg-python-refactor-variables

for you to fetch changes up to 89b33e004fc13e22a9c0bdcafcee245a97d2dd51:

docs/manual: remove references to PKG_PYTHON_*_OPTS (2023-09-30 15:18:48 +0200)

----------------------------------------------------------------
Arnout Vandecappelle (Essensium/Mind) (10):
package/pkg-python.mk: remove $(2)_PYTHON_INTERPRETER variable package/pkg-python.mk: remove _BASE_BUILD_OPTS variable package/pkg-python.mk: split the commands in a target and host section package/pkg-python.mk: replace $(_BASE_ENV) with $($(SETUP_TYPE)_ENV) package/pkg-python.mk: replace $(_BASE_BUILD_CMD) with $($(SETUP_TYPE)_BUILD_CMD) package/python-flit-core: instantiate _INSTALL_CMDS
package/jailhouse: expand PKG_PYTHON_SETUPTOOLS_INSTALL_TARGET_OPTS package/i2c-tools: expand PKG_PYTHON_SETUPTOOLS_INSTALL_TARGET_OPTS package/pkg-python.mk: replace $(_BASE_INSTALL*_CMD) with $($(SETUP_TYPE)_INSTALL*_CMD) docs/manual: remove references to PKG_PYTHON_*_OPTS

 docs/manual/adding-packages-python.txt       |  14 +-------
 package/i2c-tools/i2c-tools.mk               |   6 ++--
 package/jailhouse/jailhouse.mk               |   7 +++-
 package/pkg-python.mk                        | 256 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------------------------
 package/python-flit-core/python-flit-core.mk |   9 +++--
 5 files changed, 173 insertions(+), 119 deletions(-)

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

#1 lore raw

PATCH 1/10 package/pkg-python.mk: remove $(2)_PYTHON_INTERPRETER variable

This is a leftover from python 2/3. Since the interpreter is now always python3, we can simply call it like that - like is done in all the other places where python is called.

While we're at it, call python3 explicitly rather than relying on the symlink.

---
 package/pkg-python.mk | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)
package/pkg-python.mk +4 -8
index 28ee4cb85f..1fc096efb3 100644
@@ -325,10 +325,6 @@ $(2)_DOWNLOAD_POST_PROCESS = cargo
 $(2)_DOWNLOAD_DEPENDENCIES = host-rustc
 endif # SETUP_TYPE
 
-# Python interpreter to use for building the package.
-#
-$(2)_PYTHON_INTERPRETER = $$(HOST_DIR)/bin/python
-
 #
 # Build step. Only define it if not already defined by the package .mk
 # file.
@@ -337,7 +333,7 @@ ifndef $(2)_BUILD_CMDS
 define $(2)_BUILD_CMDS
 	(cd $$($$(PKG)_BUILDDIR)/; \
 		$$($$(PKG)_BASE_ENV) $$($$(PKG)_ENV) \
-		$$($(2)_PYTHON_INTERPRETER) \
+		$$(HOST_DIR)/bin/python3 \
 		$$($$(PKG)_BASE_BUILD_CMD) \
 		$$($$(PKG)_BASE_BUILD_OPTS) $$($$(PKG)_BUILD_OPTS))
 endef
@@ -351,7 +347,7 @@ ifndef $(2)_INSTALL_CMDS
 define $(2)_INSTALL_CMDS
 	(cd $$($$(PKG)_BUILDDIR)/; \
 		$$($$(PKG)_BASE_ENV) $$($$(PKG)_ENV) \
-		$$($(2)_PYTHON_INTERPRETER) \
+		$$(HOST_DIR)/bin/python3 \
 		$$($$(PKG)_BASE_INSTALL_CMD) \
 		$$($$(PKG)_INSTALL_OPTS))
 endef
@@ -365,7 +361,7 @@ ifndef $(2)_INSTALL_TARGET_CMDS
 define $(2)_INSTALL_TARGET_CMDS
 	(cd $$($$(PKG)_BUILDDIR)/; \
 		$$($$(PKG)_BASE_ENV) $$($$(PKG)_ENV) \
-		$$($(2)_PYTHON_INTERPRETER) \
+		$$(HOST_DIR)/bin/python3 \
 		$$($$(PKG)_BASE_INSTALL_TARGET_CMD) \
 		$$($$(PKG)_INSTALL_TARGET_OPTS))
 endef
@@ -379,7 +375,7 @@ ifndef $(2)_INSTALL_STAGING_CMDS
 define $(2)_INSTALL_STAGING_CMDS
 	(cd $$($$(PKG)_BUILDDIR)/; \
 		$$($$(PKG)_BASE_ENV) $$($$(PKG)_ENV) \
-		$$($(2)_PYTHON_INTERPRETER) \
+		$$(HOST_DIR)/bin/python3 \
 		$$($$(PKG)_BASE_INSTALL_STAGING_CMD) \
 		$$($$(PKG)_INSTALL_STAGING_OPTS))
 endef
Signature · 6 lines
2.41.0

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#2 lore raw

Re: [Buildroot] [PATCH 01/10] package/pkg-python.mk: remove $(2)_PYTHON_INTERPRETER variable

Arnout, All,

On 2023-10-01 00:16 +0200, Arnout Vandecappelle via buildroot spake thusly:

Quoted 8 lines

This is a leftover from python 2/3. Since the interpreter is now always python3, we can simply call it like that - like is done in all the other places where python is called.

While we're at it, call python3 explicitly rather than relying on the symlink.

Applied to next, thanks.

Regards,
Yann E. MORIN.

Quoted 62 lines
---
 package/pkg-python.mk | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)
package/pkg-python.mk +4 -8
index 28ee4cb85f..1fc096efb3 100644
@@ -325,10 +325,6 @@ $(2)_DOWNLOAD_POST_PROCESS = cargo
 $(2)_DOWNLOAD_DEPENDENCIES = host-rustc
 endif # SETUP_TYPE
 
-# Python interpreter to use for building the package.
-#
-$(2)_PYTHON_INTERPRETER = $$(HOST_DIR)/bin/python
-
 #
 # Build step. Only define it if not already defined by the package .mk
 # file.
@@ -337,7 +333,7 @@ ifndef $(2)_BUILD_CMDS
 define $(2)_BUILD_CMDS
 	(cd $$($$(PKG)_BUILDDIR)/; \
 		$$($$(PKG)_BASE_ENV) $$($$(PKG)_ENV) \
-		$$($(2)_PYTHON_INTERPRETER) \
+		$$(HOST_DIR)/bin/python3 \
 		$$($$(PKG)_BASE_BUILD_CMD) \
 		$$($$(PKG)_BASE_BUILD_OPTS) $$($$(PKG)_BUILD_OPTS))
 endef
@@ -351,7 +347,7 @@ ifndef $(2)_INSTALL_CMDS
 define $(2)_INSTALL_CMDS
 	(cd $$($$(PKG)_BUILDDIR)/; \
 		$$($$(PKG)_BASE_ENV) $$($$(PKG)_ENV) \
-		$$($(2)_PYTHON_INTERPRETER) \
+		$$(HOST_DIR)/bin/python3 \
 		$$($$(PKG)_BASE_INSTALL_CMD) \
 		$$($$(PKG)_INSTALL_OPTS))
 endef
@@ -365,7 +361,7 @@ ifndef $(2)_INSTALL_TARGET_CMDS
 define $(2)_INSTALL_TARGET_CMDS
 	(cd $$($$(PKG)_BUILDDIR)/; \
 		$$($$(PKG)_BASE_ENV) $$($$(PKG)_ENV) \
-		$$($(2)_PYTHON_INTERPRETER) \
+		$$(HOST_DIR)/bin/python3 \
 		$$($$(PKG)_BASE_INSTALL_TARGET_CMD) \
 		$$($$(PKG)_INSTALL_TARGET_OPTS))
 endef
@@ -379,7 +375,7 @@ ifndef $(2)_INSTALL_STAGING_CMDS
 define $(2)_INSTALL_STAGING_CMDS
 	(cd $$($$(PKG)_BUILDDIR)/; \
 		$$($$(PKG)_BASE_ENV) $$($$(PKG)_ENV) \
-		$$($(2)_PYTHON_INTERPRETER) \
+		$$(HOST_DIR)/bin/python3 \
 		$$($$(PKG)_BASE_INSTALL_STAGING_CMD) \
 		$$($$(PKG)_INSTALL_STAGING_OPTS))
 endef
Signature · 6 lines
2.41.0

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
Signature · 10 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 561 099 427 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#3 lore raw

PATCH 2/10 package/pkg-python.mk: remove _BASE_BUILD_OPTS variable

In reply to Arnout Vandecappelle via buildroot

This variable can just as well be merged into _BASE_BUILD_CMD. This is how it's done for the install opts. And anyway it's only used by distutils and nowhere else.

---
 package/pkg-python.mk | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
package/pkg-python.mk +2 -3
index 1fc096efb3..eacf75c165 100644
@@ -198,8 +198,7 @@ endif
 ifeq ($$($(2)_SETUP_TYPE),distutils)
 ifeq ($(4),target)
 $(2)_BASE_ENV = $$(PKG_PYTHON_DISTUTILS_ENV)
-$(2)_BASE_BUILD_CMD = setup.py build
-$(2)_BASE_BUILD_OPTS = $$(PKG_PYTHON_DISTUTILS_BUILD_OPTS)
+$(2)_BASE_BUILD_CMD = setup.py build $$(PKG_PYTHON_DISTUTILS_BUILD_OPTS)
 $(2)_BASE_INSTALL_TARGET_CMD  = setup.py install --no-compile $$(PKG_PYTHON_DISTUTILS_INSTALL_TARGET_OPTS)
 $(2)_BASE_INSTALL_STAGING_CMD = setup.py install $$(PKG_PYTHON_DISTUTILS_INSTALL_STAGING_OPTS)
 else
@@ -335,7 +334,7 @@ define $(2)_BUILD_CMDS
 		$$($$(PKG)_BASE_ENV) $$($$(PKG)_ENV) \
 		$$(HOST_DIR)/bin/python3 \
 		$$($$(PKG)_BASE_BUILD_CMD) \
-		$$($$(PKG)_BASE_BUILD_OPTS) $$($$(PKG)_BUILD_OPTS))
+		$$($$(PKG)_BUILD_OPTS))
 endef
 endif
 
Signature · 6 lines
2.41.0

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#4 lore raw

Re: [Buildroot] [PATCH 02/10] package/pkg-python.mk: remove _BASE_BUILD_OPTS variable

Arnout, All,

On 2023-10-01 00:16 +0200, Arnout Vandecappelle via buildroot spake thusly:

Quoted 5 lines

This variable can just as well be merged into _BASE_BUILD_CMD. This is how it's done for the install opts. And anyway it's only used by distutils and nowhere else.

Applied to next, thanks.

Regards,
Yann E. MORIN.

Quoted 34 lines
---
 package/pkg-python.mk | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
package/pkg-python.mk +2 -3
index 1fc096efb3..eacf75c165 100644
@@ -198,8 +198,7 @@ endif
 ifeq ($$($(2)_SETUP_TYPE),distutils)
 ifeq ($(4),target)
 $(2)_BASE_ENV = $$(PKG_PYTHON_DISTUTILS_ENV)
-$(2)_BASE_BUILD_CMD = setup.py build
-$(2)_BASE_BUILD_OPTS = $$(PKG_PYTHON_DISTUTILS_BUILD_OPTS)
+$(2)_BASE_BUILD_CMD = setup.py build $$(PKG_PYTHON_DISTUTILS_BUILD_OPTS)
 $(2)_BASE_INSTALL_TARGET_CMD  = setup.py install --no-compile $$(PKG_PYTHON_DISTUTILS_INSTALL_TARGET_OPTS)
 $(2)_BASE_INSTALL_STAGING_CMD = setup.py install $$(PKG_PYTHON_DISTUTILS_INSTALL_STAGING_OPTS)
 else
@@ -335,7 +334,7 @@ define $(2)_BUILD_CMDS
 		$$($$(PKG)_BASE_ENV) $$($$(PKG)_ENV) \
 		$$(HOST_DIR)/bin/python3 \
 		$$($$(PKG)_BASE_BUILD_CMD) \
-		$$($$(PKG)_BASE_BUILD_OPTS) $$($$(PKG)_BUILD_OPTS))
+		$$($$(PKG)_BUILD_OPTS))
 endef
 endif
 
Signature · 6 lines
2.41.0

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
Signature · 10 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 561 099 427 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#5 lore raw

PATCH 3/10 package/pkg-python.mk: split the commands in a target and host section

In reply to Arnout Vandecappelle via buildroot

Only define the _CMDS variables that are relevant for the target resp. host variant. Duplicate the _BUILD_CMDS. This will allow us to differentiate part of the _BUILD_CMDS definition in a follow-up patch.

---
 package/pkg-python.mk | 47 ++++++++++++++++++++++++++++++-------------
 1 file changed, 33 insertions(+), 14 deletions(-)
package/pkg-python.mk +33 -14
index eacf75c165..c1640d71bb 100644
@@ -324,6 +324,7 @@ $(2)_DOWNLOAD_POST_PROCESS = cargo
 $(2)_DOWNLOAD_DEPENDENCIES = host-rustc
 endif # SETUP_TYPE
 
+ifeq ($(4),target)
 #
 # Build step. Only define it if not already defined by the package .mk
 # file.
@@ -338,20 +339,6 @@ define $(2)_BUILD_CMDS
 endef
 endif
 
-#
-# Host installation step. Only define it if not already defined by the
-# package .mk file.
-#
-ifndef $(2)_INSTALL_CMDS
-define $(2)_INSTALL_CMDS
-	(cd $$($$(PKG)_BUILDDIR)/; \
-		$$($$(PKG)_BASE_ENV) $$($$(PKG)_ENV) \
-		$$(HOST_DIR)/bin/python3 \
-		$$($$(PKG)_BASE_INSTALL_CMD) \
-		$$($$(PKG)_INSTALL_OPTS))
-endef
-endif
-
 #
 # Target installation step. Only define it if not already defined by
 # the package .mk file.
@@ -380,6 +367,38 @@ define $(2)_INSTALL_STAGING_CMDS
 endef
 endif
 
+else # host
+
+#
+# Host build step. Only define it if not already defined by the package .mk
+# file.
+#
+ifndef $(2)_BUILD_CMDS
+define $(2)_BUILD_CMDS
+	(cd $$($$(PKG)_BUILDDIR)/; \
+		$$($$(PKG)_BASE_ENV) $$($$(PKG)_ENV) \
+		$$(HOST_DIR)/bin/python3 \
+		$$($$(PKG)_BASE_BUILD_CMD) \
+		$$($$(PKG)_BUILD_OPTS))
+endef
+endif
+
+#
+# Host installation step. Only define it if not already defined by the
+# package .mk file.
+#
+ifndef $(2)_INSTALL_CMDS
+define $(2)_INSTALL_CMDS
+	(cd $$($$(PKG)_BUILDDIR)/; \
+		$$($$(PKG)_BASE_ENV) $$($$(PKG)_ENV) \
+		$$(HOST_DIR)/bin/python3 \
+		$$($$(PKG)_BASE_INSTALL_CMD) \
+		$$($$(PKG)_INSTALL_OPTS))
+endef
+endif
+
+endif # host / target
+
 # Call the generic package infrastructure to generate the necessary
 # make targets
 $(call inner-generic-package,$(1),$(2),$(3),$(4))
Signature · 6 lines
2.41.0

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#6 lore raw

Re: [Buildroot] [PATCH 03/10] package/pkg-python.mk: split the commands in a target and host section

Arnout, All,

On 2023-10-01 00:16 +0200, Arnout Vandecappelle via buildroot spake thusly:

Quoted 5 lines

Only define the _CMDS variables that are relevant for the target resp. host variant. Duplicate the _BUILD_CMDS. This will allow us to differentiate part of the _BUILD_CMDS definition in a follow-up patch.

Applied to next, thanks.

Regards,
Yann E. MORIN.

Quoted 83 lines
---
 package/pkg-python.mk | 47 ++++++++++++++++++++++++++++++-------------
 1 file changed, 33 insertions(+), 14 deletions(-)
package/pkg-python.mk +33 -14
index eacf75c165..c1640d71bb 100644
@@ -324,6 +324,7 @@ $(2)_DOWNLOAD_POST_PROCESS = cargo
 $(2)_DOWNLOAD_DEPENDENCIES = host-rustc
 endif # SETUP_TYPE
 
+ifeq ($(4),target)
 #
 # Build step. Only define it if not already defined by the package .mk
 # file.
@@ -338,20 +339,6 @@ define $(2)_BUILD_CMDS
 endef
 endif
 
-#
-# Host installation step. Only define it if not already defined by the
-# package .mk file.
-#
-ifndef $(2)_INSTALL_CMDS
-define $(2)_INSTALL_CMDS
-	(cd $$($$(PKG)_BUILDDIR)/; \
-		$$($$(PKG)_BASE_ENV) $$($$(PKG)_ENV) \
-		$$(HOST_DIR)/bin/python3 \
-		$$($$(PKG)_BASE_INSTALL_CMD) \
-		$$($$(PKG)_INSTALL_OPTS))
-endef
-endif
-
 #
 # Target installation step. Only define it if not already defined by
 # the package .mk file.
@@ -380,6 +367,38 @@ define $(2)_INSTALL_STAGING_CMDS
 endef
 endif
 
+else # host
+
+#
+# Host build step. Only define it if not already defined by the package .mk
+# file.
+#
+ifndef $(2)_BUILD_CMDS
+define $(2)_BUILD_CMDS
+	(cd $$($$(PKG)_BUILDDIR)/; \
+		$$($$(PKG)_BASE_ENV) $$($$(PKG)_ENV) \
+		$$(HOST_DIR)/bin/python3 \
+		$$($$(PKG)_BASE_BUILD_CMD) \
+		$$($$(PKG)_BUILD_OPTS))
+endef
+endif
+
+#
+# Host installation step. Only define it if not already defined by the
+# package .mk file.
+#
+ifndef $(2)_INSTALL_CMDS
+define $(2)_INSTALL_CMDS
+	(cd $$($$(PKG)_BUILDDIR)/; \
+		$$($$(PKG)_BASE_ENV) $$($$(PKG)_ENV) \
+		$$(HOST_DIR)/bin/python3 \
+		$$($$(PKG)_BASE_INSTALL_CMD) \
+		$$($$(PKG)_INSTALL_OPTS))
+endef
+endif
+
+endif # host / target
+
 # Call the generic package infrastructure to generate the necessary
 # make targets
 $(call inner-generic-package,$(1),$(2),$(3),$(4))
Signature · 6 lines
2.41.0

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
Signature · 10 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 561 099 427 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#7 lore raw

PATCH 4/10 package/pkg-python.mk: replace $(_BASE_ENV) with $($(SETUP_TYPE)_ENV)

In reply to Arnout Vandecappelle via buildroot

The _BASE_ENV variable is set based on the setup type, and only based on the setup type. Because of this, we have a large conditional tree in inner-python-package which makes things hard to read.

Rather than conditions, it's also possible to use indirect variables. Concretely, we can use $(PKG_PYTHON_$($(PKG)_SETUP_TYPE)_ENV) instead of $($(PKG)_BASE_ENV) to dispatch to the right ENV variable.

Once we do the same for all other variables that are set in the condition tree, we'll be able to remove the condition tree entirely.

Because $($(PKG)_SETUP_TYPE) is lowercase (e.g. 'setuptools' or 'pep517'), while the existing _ENV variables have uppercase names (e.g. PKG_PYTHON_SETUPTOOLS_ENV), we need to convert the setup type to uppercase. Introduce the variable $(PKG)_SETUP_TYPE_UPPER for this.

flit was reusing the _BASE_ENV definition from pep517, and flit-bootstrap also didn't have its own _ENV definition yet, so those have to be added.

---
 package/pkg-python.mk | 52 ++++++++++++++++++++-----------------------
 1 file changed, 24 insertions(+), 28 deletions(-)
package/pkg-python.mk +24 -28
index c1640d71bb..8e8955f3c4 100644
@@ -158,6 +158,18 @@ HOST_PKG_PYTHON_PEP517_INSTALL_OPTS = \
 HOST_PKG_PYTHON_PEP517_BOOTSTRAP_INSTALL_OPTS = \
 	--installdir=$(HOST_DIR)/lib/python$(PYTHON3_VERSION_MAJOR)/site-packages
 
+# Target flit packages
+PKG_PYTHON_FLIT_ENV = \
+	$(PKG_PYTHON_PEP517_ENV)
+
+# Host flit packages
+HOST_PKG_PYTHON_FLIT_ENV = \
+	$(HOST_PKG_PYTHON_PEP517_ENV)
+
+# Host flit-bootstrap packages
+HOST_PKG_PYTHON_FLIT_BOOTSTRAP_ENV = \
+	$(HOST_PKG_PYTHON_PEP517_ENV)
+
 # Target maturin packages
 PKG_PYTHON_MATURIN_ENV = \
 	$(PKG_PYTHON_PEP517_ENV) \
@@ -194,54 +206,34 @@ ifndef $(2)_SETUP_TYPE
  endif
 endif
 
+$(2)_SETUP_TYPE_UPPER = $$(call UPPERCASE,$$($(2)_SETUP_TYPE))
+
 # Distutils
 ifeq ($$($(2)_SETUP_TYPE),distutils)
 ifeq ($(4),target)
-$(2)_BASE_ENV = $$(PKG_PYTHON_DISTUTILS_ENV)
 $(2)_BASE_BUILD_CMD = setup.py build $$(PKG_PYTHON_DISTUTILS_BUILD_OPTS)
 $(2)_BASE_INSTALL_TARGET_CMD  = setup.py install --no-compile $$(PKG_PYTHON_DISTUTILS_INSTALL_TARGET_OPTS)
 $(2)_BASE_INSTALL_STAGING_CMD = setup.py install $$(PKG_PYTHON_DISTUTILS_INSTALL_STAGING_OPTS)
 else
-$(2)_BASE_ENV         = $$(HOST_PKG_PYTHON_DISTUTILS_ENV)
 $(2)_BASE_BUILD_CMD   = setup.py build
 $(2)_BASE_INSTALL_CMD = setup.py install $$(HOST_PKG_PYTHON_DISTUTILS_INSTALL_OPTS)
 endif
 # Setuptools
 else ifneq ($$(filter setuptools setuptools-rust,$$($(2)_SETUP_TYPE)),)
 ifeq ($(4),target)
-ifeq ($$($(2)_SETUP_TYPE),setuptools-rust)
-$(2)_BASE_ENV = $$(PKG_PYTHON_SETUPTOOLS_RUST_ENV)
-else
-$(2)_BASE_ENV = $$(PKG_PYTHON_SETUPTOOLS_ENV)
-endif
 $(2)_BASE_BUILD_CMD = $$(PKG_PYTHON_SETUPTOOLS_CMD) build
 $(2)_BASE_INSTALL_TARGET_CMD = $$(PKG_PYTHON_SETUPTOOLS_CMD) install --no-compile $$(PKG_PYTHON_SETUPTOOLS_INSTALL_TARGET_OPTS)
 $(2)_BASE_INSTALL_STAGING_CMD = $$(PKG_PYTHON_SETUPTOOLS_CMD) install $$(PKG_PYTHON_SETUPTOOLS_INSTALL_STAGING_OPTS)
 else
-ifeq ($$($(2)_SETUP_TYPE),setuptools-rust)
-$(2)_BASE_ENV = $$(HOST_PKG_PYTHON_SETUPTOOLS_RUST_ENV)
-else
-$(2)_BASE_ENV = $$(HOST_PKG_PYTHON_SETUPTOOLS_ENV)
-endif
 $(2)_BASE_BUILD_CMD = $$(PKG_PYTHON_SETUPTOOLS_CMD) build
 $(2)_BASE_INSTALL_CMD = $$(PKG_PYTHON_SETUPTOOLS_CMD) install $$(HOST_PKG_PYTHON_SETUPTOOLS_INSTALL_OPTS)
 endif
 else ifneq ($$(filter flit maturin pep517,$$($(2)_SETUP_TYPE)),)
 ifeq ($(4),target)
-ifeq ($$($(2)_SETUP_TYPE),maturin)
-$(2)_BASE_ENV = $$(PKG_PYTHON_MATURIN_ENV)
-else
-$(2)_BASE_ENV = $$(PKG_PYTHON_PEP517_ENV)
-endif
 $(2)_BASE_BUILD_CMD = -m build -n -w
 $(2)_BASE_INSTALL_TARGET_CMD = $(TOPDIR)/support/scripts/pyinstaller.py dist/* $$(PKG_PYTHON_PEP517_INSTALL_TARGET_OPTS)
 $(2)_BASE_INSTALL_STAGING_CMD = $(TOPDIR)/support/scripts/pyinstaller.py dist/* $$(PKG_PYTHON_PEP517_INSTALL_STAGING_OPTS)
 else
-ifeq ($$($(2)_SETUP_TYPE),maturin)
-$(2)_BASE_ENV = $$(HOST_PKG_PYTHON_MATURIN_ENV)
-else
-$(2)_BASE_ENV = $$(HOST_PKG_PYTHON_PEP517_ENV)
-endif
 $(2)_BASE_BUILD_CMD = -m build -n -w
 $(2)_BASE_INSTALL_CMD = $(TOPDIR)/support/scripts/pyinstaller.py dist/* $$(HOST_PKG_PYTHON_PEP517_INSTALL_OPTS)
 endif
@@ -249,7 +241,6 @@ else ifeq ($$($(2)_SETUP_TYPE),flit-bootstrap)
 ifeq ($(4),target)
 $$(error flit-bootstrap setup type only supported for host packages)
 else
-$(2)_BASE_ENV = $$(HOST_PKG_PYTHON_PEP517_ENV)
 $(2)_BASE_BUILD_CMD = -m flit_core.wheel
 $(2)_BASE_INSTALL_CMD ?= $(TOPDIR)/support/scripts/pyinstaller.py dist/* $$(HOST_PKG_PYTHON_PEP517_INSTALL_OPTS)
 endif
@@ -332,7 +323,8 @@ ifeq ($(4),target)
 ifndef $(2)_BUILD_CMDS
 define $(2)_BUILD_CMDS
 	(cd $$($$(PKG)_BUILDDIR)/; \
-		$$($$(PKG)_BASE_ENV) $$($$(PKG)_ENV) \
+		$$(PKG_PYTHON_$$($$(PKG)_SETUP_TYPE_UPPER)_ENV) \
+		$$($$(PKG)_ENV) \
 		$$(HOST_DIR)/bin/python3 \
 		$$($$(PKG)_BASE_BUILD_CMD) \
 		$$($$(PKG)_BUILD_OPTS))
@@ -346,7 +338,8 @@ endif
 ifndef $(2)_INSTALL_TARGET_CMDS
 define $(2)_INSTALL_TARGET_CMDS
 	(cd $$($$(PKG)_BUILDDIR)/; \
-		$$($$(PKG)_BASE_ENV) $$($$(PKG)_ENV) \
+		$$(PKG_PYTHON_$$($$(PKG)_SETUP_TYPE_UPPER)_ENV) \
+		$$($$(PKG)_ENV) \
 		$$(HOST_DIR)/bin/python3 \
 		$$($$(PKG)_BASE_INSTALL_TARGET_CMD) \
 		$$($$(PKG)_INSTALL_TARGET_OPTS))
@@ -360,7 +353,8 @@ endif
 ifndef $(2)_INSTALL_STAGING_CMDS
 define $(2)_INSTALL_STAGING_CMDS
 	(cd $$($$(PKG)_BUILDDIR)/; \
-		$$($$(PKG)_BASE_ENV) $$($$(PKG)_ENV) \
+		$$(PKG_PYTHON_$$($$(PKG)_SETUP_TYPE_UPPER)_ENV) \
+		$$($$(PKG)_ENV) \
 		$$(HOST_DIR)/bin/python3 \
 		$$($$(PKG)_BASE_INSTALL_STAGING_CMD) \
 		$$($$(PKG)_INSTALL_STAGING_OPTS))
@@ -376,7 +370,8 @@ else # host
 ifndef $(2)_BUILD_CMDS
 define $(2)_BUILD_CMDS
 	(cd $$($$(PKG)_BUILDDIR)/; \
-		$$($$(PKG)_BASE_ENV) $$($$(PKG)_ENV) \
+		$$(HOST_PKG_PYTHON_$$($$(PKG)_SETUP_TYPE_UPPER)_ENV) \
+		$$($$(PKG)_ENV) \
 		$$(HOST_DIR)/bin/python3 \
 		$$($$(PKG)_BASE_BUILD_CMD) \
 		$$($$(PKG)_BUILD_OPTS))
@@ -390,7 +385,8 @@ endif
 ifndef $(2)_INSTALL_CMDS
 define $(2)_INSTALL_CMDS
 	(cd $$($$(PKG)_BUILDDIR)/; \
-		$$($$(PKG)_BASE_ENV) $$($$(PKG)_ENV) \
+		$$(HOST_PKG_PYTHON_$$($$(PKG)_SETUP_TYPE_UPPER)_ENV) \
+		$$($$(PKG)_ENV) \
 		$$(HOST_DIR)/bin/python3 \
 		$$($$(PKG)_BASE_INSTALL_CMD) \
 		$$($$(PKG)_INSTALL_OPTS))
Signature · 6 lines
2.41.0

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#8 lore raw

PATCH 5/10 package/pkg-python.mk: replace $(_BASE_BUILD_CMD) with $($(SETUP_TYPE)_BUILD_CMD)

In reply to Arnout Vandecappelle via buildroot

The _BASE_BUILD_CMD variable is set based on the setup type, and only based on the setup type. Because of this, we have a large conditional tree in inner-python-package which makes things hard to read.

Rather than conditions, it's also possible to use indirect variables. Concretely, we can define PKG_PYTHON_DISTUTILS_BUILD_CMD etc., and use $(PKG_PYTHON_$($(PKG)_SETUP_TYPE)_BUILD_CMD) instead of $($(PKG)_BASE_BUILD_CMD) to dispatch to the right _BUILD_CMD variable.

Once we do the same for all other variables that are set in the condition tree, we'll be able to remove the condition tree entirely.

setuptools-rust, flit and maturin didn't have their own definition of _BUILD_CMD but were under the setuptools resp. pep517 condition. For these, we have to define new variables that copy the value from PKG_PYTHON_SETUPTOOLS_BUILD_CMD resp. PKG_PYTHON_PEP517_BUILD_CMD.

---
 package/pkg-python.mk | 50 ++++++++++++++++++++++++++++++++++---------
 1 file changed, 40 insertions(+), 10 deletions(-)
package/pkg-python.mk +40 -10
index 8e8955f3c4..5f8ef14262 100644
@@ -57,7 +57,8 @@ PKG_PYTHON_DISTUTILS_ENV = \
 	$(PKG_PYTHON_ENV) \
 	LDSHARED="$(TARGET_CROSS)gcc -shared"
 
-PKG_PYTHON_DISTUTILS_BUILD_OPTS = \
+PKG_PYTHON_DISTUTILS_BUILD_CMD = \
+	setup.py build \
 	--executable=/usr/bin/python
 
 PKG_PYTHON_DISTUTILS_INSTALL_OPTS = \
@@ -76,6 +77,9 @@ PKG_PYTHON_DISTUTILS_INSTALL_STAGING_OPTS = \
 HOST_PKG_PYTHON_DISTUTILS_ENV = \
 	$(HOST_PKG_PYTHON_ENV)
 
+HOST_PKG_PYTHON_DISTUTILS_BUILD_CMD = \
+	setup.py build \
+
 HOST_PKG_PYTHON_DISTUTILS_INSTALL_OPTS = \
 	--prefix=$(HOST_DIR)
 
@@ -86,6 +90,9 @@ PKG_PYTHON_SETUPTOOLS_ENV = \
 PKG_PYTHON_SETUPTOOLS_CMD = \
 	$(if $(wildcard $($(PKG)_BUILDDIR)/setup.py),setup.py,-c 'from setuptools import setup;setup()')
 
+PKG_PYTHON_SETUPTOOLS_BUILD_CMD = \
+	$(PKG_PYTHON_SETUPTOOLS_CMD) build
+
 PKG_PYTHON_SETUPTOOLS_INSTALL_OPTS = \
 	--install-headers=/usr/include/python$(PYTHON3_VERSION_MAJOR) \
 	--prefix=/usr \
@@ -104,6 +111,9 @@ PKG_PYTHON_SETUPTOOLS_INSTALL_STAGING_OPTS = \
 HOST_PKG_PYTHON_SETUPTOOLS_ENV = \
 	$(HOST_PKG_PYTHON_ENV)
 
+HOST_PKG_PYTHON_SETUPTOOLS_BUILD_CMD = \
+	$(PKG_PYTHON_SETUPTOOLS_CMD) build
+
 HOST_PKG_PYTHON_SETUPTOOLS_INSTALL_OPTS = \
 	--prefix=$(HOST_DIR) \
 	--root=/ \
@@ -115,16 +125,25 @@ PKG_PYTHON_SETUPTOOLS_RUST_ENV = \
 	$(PKG_CARGO_ENV) \
 	PYO3_CROSS_LIB_DIR="$(STAGING_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)"
 
+PKG_PYTHON_SETUPTOOLS_RUST_BUILD_CMD = \
+	$(PKG_PYTHON_SETUPTOOLS_BUILD_CMD)
+
 # Host setuptools-rust-based packages
 HOST_PKG_PYTHON_SETUPTOOLS_RUST_ENV = \
 	$(HOST_PKG_PYTHON_SETUPTOOLS_ENV) \
 	$(HOST_PKG_CARGO_ENV) \
 	PYO3_CROSS_LIB_DIR="$(HOST_DIR)/lib/python$(PYTHON3_VERSION_MAJOR)"
 
+HOST_PKG_PYTHON_SETUPTOOLS_RUST_BUILD_CMD = \
+	$(HOST_PKG_PYTHON_SETUPTOOLS_BUILD_CMD)
+
 # Target pep517-based packages
 PKG_PYTHON_PEP517_ENV = \
 	$(PKG_PYTHON_ENV)
 
+PKG_PYTHON_PEP517_BUILD_CMD = \
+	-m build -n -w
+
 PKG_PYTHON_PEP517_INSTALL_OPTS = \
 	--interpreter=/usr/bin/python \
 	--script-kind=posix
@@ -147,6 +166,9 @@ PKG_PYTHON_PEP517_INSTALL_STAGING_OPTS = \
 HOST_PKG_PYTHON_PEP517_ENV = \
 	$(HOST_PKG_PYTHON_ENV)
 
+HOST_PKG_PYTHON_PEP517_BUILD_CMD = \
+	-m build -n -w
+
 HOST_PKG_PYTHON_PEP517_INSTALL_OPTS = \
 	--interpreter=$(HOST_DIR)/bin/python \
 	--script-kind=posix \
@@ -162,26 +184,41 @@ HOST_PKG_PYTHON_PEP517_BOOTSTRAP_INSTALL_OPTS = \
 PKG_PYTHON_FLIT_ENV = \
 	$(PKG_PYTHON_PEP517_ENV)
 
+PKG_PYTHON_FLIT_BUILD_CMD = \
+	$(PKG_PYTHON_PEP517_BUILD_CMD)
+
 # Host flit packages
 HOST_PKG_PYTHON_FLIT_ENV = \
 	$(HOST_PKG_PYTHON_PEP517_ENV)
 
+HOST_PKG_PYTHON_FLIT_BUILD_CMD = \
+	$(HOST_PKG_PYTHON_PEP517_BUILD_CMD)
+
 # Host flit-bootstrap packages
 HOST_PKG_PYTHON_FLIT_BOOTSTRAP_ENV = \
 	$(HOST_PKG_PYTHON_PEP517_ENV)
 
+HOST_PKG_PYTHON_FLIT_BOOTSTRAP_BUILD_CMD = \
+	-m flit_core.wheel
+
 # Target maturin packages
 PKG_PYTHON_MATURIN_ENV = \
 	$(PKG_PYTHON_PEP517_ENV) \
 	$(PKG_CARGO_ENV) \
 	PYO3_CROSS_LIB_DIR="$(STAGING_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)"
 
+PKG_PYTHON_MATURIN_BUILD_CMD = \
+	$(PKG_PYTHON_PEP517_BUILD_CMD)
+
 # Host maturin packages
 HOST_PKG_PYTHON_MATURIN_ENV = \
 	$(HOST_PKG_PYTHON_PEP517_ENV) \
 	$(HOST_PKG_CARGO_ENV) \
 	PYO3_CROSS_LIB_DIR="$(HOST_DIR)/lib/python$(PYTHON3_VERSION_MAJOR)"
 
+HOST_PKG_PYTHON_MATURIN_BUILD_CMD = \
+	$(HOST_PKG_PYTHON_PEP517_BUILD_CMD)
+
 ################################################################################
 # inner-python-package -- defines how the configuration, compilation
 # and installation of a Python package should be done, implements a
@@ -211,37 +248,30 @@ $(2)_SETUP_TYPE_UPPER = $$(call UPPERCASE,$$($(2)_SETUP_TYPE))
 # Distutils
 ifeq ($$($(2)_SETUP_TYPE),distutils)
 ifeq ($(4),target)
-$(2)_BASE_BUILD_CMD = setup.py build $$(PKG_PYTHON_DISTUTILS_BUILD_OPTS)
 $(2)_BASE_INSTALL_TARGET_CMD  = setup.py install --no-compile $$(PKG_PYTHON_DISTUTILS_INSTALL_TARGET_OPTS)
 $(2)_BASE_INSTALL_STAGING_CMD = setup.py install $$(PKG_PYTHON_DISTUTILS_INSTALL_STAGING_OPTS)
 else
-$(2)_BASE_BUILD_CMD   = setup.py build
 $(2)_BASE_INSTALL_CMD = setup.py install $$(HOST_PKG_PYTHON_DISTUTILS_INSTALL_OPTS)
 endif
 # Setuptools
 else ifneq ($$(filter setuptools setuptools-rust,$$($(2)_SETUP_TYPE)),)
 ifeq ($(4),target)
-$(2)_BASE_BUILD_CMD = $$(PKG_PYTHON_SETUPTOOLS_CMD) build
 $(2)_BASE_INSTALL_TARGET_CMD = $$(PKG_PYTHON_SETUPTOOLS_CMD) install --no-compile $$(PKG_PYTHON_SETUPTOOLS_INSTALL_TARGET_OPTS)
 $(2)_BASE_INSTALL_STAGING_CMD = $$(PKG_PYTHON_SETUPTOOLS_CMD) install $$(PKG_PYTHON_SETUPTOOLS_INSTALL_STAGING_OPTS)
 else
-$(2)_BASE_BUILD_CMD = $$(PKG_PYTHON_SETUPTOOLS_CMD) build
 $(2)_BASE_INSTALL_CMD = $$(PKG_PYTHON_SETUPTOOLS_CMD) install $$(HOST_PKG_PYTHON_SETUPTOOLS_INSTALL_OPTS)
 endif
 else ifneq ($$(filter flit maturin pep517,$$($(2)_SETUP_TYPE)),)
 ifeq ($(4),target)
-$(2)_BASE_BUILD_CMD = -m build -n -w
 $(2)_BASE_INSTALL_TARGET_CMD = $(TOPDIR)/support/scripts/pyinstaller.py dist/* $$(PKG_PYTHON_PEP517_INSTALL_TARGET_OPTS)
 $(2)_BASE_INSTALL_STAGING_CMD = $(TOPDIR)/support/scripts/pyinstaller.py dist/* $$(PKG_PYTHON_PEP517_INSTALL_STAGING_OPTS)
 else
-$(2)_BASE_BUILD_CMD = -m build -n -w
 $(2)_BASE_INSTALL_CMD = $(TOPDIR)/support/scripts/pyinstaller.py dist/* $$(HOST_PKG_PYTHON_PEP517_INSTALL_OPTS)
 endif
 else ifeq ($$($(2)_SETUP_TYPE),flit-bootstrap)
 ifeq ($(4),target)
 $$(error flit-bootstrap setup type only supported for host packages)
 else
-$(2)_BASE_BUILD_CMD = -m flit_core.wheel
 $(2)_BASE_INSTALL_CMD ?= $(TOPDIR)/support/scripts/pyinstaller.py dist/* $$(HOST_PKG_PYTHON_PEP517_INSTALL_OPTS)
 endif
 else
@@ -326,7 +356,7 @@ define $(2)_BUILD_CMDS
 		$$(PKG_PYTHON_$$($$(PKG)_SETUP_TYPE_UPPER)_ENV) \
 		$$($$(PKG)_ENV) \
 		$$(HOST_DIR)/bin/python3 \
-		$$($$(PKG)_BASE_BUILD_CMD) \
+		$$(PKG_PYTHON_$$($$(PKG)_SETUP_TYPE_UPPER)_BUILD_CMD) \
 		$$($$(PKG)_BUILD_OPTS))
 endef
 endif
@@ -373,7 +403,7 @@ define $(2)_BUILD_CMDS
 		$$(HOST_PKG_PYTHON_$$($$(PKG)_SETUP_TYPE_UPPER)_ENV) \
 		$$($$(PKG)_ENV) \
 		$$(HOST_DIR)/bin/python3 \
-		$$($$(PKG)_BASE_BUILD_CMD) \
+		$$(HOST_PKG_PYTHON_$$($$(PKG)_SETUP_TYPE_UPPER)_BUILD_CMD) \
 		$$($$(PKG)_BUILD_OPTS))
 endef
 endif
Signature · 6 lines
2.41.0

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#9 lore raw

PATCH 6/10 package/python-flit-core: instantiate _INSTALL_CMDS

In reply to Arnout Vandecappelle via buildroot

host-python-flit-core is the only package that overrides _BASE_INSTALL_CMD. Since we're going to remove that variable in a follow-up patch, we no longer will be able to do that.

Since host-python-flit-core is really a special case, it makes sense to define HOST_PYTHON_FLIT_CORE_INSTALL_CMDS in its entirety.

While we're at it, also instantiate HOST_PKG_PYTHON_PEP517_BOOTSTRAP_INSTALL_OPTS directly there. This variable is not used anywhere else, and it's a bit confusing to have it in pkg-python.mk - it looks like a mistake.

---
 package/pkg-python.mk                        | 3 ---
 package/python-flit-core/python-flit-core.mk | 9 +++++++--
 2 files changed, 7 insertions(+), 5 deletions(-)
package/pkg-python.mk +0 -3
index 5f8ef14262..be9756acc4 100644
@@ -177,9 +177,6 @@ HOST_PKG_PYTHON_PEP517_INSTALL_OPTS = \
 	--scripts=$(HOST_DIR)/bin \
 	--data=$(HOST_DIR)
 
-HOST_PKG_PYTHON_PEP517_BOOTSTRAP_INSTALL_OPTS = \
-	--installdir=$(HOST_DIR)/lib/python$(PYTHON3_VERSION_MAJOR)/site-packages
-
 # Target flit packages
 PKG_PYTHON_FLIT_ENV = \
 	$(PKG_PYTHON_PEP517_ENV)
package/python-flit-core/python-flit-core.mk +7 -2
index ea887a0258..34e58d03ca 100644
@@ -13,7 +13,12 @@ PYTHON_FLIT_CORE_SETUP_TYPE = flit-bootstrap
 
 # Use flit built in bootstrap_install for installing host-python-flit-core.
 # This is due to host-python-installer depending on host-python-flit-core.
-#
-HOST_PYTHON_FLIT_CORE_BASE_INSTALL_CMD = -m bootstrap_install dist/* $(HOST_PKG_PYTHON_PEP517_BOOTSTRAP_INSTALL_OPTS)
+define HOST_PYTHON_FLIT_CORE_INSTALL_CMDS
+	cd $($(PKG)_BUILDDIR)/; \
+		$(HOST_PKG_PYTHON_FLIT_BOOTSTRAP_ENV) \
+		$(HOST_DIR)/bin/python3 \
+		-m bootstrap_install dist/* \
+		--installdir=$(HOST_DIR)/lib/python$(PYTHON3_VERSION_MAJOR)/site-packages
+endef
 
 $(eval $(host-python-package))
Signature · 6 lines
2.41.0

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#10 lore raw

PATCH 7/10 package/jailhouse: expand PKG_PYTHON_SETUPTOOLS_INSTALL_TARGET_OPTS

In reply to Arnout Vandecappelle via buildroot

In a follow-up patch, we want to remove this variable. Replace it with its expansion, which is anyway just $(PKG_PYTHON_SETUPTOOLS_INSTALL_OPTS) --root=$(TARGET_DIR)

While we're at it, split the very long line.

---
 package/jailhouse/jailhouse.mk | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
package/jailhouse/jailhouse.mk +6 -1
index 6356c5a7aa..095032a1dd 100644
@@ -48,7 +48,12 @@ define JAILHOUSE_INSTALL_TARGET_CMDS
 	$(INSTALL) -D -m 0755 $(@D)/inmates/demos/*/*.bin $(TARGET_DIR)/usr/local/libexec/jailhouse/demos
 
 	$(if $(BR2_PACKAGE_JAILHOUSE_HELPER_SCRIPTS), \
-		cd $(@D) && $(PKG_PYTHON_SETUPTOOLS_ENV) $(HOST_DIR)/bin/python setup.py install --no-compile $(PKG_PYTHON_SETUPTOOLS_INSTALL_TARGET_OPTS))
+		cd $(@D) && \
+		$(PKG_PYTHON_SETUPTOOLS_ENV) \
+		$(HOST_DIR)/bin/python setup.py \
+		install --no-compile \
+		$(PKG_PYTHON_SETUPTOOLS_INSTALL_OPTS) \
+		--root=$(TARGET_DIR))
 endef
 
 $(eval $(generic-package))
Signature · 6 lines
2.41.0

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#11 lore raw

PATCH 8/10 package/i2c-tools: expand PKG_PYTHON_SETUPTOOLS_INSTALL_TARGET_OPTS

In reply to Arnout Vandecappelle via buildroot

In a follow-up patch, we want to remove this variable. Replace it with its expansion, which is anyway just $(PKG_PYTHON_SETUPTOOLS_INSTALL_OPTS) --root=$(TARGET_DIR)

Also remove PKG_PYTHON_SETUPTOOLS_BUILD_OPTS, which is not defined (i.e. empty).

---
 package/i2c-tools/i2c-tools.mk | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
package/i2c-tools/i2c-tools.mk +3 -3
index adccd9475d..f8d1bcb4b0 100644
@@ -36,15 +36,15 @@ I2C_TOOLS_PYTHON_BASE_ENV = \
 define I2C_TOOLS_BUILD_PYSMBUS
 	(cd $(@D)/py-smbus; \
 	$(I2C_TOOLS_PYTHON_BASE_ENV) \
-		$(HOST_DIR)/bin/python setup.py build \
-		$(PKG_PYTHON_SETUPTOOLS_BUILD_OPTS))
+		$(HOST_DIR)/bin/python setup.py build)
 endef
 
 define I2C_TOOLS_INSTALL_PYSMBUS
 	(cd $(@D)/py-smbus; \
 	$(I2C_TOOLS_PYTHON_BASE_ENV) \
 		$(HOST_DIR)/bin/python setup.py install \
-		$(PKG_PYTHON_SETUPTOOLS_INSTALL_TARGET_OPTS))
+		$(PKG_PYTHON_SETUPTOOLS_INSTALL_OPTS) \
+		--root=$(TARGET_DIR))
 endef
 
 endif # BR2_PACKAGE_PYTHON3
Signature · 6 lines
2.41.0

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#12 lore raw

PATCH 9/10 package/pkg-python.mk: replace $(_BASE_INSTALL*_CMD) with $($(SETUP_TYPE)_INSTALL*_CMD)

In reply to Arnout Vandecappelle via buildroot

The _BASE_INSTALL*_CMD variables are set based on the setup type, and only based on the setup type. Because of this, we have a large conditional tree in inner-python-package which makes things hard to read.

Rather than conditions, it's also possible to use indirect variables. Concretely, we can define PKG_PYTHON_DISTUTILS_INSTALL_TARGET_CMD etc., and use $(PKG_PYTHON_$($(PKG)_SETUP_TYPE)_INSTALL_TARGET_CMD) instead of $($(PKG)_BASE_INSTALL_TARGET_CMD) to dispatch to the right _INSTALL_TARGET_CMD variable. The same applies to _INSTALL_STAGING_CMD and HOST_..._INSTALL_CMD.

Since the _INSTALL*_OPTS variables are not (or no longer) used anywhere else, we can fold them into the _INSTALL*_CMD variables.

setuptools-rust, flit and maturin didn't have their own definition of _BUILD_CMD but were under the setuptools resp. pep517 condition. For these, we have to define new variables that copy the value from PKG_PYTHON_SETUPTOOLS_BUILD_CMD resp. PKG_PYTHON_PEP517_BUILD_CMD.

The condition tree is now empty, except for the error handling. Rework the conditions for the error handling and remove all other conditions.

---
 package/pkg-python.mk | 101 +++++++++++++++++++++++++-----------------
 1 file changed, 60 insertions(+), 41 deletions(-)
package/pkg-python.mk +60 -41
index be9756acc4..bda79116c8 100644
@@ -65,11 +65,13 @@ PKG_PYTHON_DISTUTILS_INSTALL_OPTS = \
 	--install-headers=/usr/include/python$(PYTHON3_VERSION_MAJOR) \
 	--prefix=/usr
 
-PKG_PYTHON_DISTUTILS_INSTALL_TARGET_OPTS = \
+PKG_PYTHON_DISTUTILS_INSTALL_TARGET_CMD = \
+	setup.py install --no-compile \
 	$(PKG_PYTHON_DISTUTILS_INSTALL_OPTS) \
 	--root=$(TARGET_DIR)
 
-PKG_PYTHON_DISTUTILS_INSTALL_STAGING_OPTS = \
+PKG_PYTHON_DISTUTILS_INSTALL_STAGING_CMD = \
+	setup.py install \
 	$(PKG_PYTHON_DISTUTILS_INSTALL_OPTS) \
 	--root=$(STAGING_DIR)
 
@@ -80,7 +82,8 @@ HOST_PKG_PYTHON_DISTUTILS_ENV = \
 HOST_PKG_PYTHON_DISTUTILS_BUILD_CMD = \
 	setup.py build \
 
-HOST_PKG_PYTHON_DISTUTILS_INSTALL_OPTS = \
+HOST_PKG_PYTHON_DISTUTILS_INSTALL_CMD = \
+	setup.py install \
 	--prefix=$(HOST_DIR)
 
 # Target setuptools-based packages
@@ -99,11 +102,15 @@ PKG_PYTHON_SETUPTOOLS_INSTALL_OPTS = \
 	--executable=/usr/bin/python \
 	--single-version-externally-managed
 
-PKG_PYTHON_SETUPTOOLS_INSTALL_TARGET_OPTS = \
+PKG_PYTHON_SETUPTOOLS_INSTALL_TARGET_CMD = \
+	$(PKG_PYTHON_SETUPTOOLS_CMD) \
+	install --no-compile \
 	$(PKG_PYTHON_SETUPTOOLS_INSTALL_OPTS) \
 	--root=$(TARGET_DIR)
 
-PKG_PYTHON_SETUPTOOLS_INSTALL_STAGING_OPTS = \
+PKG_PYTHON_SETUPTOOLS_INSTALL_STAGING_CMD = \
+	$(PKG_PYTHON_SETUPTOOLS_CMD) \
+	install \
 	$(PKG_PYTHON_SETUPTOOLS_INSTALL_OPTS) \
 	--root=$(STAGING_DIR)
 
@@ -114,7 +121,9 @@ HOST_PKG_PYTHON_SETUPTOOLS_ENV = \
 HOST_PKG_PYTHON_SETUPTOOLS_BUILD_CMD = \
 	$(PKG_PYTHON_SETUPTOOLS_CMD) build
 
-HOST_PKG_PYTHON_SETUPTOOLS_INSTALL_OPTS = \
+HOST_PKG_PYTHON_SETUPTOOLS_INSTALL_CMD = \
+	$(PKG_PYTHON_SETUPTOOLS_CMD) \
+	install \
 	--prefix=$(HOST_DIR) \
 	--root=/ \
 	--single-version-externally-managed
@@ -128,6 +137,12 @@ PKG_PYTHON_SETUPTOOLS_RUST_ENV = \
 PKG_PYTHON_SETUPTOOLS_RUST_BUILD_CMD = \
 	$(PKG_PYTHON_SETUPTOOLS_BUILD_CMD)
 
+PKG_PYTHON_SETUPTOOLS_RUST_INSTALL_TARGET_CMD = \
+	$(PKG_PYTHON_SETUPTOOLS_INSTALL_TARGET_CMD)
+
+PKG_PYTHON_SETUPTOOLS_RUST_INSTALL_STAGING_CMD = \
+	$(PKG_PYTHON_SETUPTOOLS_INSTALL_STAGING_CMD)
+
 # Host setuptools-rust-based packages
 HOST_PKG_PYTHON_SETUPTOOLS_RUST_ENV = \
 	$(HOST_PKG_PYTHON_SETUPTOOLS_ENV) \
@@ -137,6 +152,9 @@ HOST_PKG_PYTHON_SETUPTOOLS_RUST_ENV = \
 HOST_PKG_PYTHON_SETUPTOOLS_RUST_BUILD_CMD = \
 	$(HOST_PKG_PYTHON_SETUPTOOLS_BUILD_CMD)
 
+HOST_PKG_PYTHON_SETUPTOOLS_RUST_INSTALL_CMD = \
+	$(HOST_PKG_PYTHON_SETUPTOOLS_INSTALL_CMD)
+
 # Target pep517-based packages
 PKG_PYTHON_PEP517_ENV = \
 	$(PKG_PYTHON_ENV)
@@ -148,14 +166,18 @@ PKG_PYTHON_PEP517_INSTALL_OPTS = \
 	--interpreter=/usr/bin/python \
 	--script-kind=posix
 
-PKG_PYTHON_PEP517_INSTALL_TARGET_OPTS = \
+PKG_PYTHON_PEP517_INSTALL_TARGET_CMD = \
+	$(TOPDIR)/support/scripts/pyinstaller.py \
+	dist/* \
 	$(PKG_PYTHON_PEP517_INSTALL_OPTS) \
 	--purelib=$(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)/site-packages \
 	--headers=$(TARGET_DIR)/usr/include/python$(PYTHON3_VERSION_MAJOR) \
 	--scripts=$(TARGET_DIR)/usr/bin \
 	--data=$(TARGET_DIR)/usr
 
-PKG_PYTHON_PEP517_INSTALL_STAGING_OPTS = \
+PKG_PYTHON_PEP517_INSTALL_STAGING_CMD = \
+	$(TOPDIR)/support/scripts/pyinstaller.py \
+	dist/* \
 	$(PKG_PYTHON_PEP517_INSTALL_OPTS) \
 	--purelib=$(STAGING_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)/site-packages \
 	--headers=$(STAGING_DIR)/usr/include/python$(PYTHON3_VERSION_MAJOR) \
@@ -169,7 +191,9 @@ HOST_PKG_PYTHON_PEP517_ENV = \
 HOST_PKG_PYTHON_PEP517_BUILD_CMD = \
 	-m build -n -w
 
-HOST_PKG_PYTHON_PEP517_INSTALL_OPTS = \
+HOST_PKG_PYTHON_PEP517_INSTALL_CMD = \
+	$(TOPDIR)/support/scripts/pyinstaller.py \
+	dist/* \
 	--interpreter=$(HOST_DIR)/bin/python \
 	--script-kind=posix \
 	--purelib=$(HOST_DIR)/lib/python$(PYTHON3_VERSION_MAJOR)/site-packages \
@@ -184,6 +208,12 @@ PKG_PYTHON_FLIT_ENV = \
 PKG_PYTHON_FLIT_BUILD_CMD = \
 	$(PKG_PYTHON_PEP517_BUILD_CMD)
 
+PKG_PYTHON_FLIT_INSTALL_TARGET_CMD = \
+	$(PKG_PYTHON_PEP517_INSTALL_TARGET_CMD)
+
+PKG_PYTHON_FLIT_INSTALL_STAGING_CMD = \
+	$(PKG_PYTHON_PEP517_INSTALL_STAGING_CMD)
+
 # Host flit packages
 HOST_PKG_PYTHON_FLIT_ENV = \
 	$(HOST_PKG_PYTHON_PEP517_ENV)
@@ -191,6 +221,9 @@ HOST_PKG_PYTHON_FLIT_ENV = \
 HOST_PKG_PYTHON_FLIT_BUILD_CMD = \
 	$(HOST_PKG_PYTHON_PEP517_BUILD_CMD)
 
+HOST_PKG_PYTHON_FLIT_INSTALL_CMD = \
+	$(HOST_PKG_PYTHON_PEP517_INSTALL_CMD)
+
 # Host flit-bootstrap packages
 HOST_PKG_PYTHON_FLIT_BOOTSTRAP_ENV = \
 	$(HOST_PKG_PYTHON_PEP517_ENV)
@@ -198,6 +231,9 @@ HOST_PKG_PYTHON_FLIT_BOOTSTRAP_ENV = \
 HOST_PKG_PYTHON_FLIT_BOOTSTRAP_BUILD_CMD = \
 	-m flit_core.wheel
 
+HOST_PKG_PYTHON_FLIT_BOOTSTRAP_INSTALL_CMD = \
+	$(HOST_PKG_PYTHON_PEP517_INSTALL_CMD)
+
 # Target maturin packages
 PKG_PYTHON_MATURIN_ENV = \
 	$(PKG_PYTHON_PEP517_ENV) \
@@ -207,6 +243,12 @@ PKG_PYTHON_MATURIN_ENV = \
 PKG_PYTHON_MATURIN_BUILD_CMD = \
 	$(PKG_PYTHON_PEP517_BUILD_CMD)
 
+PKG_PYTHON_MATURIN_INSTALL_TARGET_CMD = \
+	$(PKG_PYTHON_PEP517_INSTALL_TARGET_CMD)
+
+PKG_PYTHON_MATURIN_INSTALL_STAGING_CMD = \
+	$(PKG_PYTHON_PEP517_INSTALL_STAGING_CMD)
+
 # Host maturin packages
 HOST_PKG_PYTHON_MATURIN_ENV = \
 	$(HOST_PKG_PYTHON_PEP517_ENV) \
@@ -216,6 +258,9 @@ HOST_PKG_PYTHON_MATURIN_ENV = \
 HOST_PKG_PYTHON_MATURIN_BUILD_CMD = \
 	$(HOST_PKG_PYTHON_PEP517_BUILD_CMD)
 
+PKG_PYTHON_MATURIN_INSTALL_CMD = \
+	$(PKG_PYTHON_PEP517_INSTALL_CMD)
+
 ################################################################################
 # inner-python-package -- defines how the configuration, compilation
 # and installation of a Python package should be done, implements a
@@ -242,37 +287,11 @@ endif
 
 $(2)_SETUP_TYPE_UPPER = $$(call UPPERCASE,$$($(2)_SETUP_TYPE))
 
-# Distutils
-ifeq ($$($(2)_SETUP_TYPE),distutils)
-ifeq ($(4),target)
-$(2)_BASE_INSTALL_TARGET_CMD  = setup.py install --no-compile $$(PKG_PYTHON_DISTUTILS_INSTALL_TARGET_OPTS)
-$(2)_BASE_INSTALL_STAGING_CMD = setup.py install $$(PKG_PYTHON_DISTUTILS_INSTALL_STAGING_OPTS)
-else
-$(2)_BASE_INSTALL_CMD = setup.py install $$(HOST_PKG_PYTHON_DISTUTILS_INSTALL_OPTS)
-endif
-# Setuptools
-else ifneq ($$(filter setuptools setuptools-rust,$$($(2)_SETUP_TYPE)),)
-ifeq ($(4),target)
-$(2)_BASE_INSTALL_TARGET_CMD = $$(PKG_PYTHON_SETUPTOOLS_CMD) install --no-compile $$(PKG_PYTHON_SETUPTOOLS_INSTALL_TARGET_OPTS)
-$(2)_BASE_INSTALL_STAGING_CMD = $$(PKG_PYTHON_SETUPTOOLS_CMD) install $$(PKG_PYTHON_SETUPTOOLS_INSTALL_STAGING_OPTS)
-else
-$(2)_BASE_INSTALL_CMD = $$(PKG_PYTHON_SETUPTOOLS_CMD) install $$(HOST_PKG_PYTHON_SETUPTOOLS_INSTALL_OPTS)
-endif
-else ifneq ($$(filter flit maturin pep517,$$($(2)_SETUP_TYPE)),)
-ifeq ($(4),target)
-$(2)_BASE_INSTALL_TARGET_CMD = $(TOPDIR)/support/scripts/pyinstaller.py dist/* $$(PKG_PYTHON_PEP517_INSTALL_TARGET_OPTS)
-$(2)_BASE_INSTALL_STAGING_CMD = $(TOPDIR)/support/scripts/pyinstaller.py dist/* $$(PKG_PYTHON_PEP517_INSTALL_STAGING_OPTS)
-else
-$(2)_BASE_INSTALL_CMD = $(TOPDIR)/support/scripts/pyinstaller.py dist/* $$(HOST_PKG_PYTHON_PEP517_INSTALL_OPTS)
+ifneq ($$(filter-out distutils setuptools setuptools-rust pep517 flit flit-bootstrap maturin,$$($(2)_SETUP_TYPE)),)
+$$(error "Invalid $(2)_SETUP_TYPE. Valid options are 'distutils', 'maturin', 'setuptools', 'setuptools-rust', 'pep517' or 'flit'.")
 endif
-else ifeq ($$($(2)_SETUP_TYPE),flit-bootstrap)
-ifeq ($(4),target)
+ifeq ($(4)-$$($(2)_SETUP_TYPE),target-flit-bootstrap)
 $$(error flit-bootstrap setup type only supported for host packages)
-else
-$(2)_BASE_INSTALL_CMD ?= $(TOPDIR)/support/scripts/pyinstaller.py dist/* $$(HOST_PKG_PYTHON_PEP517_INSTALL_OPTS)
-endif
-else
-$$(error "Invalid $(2)_SETUP_TYPE. Valid options are 'distutils', 'maturin', 'setuptools', 'setuptools-rust', 'pep517' or 'flit'.")
 endif
 
 # We need to vendor the Cargo crates at download time for pyo3 based
@@ -368,7 +387,7 @@ define $(2)_INSTALL_TARGET_CMDS
 		$$(PKG_PYTHON_$$($$(PKG)_SETUP_TYPE_UPPER)_ENV) \
 		$$($$(PKG)_ENV) \
 		$$(HOST_DIR)/bin/python3 \
-		$$($$(PKG)_BASE_INSTALL_TARGET_CMD) \
+		$$(PKG_PYTHON_$$($$(PKG)_SETUP_TYPE_UPPER)_INSTALL_TARGET_CMD) \
 		$$($$(PKG)_INSTALL_TARGET_OPTS))
 endef
 endif
@@ -383,7 +402,7 @@ define $(2)_INSTALL_STAGING_CMDS
 		$$(PKG_PYTHON_$$($$(PKG)_SETUP_TYPE_UPPER)_ENV) \
 		$$($$(PKG)_ENV) \
 		$$(HOST_DIR)/bin/python3 \
-		$$($$(PKG)_BASE_INSTALL_STAGING_CMD) \
+		$$(PKG_PYTHON_$$($$(PKG)_SETUP_TYPE_UPPER)_INSTALL_STAGING_CMD) \
 		$$($$(PKG)_INSTALL_STAGING_OPTS))
 endef
 endif
@@ -415,7 +434,7 @@ define $(2)_INSTALL_CMDS
 		$$(HOST_PKG_PYTHON_$$($$(PKG)_SETUP_TYPE_UPPER)_ENV) \
 		$$($$(PKG)_ENV) \
 		$$(HOST_DIR)/bin/python3 \
-		$$($$(PKG)_BASE_INSTALL_CMD) \
+		$$(HOST_PKG_PYTHON_$$($$(PKG)_SETUP_TYPE_UPPER)_INSTALL_CMD) \
 		$$($$(PKG)_INSTALL_OPTS))
 endef
 endif
Signature · 6 lines
2.41.0

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#13 lore raw

PATCH 10/10 docs/manual: remove references to PKG_PYTHON_*_OPTS

In reply to Arnout Vandecappelle via buildroot

These variables were removed. In addition, the text describing them wasn't terribly useful. Just remove the sentences describing them.

---
 docs/manual/adding-packages-python.adoc | 14 +-------------
 1 file changed, 1 insertion(+), 13 deletions(-)
docs/manual/adding-packages-python.adoc +1 -13
index 500967f235..33dbfc30a5 100644
@@ -135,25 +135,13 @@ therefore only use a few of them, or none.
   makes sense to use for distutils/setuptools based packages as
   flit/pep517 based packages do not pass these options to a +setup.py+
   script but instead pass them to +support/scripts/pyinstaller.py+.
-  For target distutils packages, the +PKG_PYTHON_DISTUTILS_BUILD_OPTS+
-  options are already passed automatically by the infrastructure.
 
 * +PYTHON_FOO_INSTALL_TARGET_OPTS+, +PYTHON_FOO_INSTALL_STAGING_OPTS+,
   +HOST_PYTHON_FOO_INSTALL_OPTS+ to specify additional options to pass
   to the Python +setup.py+ script (for distutils/setuptools packages)
   or +support/scripts/pyinstaller.py+ (for flit/pep517 packages) during
   the target installation step, the staging installation step or the
-  host installation, respectively. Note that the infrastructure is
-  automatically passing some options, defined in
-  +PKG_PYTHON_DISTUTILS_INSTALL_TARGET_OPTS+ or
-  +PKG_PYTHON_DISTUTILS_INSTALL_STAGING_OPTS+ (for target distutils
-  packages), +HOST_PKG_PYTHON_DISTUTILS_INSTALL_OPTS+ (for host
-  distutils packages), +PKG_PYTHON_SETUPTOOLS_INSTALL_TARGET_OPTS+ or
-  +PKG_PYTHON_SETUPTOOLS_INSTALL_STAGING_OPTS+ (for target setuptools
-  packages), +HOST_PKG_PYTHON_SETUPTOOLS_INSTALL_OPTS+ (for host
-  setuptools packages) and +PKG_PYTHON_PEP517_INSTALL_TARGET_OPTS+ or
-  +PKG_PYTHON_PEP517_INSTALL_STAGING_OPTS+ (for target flit/pep517
-  packages).
+  host installation, respectively.
 
 With the Python infrastructure, all the steps required to build and
 install the packages are already defined, and they generally work well
Signature · 6 lines
2.41.0

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#14 lore raw
In reply to Arnout Vandecappelle via buildroot
Quoted 6 lines · Arnout Vandecappelle

Most of the python-package infrastructure consists of a big conditional tree that sets various variables based on the package's setup type. Initially, this was quite OK, but since we have 7 different setup types now, some of which share some variables with others, it's becoming quite complicated and hard to read.

It might be a good idea to apply my setuptools pep517 patch first which simplifies things a bit by largely combining the setuptools setup type with pep517 builds.

https://patchwork.ozlabs.org/project/buildroot/patch/[email protected]/

We can probably drop distutils setup type as well as we should be able to instead just use setuptools for any packages using that.

Quoted 67 lines

This patch series refactors it so that the inner-python-package doesn't dispatch the setup type through a conditional tree, but instead does it with variable indirection, i.e. by using variables like
$(PKG_PYTHON_$($(PKG)_SETUP_TYPE_UPPER)_ENV)

The rist two patches are simple cleanups, removing variables that are not really needed.

The third patch is a preparatory one that splits the build commands for target and host builds. This is necessary because we need to use different variables for the two, i.e. HOST_PKG_PYTHON_* for host build.

The fourth and fifth patch each replace one variable from the conditional tree with an indirectly addressed one.

The following three patches are needed because the ninth patch removes the PKG_PYTHON_*_OPTS variables, which were used in 3 packages. It is in fact not strictly needed to remove those variables, but IMHO they don't add sufficient value to keep them. I think it's better to handle the few special cases explicitly.

The ninth patch replaces the remaining variables from the conditional tree with indirectly addressed ones. The conditional tree is now empty, and the error handling that was in there is made more explicit.

The tenth patch edits the documentation to remove the references to the PKG_PYTHON_*_OPTS variables that were removed in the previous patch.

This series adds lines rather than removing lines. That is because things are made more explicit, introducing per-setup-type variables where previously several setup types were (partially) reusing the pep517 variables. There are also some additional lines because of more line splitting.

To test this series, I built all the python packages with one specific toolchain configuration, and I ran all runtime tests for python packages. One package failed to build: host-python-sip. It also fails on master. For the runtime tests, 14 of them failed, all of them also fail on master.

The following changes since commit 7906272c39744e26ed73028725787aa3a4441c54:

package/python-rtoml: migrate to setuptools-rust infrastructure (2023-09-29 22:02:31 +0200)

are available in the Git repository at:

[email protected]:arnout/buildroot.git pkg-python-refactor-variables

for you to fetch changes up to 89b33e004fc13e22a9c0bdcafcee245a97d2dd51:

docs/manual: remove references to PKG_PYTHON_*_OPTS (2023-09-30 15:18:48 +0200)

----------------------------------------------------------------
Arnout Vandecappelle (Essensium/Mind) (10):
package/pkg-python.mk: remove $(2)_PYTHON_INTERPRETER variable package/pkg-python.mk: remove _BASE_BUILD_OPTS variable package/pkg-python.mk: split the commands in a target and host section package/pkg-python.mk: replace $(_BASE_ENV) with $($(SETUP_TYPE)_ENV) package/pkg-python.mk: replace $(_BASE_BUILD_CMD) with $($(SETUP_TYPE)_BUILD_CMD) package/python-flit-core: instantiate _INSTALL_CMDS
package/jailhouse: expand PKG_PYTHON_SETUPTOOLS_INSTALL_TARGET_OPTS package/i2c-tools: expand PKG_PYTHON_SETUPTOOLS_INSTALL_TARGET_OPTS package/pkg-python.mk: replace $(_BASE_INSTALL*_CMD) with $($(SETUP_TYPE)_INSTALL*_CMD) docs/manual: remove references to PKG_PYTHON_*_OPTS

Quoted 9 lines
 docs/manual/adding-packages-python.txt       |  14 +-------
 package/i2c-tools/i2c-tools.mk               |   6 ++--
 package/jailhouse/jailhouse.mk               |   7 +++-
 package/pkg-python.mk                        | 256 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------------------------
 package/python-flit-core/python-flit-core.mk |   9 +++--
 5 files changed, 173 insertions(+), 119 deletions(-)

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

#15 lore raw
Quoted 8 lines · James Hilliard
Quoted 6 lines · Arnout Vandecappelle

Most of the python-package infrastructure consists of a big conditional tree that sets various variables based on the package's setup type. Initially, this was quite OK, but since we have 7 different setup types now, some of which share some variables with others, it's becoming quite complicated and hard to read.

Quoted 5 lines

It might be a good idea to apply my setuptools pep517 patch first which simplifies things a bit by largely combining the setuptools setup type with pep517 builds.

https://patchwork.ozlabs.org/project/buildroot/patch/[email protected]/

Yeah, my series was already finished when you sent that, but the testing took
more than 24 hours...

The two will conflict with each other, obviously, but I think they can be
applied in either order.

Quoted 2 lines

We can probably drop distutils setup type as well as we should be able to instead just use setuptools for any packages using that.

That's a bit a longer-term project.

That said, assuming that distutils is gone, do you think the current condition
tree would be simpler than the indirect variables that my series ends up with?

Regards,
Arnout

[snip]
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

#16 lore raw
Quoted 16 lines · Arnout Vandecappelle
Quoted 12 lines · James Hilliard
Quoted 6 lines · Arnout Vandecappelle

Most of the python-package infrastructure consists of a big conditional tree that sets various variables based on the package's setup type. Initially, this was quite OK, but since we have 7 different setup types now, some of which share some variables with others, it's becoming quite complicated and hard to read.

It might be a good idea to apply my setuptools pep517 patch first which simplifies things a bit by largely combining the setuptools setup type with pep517 builds.

Quoted 7 lines
Quoted 1 line

https://patchwork.ozlabs.org/project/buildroot/patch/[email protected]/

Yeah, my series was already finished when you sent that, but the testing took
more than 24 hours...

The two will conflict with each other, obviously, but I think they can be
applied in either order.

True, however the complexity reduction of the pep517 migration should also simplify your series a bit and make it a lot easier to review.

Quoted 6 lines
Quoted 4 lines

We can probably drop distutils setup type as well as we should be able to instead just use setuptools for any packages using that.

That's a bit a longer-term project.

I only see 4 packages still using distutils still so assuming they work ok under setuptools this may actually be quite simple.

I'll try and test if those build under setuptools and migrate them if they do.

Quoted 3 lines

That said, assuming that distutils is gone, do you think the current condition
tree would be simpler than the indirect variables that my series ends up with?

It's a little hard to tell, ultimately we're only going to have pep517 style builds for
everything plus flit-core-boostrap for bootstrapping our pep517 toolchain since the entire python ecosystem appears to have moved to pep517 packaging.

Quoted 5 lines

Regards,
Arnout

[snip]

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

#17 lore raw
Quoted 6 lines · James Hilliard
Quoted 4 lines · Arnout Vandecappelle
Quoted 3 lines

We can probably drop distutils setup type as well as we should be able to instead just use setuptools for any packages using that.

Quoted 7 lines
Quoted 1 line

That's a bit a longer-term project.

I only see 4 packages still using distutils still so assuming they work ok under setuptools this may actually be quite simple.

I'll try and test if those build under setuptools and migrate them if they do.

Yeah, they all seem to build fine under setuptools, I sent patches migrating those
so we should be good to remove our distutils infrastructure any time after those are merged I think.

https://patchwork.ozlabs.org/project/buildroot/patch/[email protected]/
https://patchwork.ozlabs.org/project/buildroot/patch/[email protected]/
https://patchwork.ozlabs.org/project/buildroot/patch/[email protected]/
https://patchwork.ozlabs.org/project/buildroot/patch/[email protected]/
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

#18 lore raw
In reply to Arnout Vandecappelle via buildroot

Arnout, All,

On 2023-10-01 00:16 +0200, Arnout Vandecappelle via buildroot spake thusly:

Quoted 10 lines

Most of the python-package infrastructure consists of a big conditional tree that sets various variables based on the package's setup type. Initially, this was quite OK, but since we have 7 different setup types now, some of which share some variables with others, it's becoming quite complicated and hard to read.

This patch series refactors it so that the inner-python-package doesn't dispatch the setup type through a conditional tree, but instead does it with variable indirection, i.e. by using variables like
$(PKG_PYTHON_$($(PKG)_SETUP_TYPE_UPPER)_ENV)

I've applied the whole series to next, now, thanks!

When I started looking at:

    package/pkg-python.mk: replace $(_BASE_ENV) with $($(SETUP_TYPE)_ENV)

I was not very happy with it, because it moves the variable part of the variable name in the middle, while I believe it is more customary to have it at the end.

Also, I did not initially see why we needed to go with UPPERCASE, especially as dot and dash are perfectly legit in variable names.

So I started changing your patch to use:

    FOO_ENV_$($(PKG)_SETUP_TYPE)

And then I did the same to the other patches.

Until I realised that those variables were used in specific packages, and there it looked misplaced to use such a naming.

Also, this would have also meant we'd have to renamed the remaining variables, like _OPTS and co for consistency, so I backpedaled on it and restored your patches as you initially sent them.

Still, I reworked the jailhouse package slightly, to move the odd condition-in-_CMDS to conditionally defined macros.

So, bottom of it: whole series applied to next.

Thanks a lot for this immensely valuable rework!

I think we could even go a bit further and drop the conditional block that defines the dependencies...

Any taker? ;-)

Regards,
Yann E. MORIN.

Quoted 74 lines

The rist two patches are simple cleanups, removing variables that are not really needed.

The third patch is a preparatory one that splits the build commands for target and host builds. This is necessary because we need to use different variables for the two, i.e. HOST_PKG_PYTHON_* for host build.

The fourth and fifth patch each replace one variable from the conditional tree with an indirectly addressed one.

The following three patches are needed because the ninth patch removes the PKG_PYTHON_*_OPTS variables, which were used in 3 packages. It is in fact not strictly needed to remove those variables, but IMHO they don't add sufficient value to keep them. I think it's better to handle the few special cases explicitly.

The ninth patch replaces the remaining variables from the conditional tree with indirectly addressed ones. The conditional tree is now empty, and the error handling that was in there is made more explicit.

The tenth patch edits the documentation to remove the references to the PKG_PYTHON_*_OPTS variables that were removed in the previous patch.

This series adds lines rather than removing lines. That is because things are made more explicit, introducing per-setup-type variables where previously several setup types were (partially) reusing the pep517 variables. There are also some additional lines because of more line splitting.

To test this series, I built all the python packages with one specific toolchain configuration, and I ran all runtime tests for python packages. One package failed to build: host-python-sip. It also fails on master. For the runtime tests, 14 of them failed, all of them also fail on master.

The following changes since commit 7906272c39744e26ed73028725787aa3a4441c54:

package/python-rtoml: migrate to setuptools-rust infrastructure (2023-09-29 22:02:31 +0200)

are available in the Git repository at:

[email protected]:arnout/buildroot.git pkg-python-refactor-variables

for you to fetch changes up to 89b33e004fc13e22a9c0bdcafcee245a97d2dd51:

docs/manual: remove references to PKG_PYTHON_*_OPTS (2023-09-30 15:18:48 +0200)

----------------------------------------------------------------
Arnout Vandecappelle (Essensium/Mind) (10):
package/pkg-python.mk: remove $(2)_PYTHON_INTERPRETER variable package/pkg-python.mk: remove _BASE_BUILD_OPTS variable package/pkg-python.mk: split the commands in a target and host section package/pkg-python.mk: replace $(_BASE_ENV) with $($(SETUP_TYPE)_ENV) package/pkg-python.mk: replace $(_BASE_BUILD_CMD) with $($(SETUP_TYPE)_BUILD_CMD) package/python-flit-core: instantiate _INSTALL_CMDS
package/jailhouse: expand PKG_PYTHON_SETUPTOOLS_INSTALL_TARGET_OPTS package/i2c-tools: expand PKG_PYTHON_SETUPTOOLS_INSTALL_TARGET_OPTS package/pkg-python.mk: replace $(_BASE_INSTALL*_CMD) with $($(SETUP_TYPE)_INSTALL*_CMD) docs/manual: remove references to PKG_PYTHON_*_OPTS

 docs/manual/adding-packages-python.txt       |  14 +-------
 package/i2c-tools/i2c-tools.mk               |   6 ++--
 package/jailhouse/jailhouse.mk               |   7 +++-
 package/pkg-python.mk                        | 256 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------------------------
 package/python-flit-core/python-flit-core.mk |   9 +++--
 5 files changed, 173 insertions(+), 119 deletions(-)

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

Signature · 10 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 561 099 427 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#19 lore raw
Quoted 44 lines · Yann E. MORIN

Arnout, All,

On 2023-10-01 00:16 +0200, Arnout Vandecappelle via buildroot spake thusly:

Quoted 10 lines

Most of the python-package infrastructure consists of a big conditional tree that sets various variables based on the package's setup type. Initially, this was quite OK, but since we have 7 different setup types now, some of which share some variables with others, it's becoming quite complicated and hard to read.

This patch series refactors it so that the inner-python-package doesn't dispatch the setup type through a conditional tree, but instead does it with variable indirection, i.e. by using variables like
$(PKG_PYTHON_$($(PKG)_SETUP_TYPE_UPPER)_ENV)

I've applied the whole series to next, now, thanks!

When I started looking at:

    package/pkg-python.mk: replace $(_BASE_ENV) with $($(SETUP_TYPE)_ENV)

I was not very happy with it, because it moves the variable part of the variable name in the middle, while I believe it is more customary to have it at the end.

Also, I did not initially see why we needed to go with UPPERCASE, especially as dot and dash are perfectly legit in variable names.

So I started changing your patch to use:

    FOO_ENV_$($(PKG)_SETUP_TYPE)

And then I did the same to the other patches.

Until I realised that those variables were used in specific packages, and there it looked misplaced to use such a naming.

Also, this would have also meant we'd have to renamed the remaining variables, like _OPTS and co for consistency, so I backpedaled on it and restored your patches as you initially sent them.

Still, I reworked the jailhouse package slightly, to move the odd condition-in-_CMDS to conditionally defined macros.

Quoted 8 lines

So, bottom of it: whole series applied to next.

Thanks a lot for this immensely valuable rework!

I think we could even go a bit further and drop the conditional block that defines the dependencies...

Any taker? ;-)

Which conditional dependencies block are you referring to?

I rebased my setuptools pep517 migration, once that's merged and we've removed distutils support there's a good bit of refactoring we can do to simplify things as everything will then use pep517 build/install commands.

https://patchwork.ozlabs.org/project/buildroot/patch/[email protected]/

Quoted 79 lines

Regards,
Yann E. MORIN.

Quoted 70 lines

The rist two patches are simple cleanups, removing variables that are not really needed.

The third patch is a preparatory one that splits the build commands for target and host builds. This is necessary because we need to use different variables for the two, i.e. HOST_PKG_PYTHON_* for host build.

The fourth and fifth patch each replace one variable from the conditional tree with an indirectly addressed one.

The following three patches are needed because the ninth patch removes the PKG_PYTHON_*_OPTS variables, which were used in 3 packages. It is in fact not strictly needed to remove those variables, but IMHO they don't add sufficient value to keep them. I think it's better to handle the few special cases explicitly.

The ninth patch replaces the remaining variables from the conditional tree with indirectly addressed ones. The conditional tree is now empty, and the error handling that was in there is made more explicit.

The tenth patch edits the documentation to remove the references to the PKG_PYTHON_*_OPTS variables that were removed in the previous patch.

This series adds lines rather than removing lines. That is because things are made more explicit, introducing per-setup-type variables where previously several setup types were (partially) reusing the pep517 variables. There are also some additional lines because of more line splitting.

To test this series, I built all the python packages with one specific toolchain configuration, and I ran all runtime tests for python packages. One package failed to build: host-python-sip. It also fails on master. For the runtime tests, 14 of them failed, all of them also fail on master.

The following changes since commit 7906272c39744e26ed73028725787aa3a4441c54:

package/python-rtoml: migrate to setuptools-rust infrastructure (2023-09-29 22:02:31 +0200)

are available in the Git repository at:

[email protected]:arnout/buildroot.git pkg-python-refactor-variables

for you to fetch changes up to 89b33e004fc13e22a9c0bdcafcee245a97d2dd51:

docs/manual: remove references to PKG_PYTHON_*_OPTS (2023-09-30 15:18:48 +0200)

----------------------------------------------------------------
Arnout Vandecappelle (Essensium/Mind) (10):
package/pkg-python.mk: remove $(2)_PYTHON_INTERPRETER variable package/pkg-python.mk: remove _BASE_BUILD_OPTS variable package/pkg-python.mk: split the commands in a target and host section package/pkg-python.mk: replace $(_BASE_ENV) with $($(SETUP_TYPE)_ENV) package/pkg-python.mk: replace $(_BASE_BUILD_CMD) with $($(SETUP_TYPE)_BUILD_CMD) package/python-flit-core: instantiate _INSTALL_CMDS
package/jailhouse: expand PKG_PYTHON_SETUPTOOLS_INSTALL_TARGET_OPTS package/i2c-tools: expand PKG_PYTHON_SETUPTOOLS_INSTALL_TARGET_OPTS package/pkg-python.mk: replace $(_BASE_INSTALL*_CMD) with $($(SETUP_TYPE)_INSTALL*_CMD) docs/manual: remove references to PKG_PYTHON_*_OPTS

 docs/manual/adding-packages-python.txt       |  14 +-------
 package/i2c-tools/i2c-tools.mk               |   6 ++--
 package/jailhouse/jailhouse.mk               |   7 +++-
 package/pkg-python.mk                        | 256 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------------------------
 package/python-flit-core/python-flit-core.mk |   9 +++--
 5 files changed, 173 insertions(+), 119 deletions(-)
Quoted 4 lines

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

Quoted 7 lines

--
.-----------------.--------------------.------------------.--------------------.

|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 561 099 427 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |

'------------------------------^-------^------------------^--------------------'

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

#20 lore raw

James, All,

On 2023-11-25 18:40 -0700, James Hilliard spake thusly:

Quoted 4 lines · Yann E. MORIN
Quoted 2 lines

I think we could even go a bit further and drop the conditional block that defines the dependencies...

Which conditional dependencies block are you referring to?

This one:

https://gitlab.com/buildroot.org/buildroot/-/blob/next/package/pkg-python.mk#L333

Quoted 5 lines

I rebased my setuptools pep517 migration, once that's merged and we've removed distutils support there's a good bit of refactoring we can do to simplify things as everything will then use pep517 build/install commands.

https://patchwork.ozlabs.org/project/buildroot/patch/[email protected]/

As far as I can see, that patch does not refactor the dependencies in a way similar to how the other variables have been refactored, i.e. something like:

PKG_PYTHON_SETUPTOOLS_DEPENDENCIES = host-python-setuptools

PKG_PYTHON_SETUPTOOLS_RUST_DEPENDENCIES = host-python-setuptools host-python-setuptools-rust

and so on (and for the HOST_ variants as well), and then:

    $(2)_DEPENDENCIES += $$(PKG_PYTHON_$$($$(PKG)_SETUP_TYPE_UPPER)_DEPENDENCIES)

which, as I suggested, would do with the dependency comnditional block basically the same as the previous patches have done for the build commands.

And if we're smart, we can go even further and handle all the setup-type-based variables similarly:

    PKG_PYTHON_SETUPTOOLS_RUST_DL_ENV = $$(PKG_CARGO_ENV)

    PKG_PYTHON_MATURIN_RUST_DL_ENV = $$(PKG_CARGO_ENV)

and then:

    $(2)_DL_ENV += $$(PKG_PYTHON_$$($$(PKG)_SETUP_TYPE_UPPER)_DL_ENV)

It is not that the remaining conditional block are as unwieldy as the previos one about build sommands, but it would be goos to have some consistency in the way the various setup-types are handled.

Regards,
Yann E. MORIN.

Quoted 86 lines
Quoted 86 lines

Regards,
Yann E. MORIN.

Quoted 70 lines

The rist two patches are simple cleanups, removing variables that are not really needed.

The third patch is a preparatory one that splits the build commands for target and host builds. This is necessary because we need to use different variables for the two, i.e. HOST_PKG_PYTHON_* for host build.

The fourth and fifth patch each replace one variable from the conditional tree with an indirectly addressed one.

The following three patches are needed because the ninth patch removes the PKG_PYTHON_*_OPTS variables, which were used in 3 packages. It is in fact not strictly needed to remove those variables, but IMHO they don't add sufficient value to keep them. I think it's better to handle the few special cases explicitly.

The ninth patch replaces the remaining variables from the conditional tree with indirectly addressed ones. The conditional tree is now empty, and the error handling that was in there is made more explicit.

The tenth patch edits the documentation to remove the references to the PKG_PYTHON_*_OPTS variables that were removed in the previous patch.

This series adds lines rather than removing lines. That is because things are made more explicit, introducing per-setup-type variables where previously several setup types were (partially) reusing the pep517 variables. There are also some additional lines because of more line splitting.

To test this series, I built all the python packages with one specific toolchain configuration, and I ran all runtime tests for python packages. One package failed to build: host-python-sip. It also fails on master. For the runtime tests, 14 of them failed, all of them also fail on master.

The following changes since commit 7906272c39744e26ed73028725787aa3a4441c54:

package/python-rtoml: migrate to setuptools-rust infrastructure (2023-09-29 22:02:31 +0200)

are available in the Git repository at:

[email protected]:arnout/buildroot.git pkg-python-refactor-variables

for you to fetch changes up to 89b33e004fc13e22a9c0bdcafcee245a97d2dd51:

docs/manual: remove references to PKG_PYTHON_*_OPTS (2023-09-30 15:18:48 +0200)

----------------------------------------------------------------
Arnout Vandecappelle (Essensium/Mind) (10):
package/pkg-python.mk: remove $(2)_PYTHON_INTERPRETER variable package/pkg-python.mk: remove _BASE_BUILD_OPTS variable package/pkg-python.mk: split the commands in a target and host section package/pkg-python.mk: replace $(_BASE_ENV) with $($(SETUP_TYPE)_ENV) package/pkg-python.mk: replace $(_BASE_BUILD_CMD) with $($(SETUP_TYPE)_BUILD_CMD) package/python-flit-core: instantiate _INSTALL_CMDS
package/jailhouse: expand PKG_PYTHON_SETUPTOOLS_INSTALL_TARGET_OPTS package/i2c-tools: expand PKG_PYTHON_SETUPTOOLS_INSTALL_TARGET_OPTS package/pkg-python.mk: replace $(_BASE_INSTALL*_CMD) with $($(SETUP_TYPE)_INSTALL*_CMD) docs/manual: remove references to PKG_PYTHON_*_OPTS

 docs/manual/adding-packages-python.txt       |  14 +-------
 package/i2c-tools/i2c-tools.mk               |   6 ++--
 package/jailhouse/jailhouse.mk               |   7 +++-
 package/pkg-python.mk                        | 256 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------------------------
 package/python-flit-core/python-flit-core.mk |   9 +++--
 5 files changed, 173 insertions(+), 119 deletions(-)
Quoted 4 lines

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

--
.-----------------.--------------------.------------------.--------------------.

|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 561 099 427 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |

'------------------------------^-------^------------------^--------------------'

Signature · 10 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 561 099 427 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#21 lore raw
Quoted 23 lines · Yann E. MORIN

James, All,

On 2023-11-25 18:40 -0700, James Hilliard spake thusly:

Quoted 4 lines · Yann E. MORIN
Quoted 2 lines

I think we could even go a bit further and drop the conditional block that defines the dependencies...

Which conditional dependencies block are you referring to?

This one:

https://gitlab.com/buildroot.org/buildroot/-/blob/next/package/pkg-python.mk#L333

Quoted 5 lines

I rebased my setuptools pep517 migration, once that's merged and we've removed distutils support there's a good bit of refactoring we can do to simplify things as everything will then use pep517 build/install commands.

https://patchwork.ozlabs.org/project/buildroot/patch/[email protected]/

As far as I can see, that patch does not refactor the dependencies in a way similar to how the other variables have been refactored, i.e. something like:

Quoted 5 lines

PKG_PYTHON_SETUPTOOLS_DEPENDENCIES = host-python-setuptools

PKG_PYTHON_SETUPTOOLS_RUST_DEPENDENCIES = host-python-setuptools host-python-setuptools-rust

and so on (and for the HOST_ variants as well), and then:

Actually HOST_ variants are not needed here since all setup type specific dependencies are the same for host and target package builds.

Quoted 2 lines
    $(2)_DEPENDENCIES += $$(PKG_PYTHON_$$($$(PKG)_SETUP_TYPE_UPPER)_DEPENDENCIES)

I had to tweak this a little to get it to work since it seems we can't use $$(PKG) here:
$(2)_DEPENDENCIES += $$(PKG_PYTHON_$$($(2)_SETUP_TYPE_UPPER)_DEPENDENCIES)

Quoted 4 lines

which, as I suggested, would do with the dependency comnditional block basically the same as the previous patches have done for the build commands.

Ok, I refactored my v6 to use this style:
https://patchwork.ozlabs.org/project/buildroot/patch/[email protected]/

Quoted 8 lines

And if we're smart, we can go even further and handle all the setup-type-based variables similarly:

    PKG_PYTHON_SETUPTOOLS_RUST_DL_ENV = $$(PKG_CARGO_ENV)

    PKG_PYTHON_MATURIN_RUST_DL_ENV = $$(PKG_CARGO_ENV)
Quoted 7 lines

and then:

    $(2)_DL_ENV += $$(PKG_PYTHON_$$($$(PKG)_SETUP_TYPE_UPPER)_DL_ENV)

It is not that the remaining conditional block are as unwieldy as the previos one about build sommands, but it would be goos to have some consistency in the way the various setup-types are handled.

I'm not sure this makes sense since all the cargo DL_ENV stuff shouldn't change based on a package being setuptools-rust vs maturin.

Quoted 91 lines

Regards,
Yann E. MORIN.

Quoted 79 lines
Quoted 79 lines

Regards,
Yann E. MORIN.

Quoted 74 lines

The rist two patches are simple cleanups, removing variables that are not really needed.

The third patch is a preparatory one that splits the build commands for target and host builds. This is necessary because we need to use different variables for the two, i.e. HOST_PKG_PYTHON_* for host build.

The fourth and fifth patch each replace one variable from the conditional tree with an indirectly addressed one.

The following three patches are needed because the ninth patch removes the PKG_PYTHON_*_OPTS variables, which were used in 3 packages. It is in fact not strictly needed to remove those variables, but IMHO they don't add sufficient value to keep them. I think it's better to handle the few special cases explicitly.

The ninth patch replaces the remaining variables from the conditional tree with indirectly addressed ones. The conditional tree is now empty, and the error handling that was in there is made more explicit.

The tenth patch edits the documentation to remove the references to the PKG_PYTHON_*_OPTS variables that were removed in the previous patch.

This series adds lines rather than removing lines. That is because things are made more explicit, introducing per-setup-type variables where previously several setup types were (partially) reusing the pep517 variables. There are also some additional lines because of more line splitting.

To test this series, I built all the python packages with one specific toolchain configuration, and I ran all runtime tests for python packages. One package failed to build: host-python-sip. It also fails on master. For the runtime tests, 14 of them failed, all of them also fail on master.

The following changes since commit 7906272c39744e26ed73028725787aa3a4441c54:

package/python-rtoml: migrate to setuptools-rust infrastructure (2023-09-29 22:02:31 +0200)

are available in the Git repository at:

[email protected]:arnout/buildroot.git pkg-python-refactor-variables

for you to fetch changes up to 89b33e004fc13e22a9c0bdcafcee245a97d2dd51:

docs/manual: remove references to PKG_PYTHON_*_OPTS (2023-09-30 15:18:48 +0200)

----------------------------------------------------------------
Arnout Vandecappelle (Essensium/Mind) (10):
package/pkg-python.mk: remove $(2)_PYTHON_INTERPRETER variable package/pkg-python.mk: remove _BASE_BUILD_OPTS variable package/pkg-python.mk: split the commands in a target and host section package/pkg-python.mk: replace $(_BASE_ENV) with $($(SETUP_TYPE)_ENV) package/pkg-python.mk: replace $(_BASE_BUILD_CMD) with $($(SETUP_TYPE)_BUILD_CMD) package/python-flit-core: instantiate _INSTALL_CMDS
package/jailhouse: expand PKG_PYTHON_SETUPTOOLS_INSTALL_TARGET_OPTS package/i2c-tools: expand PKG_PYTHON_SETUPTOOLS_INSTALL_TARGET_OPTS package/pkg-python.mk: replace $(_BASE_INSTALL*_CMD) with $($(SETUP_TYPE)_INSTALL*_CMD) docs/manual: remove references to PKG_PYTHON_*_OPTS

 docs/manual/adding-packages-python.txt       |  14 +-------
 package/i2c-tools/i2c-tools.mk               |   6 ++--
 package/jailhouse/jailhouse.mk               |   7 +++-
 package/pkg-python.mk                        | 256 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------------------------
 package/python-flit-core/python-flit-core.mk |   9 +++--
 5 files changed, 173 insertions(+), 119 deletions(-)

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

Quoted 7 lines
Quoted 7 lines

--
.-----------------.--------------------.------------------.--------------------.

|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 561 099 427 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |

'------------------------------^-------^------------------^--------------------'

Quoted 7 lines

--
.-----------------.--------------------.------------------.--------------------.

|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 561 099 427 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |

'------------------------------^-------^------------------^--------------------'

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot