1 From d12e039037bf9a7d22d51bf1cc5925525a945ddf Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= <miro@hroncok.cz>
3 Date: Mon, 19 Apr 2021 20:33:33 +0200
4 Subject: [PATCH] Fix python(abi) generator (the one written in Python)
6 There were three problems:
8 - sys.version was not imported
9 - sys.version[:3] is not reliable on Python 3.10+
10 - distutils is deprecated on Python 3.10+
12 We were not hit by the missing import in Fedora because we only run the script
13 on .dist-info/.egg-info/.egg and not on .py files, so this if-branch never runs.
15 But when the script was fed with a .py path, it errored:
17 Traceback (most recent call last):
18 File "/usr/lib/rpm/pythondistdeps.py", line 344, in <module>
19 purelib = get_python_lib(standard_lib=0, plat_specific=0).split(version[:3])[0]
20 NameError: name 'version' is not defined
22 The sys.version[:3] thing kinda works for Python 3.10+ because *in this
23 particular case* splitting on '3.1' and taking the prefix yields the same
24 results as splitting on '3.10', but I consider that mere coincidence.
26 Finally, since the distutils import happened at module-level,
27 we got the Deprecation warning in all Fedora's Python packages:
29 /usr/lib/rpm/pythondistdeps.py:16: DeprecationWarning: The distutils package is deprecated and slated for removal in Python 3.12
31 scripts/pythondistdeps.py | 9 +++++----
32 1 file changed, 5 insertions(+), 4 deletions(-)
34 diff --git a/scripts/pythondistdeps.py b/scripts/pythondistdeps.py
35 index 4e178c0..1f81c19 100755
36 --- a/scripts/pythondistdeps.py
37 +++ b/scripts/pythondistdeps.py
39 from __future__ import print_function
41 from os.path import basename, dirname, isdir, sep
42 -from sys import argv, stdin, version
43 -from distutils.sysconfig import get_python_lib
44 +from sys import argv, stdin, version, version_info
45 +from sysconfig import get_path
46 from warnings import warn
49 @@ -287,8 +287,9 @@ def get_marker_env(dist, extra):
50 if py_abi and (lower.endswith('.py') or lower.endswith('.pyc') or lower.endswith('.pyo')):
51 if name not in py_deps:
53 - purelib = get_python_lib(standard_lib=0, plat_specific=0).split(version[:3])[0]
54 - platlib = get_python_lib(standard_lib=0, plat_specific=1).split(version[:3])[0]
55 + running_python_version = '{}.{}'.format(*version_info[:2])
56 + purelib = get_path('purelib').split(running_python_version)[0]
57 + platlib = get_path('platlib').split(running_python_version)[0]
58 for lib in (purelib, platlib):
60 spec = ('==', f.split(lib)[1].split(sep)[0])