Re: Replace uses of deprecated Python module distutils.sysconfig
Andres Freund <andres@anarazel.de>
From: Andres Freund <andres@anarazel.de>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Peter Eisentraut <peter.eisentraut@enterprisedb.com>, Andrew Dunstan <andrew@dunslane.net>, pgsql-hackers@lists.postgresql.org
Date: 2022-01-23T22:59:32Z
Lists: pgsql-hackers
Hi,
On 2022-01-23 16:06:21 -0500, Tom Lane wrote:
> I wrote:
> > Based on the buildfarm results so far, the problem can be described
> > as "some installations say /usr/local when they should have said /usr".
> > I experimented with the attached delta patch and it fixes the problem
> > on my Debian 9 image. (I don't know Python, so there may be a better
> > way to do this.) We'd have to also bump the minimum 3.x version to
> > 3.2, but that seems very unlikely to bother anyone.
>
> I did a little more digging into this. The python2 package on
> my Deb9 (actually Raspbian) system says it is 2.7.13, but
> /usr/lib/python2.7/sysconfig.py is different from what I find in
> a virgin Python 2.7.13 tarball, as per attached diff. I conclude
> that somebody at Debian decided that Python should live under
> /usr/local, and changed sysconfig.py to match, but then failed
> to adjust the actual install scripts to agree, because there is
> certainly nothing installed under /usr/local. (I don't know
> enough about Debian packaging to find the smoking gun though;
> what apt-get claims is the source package contains no trace of
> this diff.) There's no sign of comparable changes in
> /usr/lib/python3.5/sysconfig.py on the same machine, either.
> + 'posix_local': {
> + 'stdlib': '{base}/lib/python{py_version_short}',
> + 'platstdlib': '{platbase}/lib/python{py_version_short}',
> + 'purelib': '{base}/local/lib/python{py_version_short}/dist-packages',
> + 'platlib': '{platbase}/local/lib/python{py_version_short}/dist-packages',
> + 'include': '{base}/local/include/python{py_version_short}',
> + 'platinclude': '{platbase}/local/include/python{py_version_short}',
> + 'scripts': '{base}/local/bin',
> + 'data': '{base}/local',
> + },
> + 'deb_system': {
> + 'stdlib': '{base}/lib/python{py_version_short}',
> + 'platstdlib': '{platbase}/lib/python{py_version_short}',
> + 'purelib': '{base}/lib/python{py_version_short}/dist-packages',
> + 'platlib': '{platbase}/lib/python{py_version_short}/dist-packages',
> + 'include': '{base}/include/python{py_version_short}',
> + 'platinclude': '{platbase}/include/python{py_version_short}',
> + 'scripts': '{base}/bin',
> + 'data': '{base}',
> + },
> 'posix_home': {
Hm. It seems the intent of the different paths you show is that we can specify
which type of path we want. The one to locally installed extensions, or the
distribution ones. So we'd have to specify the scheme to get the other include
path?
andres@awork3:~$ python2
Python 2.7.18 (default, Sep 24 2021, 09:39:51)
[GCC 10.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sysconfig
>>> sysconfig.get_path('include')
'/usr/local/include/python2.7'
>>> sysconfig.get_path('include', 'posix_prefix')
'/usr/include/python2.7'
>>> sysconfig.get_path('include', 'posix_local')
'/usr/local/include/python2.7'
So it seems we could do something like
sysconfig.get_path('include', 'posix_prefix' if os.name == 'posix' else os.name)
or
scheme = sysconfig._get_default_scheme()
# Work around Debian / Ubuntu returning paths not useful for finding python headers
if scheme == 'posix_local':
scheme = 'posix_prefix'
sysconfig.get_path('include', scheme = scheme)
Greetings,
Andres Freund
Commits
-
Replace use of deprecated Python module distutils.sysconfig, take 2.
- e41176bd6f47 11.15 landed
- aa2215d6b8ac 12.10 landed
- a72c430120cf 10.20 landed
- 803f0b173906 14.2 landed
- 4d7d196ff693 13.6 landed
- bd233bdd8dd9 15.0 landed
-
Temporarily add some information about python include paths to configure.
- f032f63e727c 15.0 landed
-
Revert "Make configure prefer python3 to plain python."
- 512fc2dd790e 15.0 landed
-
Make configure prefer python3 to plain python.
- f201da39edcd 15.0 landed
-
Replace use of deprecated Python module distutils.sysconfig
- e0e567a10672 15.0 landed