Skip to contentSkip to conversation

package/python-tomli: new package

PATCH New James Hilliard 1 participant 4 messages Dec 5, 2021

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/4 package/python-tomli: new package

---
 package/Config.in                      |  1 +
 package/python-tomli/Config.in         |  7 +++++++
 package/python-tomli/python-tomli.hash |  5 +++++
 package/python-tomli/python-tomli.mk   | 16 ++++++++++++++++
 4 files changed, 29 insertions(+)
 create mode 100644 package/python-tomli/Config.in
 create mode 100644 package/python-tomli/python-tomli.hash
 create mode 100644 package/python-tomli/python-tomli.mk
package/Config.in +1 -0
index 006d3cf284..2089fc4ea6 100644
@@ -1248,6 +1248,7 @@ menu "External python modules"
 	source "package/python-tinyrpc/Config.in"
 	source "package/python-tomako/Config.in"
 	source "package/python-toml/Config.in"
+	source "package/python-tomli/Config.in"
 	source "package/python-tornado/Config.in"
 	source "package/python-tqdm/Config.in"
 	source "package/python-traitlets/Config.in"
package/python-tomli/Config.in new file +7 -0
new file mode 100644
index 0000000000..e1cecaaa36
@@ -0,0 +1,7 @@
+config BR2_PACKAGE_PYTHON_TOMLI
+	bool "python-tomli"
+	depends on BR2_PACKAGE_PYTHON3
+	help
+	  A lil' TOML parser.
+
+	  https://github.com/hukkin/tomli
package/python-tomli/python-tomli.hash new file +5 -0
new file mode 100644
index 0000000000..1a274c8a40
@@ -0,0 +1,5 @@
+# md5, sha256 from https://pypi.org/pypi/tomli/json
+md5  2ecbc7a23b8c8dc2fe96f588f88463d9  tomli-1.2.0.tar.gz
+sha256  d60e681734099207a6add7a10326bc2ddd1fdc36c1b0f547d00ef73ac63739c2  tomli-1.2.0.tar.gz
+# Locally computed sha256 checksums
+sha256  b80816b0d530b8accb4c2211783790984a6e3b61922c2b5ee92f3372ab2742fe  LICENSE
package/python-tomli/python-tomli.mk new file +16 -0
new file mode 100644
index 0000000000..4e6b023ef7
@@ -0,0 +1,16 @@
+################################################################################
+#
+# python-tomli
+#
+################################################################################
+
+PYTHON_TOMLI_VERSION = 1.2.0
+PYTHON_TOMLI_SOURCE = tomli-$(PYTHON_TOMLI_VERSION).tar.gz
+PYTHON_TOMLI_SITE = https://files.pythonhosted.org/packages/ec/38/8eccdc662c61aed187d5f5b168c18b1d2de3827976c3691e4da8be7375aa
+PYTHON_TOMLI_SETUP_TYPE = distutils
+PYTHON_TOMLI_LICENSE = MIT
+PYTHON_TOMLI_LICENSE_FILES = LICENSE
+HOST_PYTHON_TOMLI_NEEDS_HOST_PYTHON = python3
+
+$(eval $(python-package))
+$(eval $(host-python-package))
Signature · 6 lines
2.25.1

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

PATCH v2 2/4 package/pkg-python: add flit package infrastructure

Due to flit removing the setup.py generation from the default sdist releases we need to add a hook that generates them before we can do a build and install using distutils.

Installing flit/flit-core is also a bit tricky since we also need to generate setup.py's for them as well, we can do this by adding their build directories to path and calling the internal methods required to do the setup.py generation.

---
 package/pkg-python.mk                         | 30 ++++++-
 ...sion-parser-for-multiple-assignments.patch | 80 +++++++++++++++++++
 .../python-flit-core/python-flit-core.hash    |  3 +
 package/python-flit-core/python-flit-core.mk  | 34 ++++++++
 package/python-flit/python-flit.hash          |  5 ++
 package/python-flit/python-flit.mk            | 17 ++++
 6 files changed, 166 insertions(+), 3 deletions(-)
 create mode 100644 package/python-flit-core/0001-Fix-ast-version-parser-for-multiple-assignments.patch
 create mode 100644 package/python-flit-core/python-flit-core.hash
 create mode 100644 package/python-flit-core/python-flit-core.mk
 create mode 100644 package/python-flit/python-flit.hash
 create mode 100644 package/python-flit/python-flit.mk
package/pkg-python.mk +27 -3
index e6b81bdfd3..f50c33a89a 100644
@@ -120,8 +120,8 @@ ifndef $(2)_SETUP_TYPE
  endif
 endif
 
-# Distutils
-ifeq ($$($(2)_SETUP_TYPE),distutils)
+# Distutils/flit
+ifneq ($$(filter distutils flit,$$($(2)_SETUP_TYPE)),)
 ifeq ($(4),target)
 $(2)_BASE_ENV         = $$(PKG_PYTHON_DISTUTILS_ENV)
 $(2)_BASE_BUILD_TGT   = build
@@ -149,7 +149,7 @@ $(2)_BASE_BUILD_OPTS   =
 $(2)_BASE_INSTALL_OPTS = $$(HOST_PKG_PYTHON_SETUPTOOLS_INSTALL_OPTS)
 endif
 else
-$$(error "Invalid $(2)_SETUP_TYPE. Valid options are 'distutils' or 'setuptools'")
+$$(error "Invalid $(2)_SETUP_TYPE. Valid options are 'distutils', 'setuptools' or 'flit")
 endif
 
 # Target packages need both the python interpreter on the target (for
@@ -212,6 +212,10 @@ $(2)_DEPENDENCIES += $$(if $$(filter host-python-setuptools,$(1)),,host-python-s
 endif
 endif # SETUP_TYPE
 
+ifeq ($$($(2)_SETUP_TYPE),flit)
+$(2)_DEPENDENCIES += $$(if $$(filter host-python-flit host-python-flit-core,$(1)),,host-python-flit-core)
+endif # SETUP_TYPE
+
 # Python interpreter to use for building the package.
 #
 # We may want to specify the python interpreter to be used for building a
@@ -236,12 +240,32 @@ $(2)_PYTHON_INTERPRETER = $$(HOST_DIR)/bin/$$($(2)_NEEDS_HOST_PYTHON)
 endif
 endif
 
+ifeq ($$($(2)_SETUP_TYPE),flit)
+ifndef $(2)_FLIT_GENERATE_SETUP
+define $(2)_FLIT_GENERATE_SETUP
+	(cd $$($$(PKG)_BUILDDIR)/; \
+		$$($$(PKG)_BASE_ENV) $$($$(PKG)_ENV) \
+		$$($(2)_PYTHON_INTERPRETER) -c \
+		"import sys; \
+		sys.modules['requests'] = False; \
+		from flit.sdist import SdistBuilder; \
+		from pathlib import Path; \
+		cwd=Path.cwd(); \
+		setup=cwd.joinpath('setup.py').open('wb'); \
+		pyproject=cwd.joinpath('pyproject.toml'); \
+		builder=SdistBuilder.from_ini_path(pyproject); \
+		setup.write(builder.make_setup_py())")
+endef
+endif
+endif
+
 #
 # Build step. Only define it if not already defined by the package .mk
 # file.
 #
 ifndef $(2)_BUILD_CMDS
 define $(2)_BUILD_CMDS
+	$$($$(PKG)_FLIT_GENERATE_SETUP)
 	(cd $$($$(PKG)_BUILDDIR)/; \
 		$$($$(PKG)_BASE_ENV) $$($$(PKG)_ENV) \
 		$$($(2)_PYTHON_INTERPRETER) setup.py \
package/python-flit-core/0001-Fix-ast-version-parser-for-multiple-assignments.patch new file +80 -0

80 lines not on this page · raw message

package/python-flit-core/python-flit-core.hash new file +3 -0
new file mode 100644
index 0000000000..e32a05365b
@@ -0,0 +1,3 @@
+# md5, sha256 from https://pypi.org/pypi/flit_core/json
+md5  cf656ea7dac7cfa0f714e24bbadfb013  flit_core-3.5.1.tar.gz
+sha256  3083720351a6cb00e0634a1ec0e26eae7b273174c3c6c03d5b597a14203b282e  flit_core-3.5.1.tar.gz
package/python-flit-core/python-flit-core.mk new file +34 -0
new file mode 100644
index 0000000000..95a215bd39
@@ -0,0 +1,34 @@
+################################################################################
+#
+# python-flit-core
+#
+################################################################################
+
+PYTHON_FLIT_CORE_VERSION = 3.5.1
+PYTHON_FLIT_CORE_SOURCE = flit_core-$(PYTHON_FLIT_CORE_VERSION).tar.gz
+PYTHON_FLIT_CORE_SITE = https://files.pythonhosted.org/packages/7e/1e/15198966abf00e590ec95fb8aa4ba3d274897fe7b182fce2867f672f6a91
+PYTHON_FLIT_CORE_SETUP_TYPE = flit
+PYTHON_FLIT_CORE_LICENSE = BSD-3-Clause
+HOST_PYTHON_FLIT_CORE_NEEDS_HOST_PYTHON = python3
+HOST_PYTHON_FLIT_CORE_DEPENDENCIES = host-python-flit
+HOST_PYTHON_FLIT_CORE_ENV = PYTHONPATH="$(PYTHON3_PATH):$(@D)"
+
+define HOST_PYTHON_FLIT_CORE_FLIT_GENERATE_SETUP
+	cd $(HOST_PYTHON_FLIT_CORE_BUILDDIR)/; \
+		$(HOST_PYTHON_FLIT_CORE_BASE_ENV) $(HOST_PYTHON_FLIT_CORE_ENV) \
+		$(HOST_PYTHON_FLIT_CORE_PYTHON_INTERPRETER) -c \
+		"import sys; \
+		sys.modules['requests'] = False; \
+		from flit.sdist import SdistBuilder; \
+		from flit_core.build_thyself import metadata, Module; \
+		from pathlib import Path; \
+		cwd=Path.cwd(); \
+		module=Module('flit_core', cwd); \
+		reqs_by_extra={'.none': metadata.requires}; \
+		extra_files=['pyproject.toml', 'build_dists.py']; \
+		setup=cwd.joinpath('setup.py').open('wb'); \
+		builder=SdistBuilder(module, metadata, cwd, reqs_by_extra, {}, extra_files); \
+		setup.write(builder.make_setup_py())"
+endef
+
+$(eval $(host-python-package))
package/python-flit/python-flit.hash new file +5 -0
new file mode 100644
index 0000000000..e676b85090
@@ -0,0 +1,5 @@
+# md5, sha256 from https://pypi.org/pypi/flit/json
+md5  1ff1eb6e71cac6d873808fa12328a8c5  flit-3.5.1.tar.gz
+sha256  2e3b7377714483ecc54b236330d7bf3467b9f5b909b22333b50b6b4324162510  flit-3.5.1.tar.gz
+# Locally computed sha256 checksums
+sha256  35b4f1dec512e617077fd6980dbb43ef8c2887adc5d0185edb4c04da175dd816  LICENSE
package/python-flit/python-flit.mk new file +17 -0
new file mode 100644
index 0000000000..557ee7d8d9
@@ -0,0 +1,17 @@
+################################################################################
+#
+# python-flit
+#
+################################################################################
+
+PYTHON_FLIT_VERSION = 3.5.1
+PYTHON_FLIT_SOURCE = flit-$(PYTHON_FLIT_VERSION).tar.gz
+PYTHON_FLIT_SITE = https://files.pythonhosted.org/packages/a8/bc/4bbb98f1ce0ae4e778f3486c39c487a066d69f5ffe4e762c79664dfd5df8
+PYTHON_FLIT_SETUP_TYPE = flit
+PYTHON_FLIT_LICENSE = BSD-3-Clause
+PYTHON_FLIT_LICENSE_FILES = LICENSE
+HOST_PYTHON_FLIT_NEEDS_HOST_PYTHON = python3
+HOST_PYTHON_FLIT_DEPENDENCIES = host-python-docutils host-python-tomli
+HOST_PYTHON_FLIT_ENV = PYTHONPATH="$(PYTHON3_PATH):$(@D):$(@D)/flit_core"
+
+$(eval $(host-python-package))
Signature · 6 lines
2.25.1

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

PATCH v2 3/4 utils/scanpypi: add flit package support

In reply to James Hilliard

These packages don't have a setup.py so we instead need to parse their pyproject.toml file.

---
 utils/scanpypi | 81 ++++++++++++++++++++++++++++++++++++++++----------
 1 file changed, 65 insertions(+), 16 deletions(-)
utils/scanpypi +65 -16
index 1f3326cf4d..4164a52db3 100755
@@ -296,21 +296,67 @@ class BuildrootPackage():
         current_dir = os.getcwd()
         os.chdir(self.tmp_extract)
         sys.path.insert(0, self.tmp_extract)
-        s_file, s_path, s_desc = imp.find_module('setup', [self.tmp_extract])
-        imp.load_module('__main__', s_file, s_path, s_desc)
-        if self.metadata_name in self.setup_args:
-            pass
-        elif self.metadata_name.replace('_', '-') in self.setup_args:
-            self.metadata_name = self.metadata_name.replace('_', '-')
-        elif self.metadata_name.replace('-', '_') in self.setup_args:
-            self.metadata_name = self.metadata_name.replace('-', '_')
         try:
-            self.setup_metadata = self.setup_args[self.metadata_name]
-        except KeyError:
-            # This means setup was not called
-            print('ERROR: Could not determine package metadata for {pkg}.\n'
-                  .format(pkg=self.real_name))
+            s_file, s_path, s_desc = imp.find_module('setup', [self.tmp_extract])
+            imp.load_module('__main__', s_file, s_path, s_desc)
+            if self.metadata_name in self.setup_args:
+                pass
+            elif self.metadata_name.replace('_', '-') in self.setup_args:
+                self.metadata_name = self.metadata_name.replace('_', '-')
+            elif self.metadata_name.replace('-', '_') in self.setup_args:
+                self.metadata_name = self.metadata_name.replace('-', '_')
+            try:
+                self.setup_metadata = self.setup_args[self.metadata_name]
+            except KeyError:
+                # This means setup was not called
+                print('ERROR: Could not determine package metadata for {pkg}.\n'
+                      .format(pkg=self.real_name))
+                raise
+        finally:
+            os.chdir(current_dir)
+            sys.path.remove(self.tmp_extract)
+
+    def load_pyproject(self):
+        """
+        Loads the corresponding pyproject.toml and store its metadata
+        """
+        from pprint import pprint
+        current_dir = os.getcwd()
+        os.chdir(self.tmp_extract)
+        sys.path.insert(0, self.tmp_extract)
+        try:
+            pyproject = open('pyproject.toml')
+        except FileNotFoundError:
             raise
+        else:
+            try:
+                from pip._vendor.tomli import load as toml_load
+            except ImportError:
+                try:
+                    from toml import load as _toml_load  # noqa: F401
+                    def toml_load(f):
+                        w = io.TextIOWrapper(f, encoding="utf8", newline="")
+                        try:
+                            return _toml_load(w)
+                        finally:
+                            w.detach()
+                except ImportError:
+                    print('This package needs toml')
+                    raise
+            with pyproject:
+                pyproject_data = toml_load(pyproject)
+                try:
+                    self.setup_metadata = pyproject_data.get('project', {})
+                    self.metadata_name = self.setup_metadata.get('name', self.real_name)
+                    build_backend = pyproject_data.get('build-system', {}).get('build-backend', None)
+                    if build_backend is not None:
+                        if build_backend == 'flit_core.buildapi':
+                            self.setup_metadata['method'] = 'flit'
+                except KeyError:
+                    # This means setup was not called
+                    print('ERROR: Could not determine package metadata for {pkg}.\n'
+                          .format(pkg=self.real_name))
+                    raise
         os.chdir(current_dir)
         sys.path.remove(self.tmp_extract)
 
@@ -690,11 +736,14 @@ def main():
             try:
                 package.load_setup()
             except ImportError as err:
-                if 'buildutils' in err.message:
+                if 'buildutils' in str(err):
                     print('This package needs buildutils')
+                    continue
                 else:
-                    raise
-                continue
+                    try:
+                        package.load_pyproject()
+                    except Exception as e:
+                        raise
             except (AttributeError, KeyError) as error:
                 print('Error: Could not install package {pkg}: {error}'.format(
                     pkg=package.real_name, error=error))
Signature · 6 lines
2.25.1

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

PATCH v2 4/4 package/python-tinycss2: bump to version 1.1.1

In reply to James Hilliard

This version now requires flit package infrastructure.

---
Changes v1 -> v2:
- rebased on next
- bump version instead of add package

---
 package/python-tinycss2/Config.in            | 2 ++
 package/python-tinycss2/python-tinycss2.hash | 4 ++--
 package/python-tinycss2/python-tinycss2.mk   | 6 +++---
 3 files changed, 7 insertions(+), 5 deletions(-)
package/python-tinycss2/Config.in +2 -0
index e6c992b8c5..e7a5bb3659 100644
@@ -4,3 +4,5 @@ config BR2_PACKAGE_PYTHON_TINYCSS2
 	select BR2_PACKAGE_PYTHON_WEBENCODINGS # runtime
 	help
 	  A tiny CSS parser.
+
+	  https://www.courtbouillon.org/tinycss2
package/python-tinycss2/python-tinycss2.hash +2 -2
index eeb3754752..e8e1d93f83 100644
@@ -1,5 +1,5 @@
 # md5, sha256 from https://pypi.org/pypi/tinycss2/json
-md5  7caf513c4e87fc2449dcfbf407a8416f  tinycss2-1.1.0.tar.gz
-sha256  fbdcac3044d60eb85fdb2aa840ece43cf7dbe798e373e6ee0be545d4d134e18a  tinycss2-1.1.0.tar.gz
+md5  60272f58f8d5834b2e09ffbc9bd5de53  tinycss2-1.1.1.tar.gz
+sha256  b2e44dd8883c360c35dd0d1b5aad0b610e5156c2cb3b33434634e539ead9d8bf  tinycss2-1.1.1.tar.gz
 # Locally computed sha256 checksums
 sha256  6b94acee20ec9f2709333134f3ba70322535fb420af0ce8c1455d9cbe297f1d5  LICENSE
package/python-tinycss2/python-tinycss2.mk +3 -3
index 4bf5b97766..e4fc5dc9c5 100644
@@ -4,10 +4,10 @@
 #
 ################################################################################
 
-PYTHON_TINYCSS2_VERSION = 1.1.0
+PYTHON_TINYCSS2_VERSION = 1.1.1
 PYTHON_TINYCSS2_SOURCE = tinycss2-$(PYTHON_TINYCSS2_VERSION).tar.gz
-PYTHON_TINYCSS2_SITE = https://files.pythonhosted.org/packages/ce/d3/ece7a98d5826bd134e269a3a3030153d30482194fca71d95a3041812aab8
-PYTHON_TINYCSS2_SETUP_TYPE = distutils
+PYTHON_TINYCSS2_SITE = https://files.pythonhosted.org/packages/1e/5a/576828164b5486f319c4323915b915a8af3fa4a654bbb6f8fc8e87b5cb17
+PYTHON_TINYCSS2_SETUP_TYPE = flit
 PYTHON_TINYCSS2_LICENSE = BSD-3-Clause
 PYTHON_TINYCSS2_LICENSE_FILES = LICENSE
 
Signature · 6 lines
2.25.1

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