Bug 1946972

Summary: %{python3_sitelib} and %{python3_sitearch} use the deprecated distutils module
Product: [Fedora] Fedora Reporter: Miro Hrončok <mhroncok>
Component: python-rpm-macrosAssignee: Karolina Surma <ksurma>
Status: CLOSED ERRATA QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: rawhideCC: cstratak, j, ksurma, m.cyprian, mhroncok, python-sig
Target Milestone: ---Keywords: FutureFeature
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: python-rpm-macros-3.9-37.fc35 Doc Type: Enhancement
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2021-04-08 14:26:21 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 1947468    

Description Miro Hrončok 2021-04-07 12:00:54 UTC
Currently, we define the following macros:

%python3_sitelib %(%{__python3} -Ic "from distutils.sysconfig import get_python_lib; print(get_python_lib())")
%python3_sitearch %(%{__python3} -Ic "from distutils.sysconfig import get_python_lib; print(get_python_lib(1))")

%python_sitelib %(%{__python} -Esc "from distutils.sysconfig import get_python_lib; print(get_python_lib())")
%python_sitearch %(%{__python} -Esc "from distutils.sysconfig import get_python_lib; print(get_python_lib(1))")

But distutils is deprecated in Python 3.10: https://www.python.org/dev/peps/pep-0632/

We need to figure out how to get this data from somewhere else.

I've checked and sysconfig does not have get_python_lib(), but it has get_path(). This is a code that we can use:

>>> from sysconfig import get_path
>>> get_path('platlib') 
'/usr/lib64/python3.9/site-packages'
>>> get_path('purelib')
'/usr/lib/python3.9/site-packages'


It seems to work across variety of our Pythons:

$ for PYTHON in python{2.7,3.{5..10}} pypy2 pypy3; do echo $PYTHON; $PYTHON -c 'from __future__ import print_function; from distutils.sysconfig import get_python_lib; from sysconfig import get_path; print(get_path("platlib"), get_python_lib(1), get_path("platlib")==get_python_lib(1)); print(get_path("purelib"), get_python_lib(), get_path("purelib")==get_python_lib())'; echo; done
python2.7
/usr/lib64/python2.7/site-packages /usr/lib64/python2.7/site-packages True
/usr/lib/python2.7/site-packages /usr/lib/python2.7/site-packages True

python3.5
/usr/lib64/python3.5/site-packages /usr/lib64/python3.5/site-packages True
/usr/lib/python3.5/site-packages /usr/lib/python3.5/site-packages True

python3.6
/usr/lib64/python3.6/site-packages /usr/lib64/python3.6/site-packages True
/usr/lib/python3.6/site-packages /usr/lib/python3.6/site-packages True

python3.7
/usr/lib64/python3.7/site-packages /usr/lib64/python3.7/site-packages True
/usr/lib/python3.7/site-packages /usr/lib/python3.7/site-packages True

python3.8
/usr/lib64/python3.8/site-packages /usr/lib64/python3.8/site-packages True
/usr/lib/python3.8/site-packages /usr/lib/python3.8/site-packages True

python3.9
/usr/lib64/python3.9/site-packages /usr/lib64/python3.9/site-packages True
/usr/lib/python3.9/site-packages /usr/lib/python3.9/site-packages True

python3.10
/usr/lib64/python3.10/site-packages /usr/lib64/python3.10/site-packages True
/usr/lib/python3.10/site-packages /usr/lib/python3.10/site-packages True

pypy2
/usr/lib64/pypy-7.3/site-packages /usr/lib64/pypy-7.3/site-packages True
/usr/lib64/pypy-7.3/site-packages /usr/lib64/pypy-7.3/site-packages True

pypy3
/usr/lib64/pypy3-7.3/site-packages /usr/lib64/pypy3-7.3/site-packages True
/usr/lib64/pypy3-7.3/site-packages /usr/lib64/pypy3-7.3/site-packages True

Comment 2 Fedora Update System 2021-04-08 14:26:21 UTC
FEDORA-2021-afa6e07b4d has been pushed to the Fedora 35 stable repository.
If problem still persists, please make note of it in this bug report.