From dd063ac15470ab0d16fe92a0499e5daf0d547fd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Mon, 19 Apr 2021 20:59:10 +0000 Subject: [PATCH] Fix python(abi) generator (the one written in Python) There were three problems: - sys.version was not imported - sys.version[:3] is not reliable on Python 3.10+ - distutils is deprecated on Python 3.10+ We were not hit by the missing import in Fedora because we only run the script on .dist-info/.egg-info/.egg and not on .py files, so this if-branch never runs. But when the script was fed with a .py path, it errored: Traceback (most recent call last): File "/usr/lib/rpm/pythondistdeps.py", line 344, in purelib = get_python_lib(standard_lib=0, plat_specific=0).split(version[:3])[0] NameError: name 'version' is not defined The sys.version[:3] thing kinda works for Python 3.10+ because *in this particular case* splitting on '3.1' and taking the prefix yields the same results as splitting on '3.10', but I consider that mere coincidence. Finally, since the distutils import happened at module-level, we got the Deprecation warning in all Fedora's Python packages: /usr/lib/rpm/pythondistdeps.py:16: DeprecationWarning: The distutils package is deprecated and slated for removal in Python 3.12 Backported from https://github.com/rpm-software-management/python-rpm-packaging/commit/d12e039037 Related: rhbz#1950291 --- python-rpm-generators.spec | 7 ++++++- pythondistdeps.py | 9 +++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/python-rpm-generators.spec b/python-rpm-generators.spec index af34aa6..df5cec6 100644 --- a/python-rpm-generators.spec +++ b/python-rpm-generators.spec @@ -1,7 +1,7 @@ Name: python-rpm-generators Summary: Dependency generators for Python RPMs Version: 12 -Release: 5.1%{?dist} +Release: 6%{?dist} # Originally all those files were part of RPM, so license is kept here License: GPLv2+ @@ -47,6 +47,11 @@ install -Dpm0755 -t %{buildroot}%{_rpmconfigdir} *.py %{_rpmconfigdir}/pythonbundles.py %changelog +* Mon Apr 19 2021 Miro Hrončok - 12-6 +- Get rid of distutils deprecation warning (by not using it) +- The distutils module is deprecated in Python 3.10+ +- https://www.python.org/dev/peps/pep-0632/ + * Fri Apr 16 2021 Miro Hrončok - 12-5.1 - Do not generate setuptools requirement for console_scripts on Python 3.10+ - See https://fedoraproject.org/wiki/Changes/Reduce_dependencies_on_python3-setuptools diff --git a/pythondistdeps.py b/pythondistdeps.py index 17f49f3..8be1a4d 100755 --- a/pythondistdeps.py +++ b/pythondistdeps.py @@ -13,10 +13,10 @@ from __future__ import print_function import argparse -from distutils.sysconfig import get_python_lib from os.path import dirname, sep import re -from sys import argv, stdin, stderr +from sys import argv, stdin, stderr, version_info +from sysconfig import get_path from warnings import warn from packaging.requirements import Requirement as Requirement_ @@ -341,8 +341,9 @@ if __name__ == "__main__": if py_abi and (lower.endswith('.py') or lower.endswith('.pyc') or lower.endswith('.pyo')): if name not in py_deps: py_deps[name] = [] - purelib = get_python_lib(standard_lib=0, plat_specific=0).split(version[:3])[0] - platlib = get_python_lib(standard_lib=0, plat_specific=1).split(version[:3])[0] + running_python_version = '{}.{}'.format(*version_info[:2]) + purelib = get_path('purelib').split(running_python_version)[0] + platlib = get_path('platlib').split(running_python_version)[0] for lib in (purelib, platlib): if lib in f: spec = ('==', f.split(lib)[1].split(sep)[0])