summaryrefslogtreecommitdiff
path: root/meta-openembedded/meta-python/recipes-extended/python-pyparted/files/setuptools.patch
blob: 51fe8c7c5600ee92842fd22945cc8b0f0cc4ab19 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
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