blob: 51fe8c7c5600ee92842fd22945cc8b0f0cc4ab19 [file] [log] [blame]
Andrew Geissler595f6302022-01-24 19:11:47 +00001Upstream-Status: Submitted [https://github.com/dcantrell/pyparted/pull/85]
2Signed-off-by: Ross Burton <ross.burton@arm.com>
3
4From 3f5ca7eb6f57d8bcaa3b333497aba6e53d847450 Mon Sep 17 00:00:00 2001
5From: Ross Burton <ross.burton@arm.com>
6Date: Fri, 14 Jan 2022 16:06:31 +0000
7Subject: [PATCH] setup.py: port to setuptools
8
9Python 3.10 has deprecated distutils[1], and it will be removed entirely
10in Python 3.12.
11
12As the setuptools API is identical, moving to setuptools is trivial by
13changing the import.
14
15Remove check_mod_version, a version specifier can be passed directly
16to pkg-config.
17
18Remove unused imports.
19
20[1] https://docs.python.org/3/whatsnew/3.10.html#distutils-deprecated
21
22Signed-off-by: Ross Burton <ross.burton@arm.com>
23---
24 setup.py | 29 +++++++++--------------------
25 1 file changed, 9 insertions(+), 20 deletions(-)
26
27diff --git a/setup.py b/setup.py
28index da71d9c..1e9e367 100644
29--- a/setup.py
30+++ b/setup.py
31@@ -25,12 +25,7 @@ import glob
32 import os
33 import platform
34 import sys
35-from distutils.ccompiler import new_compiler
36-from distutils.errors import CompileError
37-from distutils.errors import LinkError
38-from distutils.core import setup
39-from distutils.core import Extension
40-from distutils.version import LooseVersion
41+from setuptools import setup, Extension
42
43 pyparted_version = '3.11.7'
44 python_version = sys.version_info
45@@ -45,19 +40,13 @@ if python_version < need_python_version:
46 # http://code.activestate.com/recipes/502261-python-distutils-pkg-config/
47 def pkgconfig(*packages, **kwargs):
48 flag_map = {'-I': 'include_dirs', '-L': 'library_dirs', '-l': 'libraries'}
49- for token in subprocess.check_output(["pkg-config", "--libs", "--cflags"] + list(packages)).decode('utf-8').split():
50-
51- kwargs.setdefault(flag_map.get(token[:2]), []).append(token[2:])
52- return kwargs
53-
54-def check_mod_version(module, version):
55- modversion = subprocess.check_output(["pkg-config", "--modversion", module]).decode('utf-8').split()[0]
56- if not LooseVersion(modversion) >= LooseVersion(version):
57- sys.stderr.write("*** Minimum required %s version: %s, found: %s\n" % (module, version, modversion,))
58- sys.exit(1)
59- return
60-
61-check_mod_version('libparted', need_libparted_version)
62+ try:
63+ for token in subprocess.check_output(["pkg-config", "--libs", "--cflags"] + list(packages),
64+ universal_newlines=True).split():
65+ kwargs.setdefault(flag_map.get(token[:2]), []).append(token[2:])
66+ return kwargs
67+ except subprocess.CalledProcessError as e:
68+ sys.exit("Cannot find pkg-config dependencies:\n" + e.output)
69
70 # This list is in the format necessary for the define_macros parameter
71 # for an Extension() module definition. See:
72@@ -77,6 +66,6 @@ setup(name='pyparted',
73 ext_modules=[Extension('_ped',
74 sorted(glob.glob(os.path.join('src', '*.c'))),
75 define_macros=features,
76- **pkgconfig('libparted',
77+ **pkgconfig('libparted >= %s' % need_libparted_version,
78 include_dirs=['include']))
79 ])
80--
812.25.1
82