python3-pyparted: port to setuptools

Message ID 20220114161207.4013613-1-ross.burton@arm.com
State New
Headers show
Series python3-pyparted: port to setuptools | expand

Commit Message

Ross Burton Jan. 14, 2022, 4:12 p.m. UTC
Signed-off-by: Ross Burton <ross.burton@arm.com>
---
 .../python-pyparted/files/setuptools.patch    | 82 +++++++++++++++++++
 .../python3-pyparted_3.11.7.bb                |  4 +-
 2 files changed, 85 insertions(+), 1 deletion(-)
 create mode 100644 meta-python/recipes-extended/python-pyparted/files/setuptools.patch

Patch

diff --git a/meta-python/recipes-extended/python-pyparted/files/setuptools.patch b/meta-python/recipes-extended/python-pyparted/files/setuptools.patch
new file mode 100644
index 0000000000..51fe8c7c56
--- /dev/null
+++ b/meta-python/recipes-extended/python-pyparted/files/setuptools.patch
@@ -0,0 +1,82 @@ 
+Upstream-Status: Submitted [https://github.com/dcantrell/pyparted/pull/85]
+Signed-off-by: Ross Burton <ross.burton@arm.com>
+
+From 3f5ca7eb6f57d8bcaa3b333497aba6e53d847450 Mon Sep 17 00:00:00 2001
+From: Ross Burton <ross.burton@arm.com>
+Date: Fri, 14 Jan 2022 16:06:31 +0000
+Subject: [PATCH] setup.py: port to setuptools
+
+Python 3.10 has deprecated distutils[1], and it will be removed entirely
+in Python 3.12.
+
+As the setuptools API is identical, moving to setuptools is trivial by
+changing the import.
+
+Remove check_mod_version, a version specifier can be passed directly
+to pkg-config.
+
+Remove unused imports.
+
+[1] https://docs.python.org/3/whatsnew/3.10.html#distutils-deprecated
+
+Signed-off-by: Ross Burton <ross.burton@arm.com>
+---
+ setup.py | 29 +++++++++--------------------
+ 1 file changed, 9 insertions(+), 20 deletions(-)
+
+diff --git a/setup.py b/setup.py
+index da71d9c..1e9e367 100644
+--- a/setup.py
++++ b/setup.py
+@@ -25,12 +25,7 @@ import glob
+ import os
+ import platform
+ import sys
+-from distutils.ccompiler import new_compiler
+-from distutils.errors import CompileError
+-from distutils.errors import LinkError
+-from distutils.core import setup
+-from distutils.core import Extension
+-from distutils.version import LooseVersion
++from setuptools import setup, Extension
+ 
+ pyparted_version = '3.11.7'
+ python_version = sys.version_info
+@@ -45,19 +40,13 @@ if python_version < need_python_version:
+ # http://code.activestate.com/recipes/502261-python-distutils-pkg-config/
+ def pkgconfig(*packages, **kwargs):
+     flag_map = {'-I': 'include_dirs', '-L': 'library_dirs', '-l': 'libraries'}
+-    for token in subprocess.check_output(["pkg-config", "--libs", "--cflags"] + list(packages)).decode('utf-8').split():
+-
+-        kwargs.setdefault(flag_map.get(token[:2]), []).append(token[2:])
+-    return kwargs
+-
+-def check_mod_version(module, version):
+-    modversion = subprocess.check_output(["pkg-config", "--modversion", module]).decode('utf-8').split()[0]
+-    if not LooseVersion(modversion) >= LooseVersion(version):
+-        sys.stderr.write("*** Minimum required %s version: %s, found: %s\n" % (module, version, modversion,))
+-        sys.exit(1)
+-    return
+-
+-check_mod_version('libparted', need_libparted_version)
++    try:
++        for token in subprocess.check_output(["pkg-config", "--libs", "--cflags"] + list(packages),
++                                            universal_newlines=True).split():
++            kwargs.setdefault(flag_map.get(token[:2]), []).append(token[2:])
++        return kwargs
++    except subprocess.CalledProcessError as e:
++        sys.exit("Cannot find pkg-config dependencies:\n" + e.output)
+ 
+ # This list is in the format necessary for the define_macros parameter
+ # for an Extension() module definition.  See:
+@@ -77,6 +66,6 @@ setup(name='pyparted',
+       ext_modules=[Extension('_ped',
+                              sorted(glob.glob(os.path.join('src', '*.c'))),
+                              define_macros=features,
+-                             **pkgconfig('libparted',
++                             **pkgconfig('libparted >= %s' % need_libparted_version,
+                                          include_dirs=['include']))
+                   ])
+-- 
+2.25.1
+
diff --git a/meta-python/recipes-extended/python-pyparted/python3-pyparted_3.11.7.bb b/meta-python/recipes-extended/python-pyparted/python3-pyparted_3.11.7.bb
index ef04024aaf..66cd27d447 100644
--- a/meta-python/recipes-extended/python-pyparted/python3-pyparted_3.11.7.bb
+++ b/meta-python/recipes-extended/python-pyparted/python3-pyparted_3.11.7.bb
@@ -9,10 +9,12 @@  LIC_FILES_CHKSUM = "\
     file://src/_pedmodule.c;beginline=10;endline=22;md5=9e53304db812b80d0939e11bb69dcab2 \
 "
 
+SRC_URI += "file://setuptools.patch"
+
 SRC_URI[md5sum] = "69284f943982f54ded76960c92098a02"
 SRC_URI[sha256sum] = "61cde7b096bccd69ddc75c85b17f8baed45c3687d404706d91403a319453b903"
 
-inherit pkgconfig pypi distutils3
+inherit pkgconfig pypi setuptools3
 
 DEPENDS += "parted"