]>
Commit | Line | Data |
---|---|---|
b3a46cd9 JR |
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) | |
5 | ||
6 | There were three problems: | |
7 | ||
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+ | |
11 | ||
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. | |
14 | ||
15 | But when the script was fed with a .py path, it errored: | |
16 | ||
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 | |
21 | ||
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. | |
25 | ||
26 | Finally, since the distutils import happened at module-level, | |
27 | we got the Deprecation warning in all Fedora's Python packages: | |
28 | ||
29 | /usr/lib/rpm/pythondistdeps.py:16: DeprecationWarning: The distutils package is deprecated and slated for removal in Python 3.12 | |
30 | --- | |
31 | scripts/pythondistdeps.py | 9 +++++---- | |
32 | 1 file changed, 5 insertions(+), 4 deletions(-) | |
33 | ||
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 | |
38 | @@ -13,8 +13,8 @@ | |
39 | from __future__ import print_function | |
40 | import argparse | |
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 | |
47 | ||
48 | ||
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: | |
52 | py_deps[name] = [] | |
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): | |
59 | if lib in f: | |
60 | spec = ('==', f.split(lib)[1].split(sep)[0]) |