Re: Replace uses of deprecated Python module distutils.sysconfig

From: Andres Freund <andres(at)anarazel(dot)de>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Peter Eisentraut <peter(dot)eisentraut(at)enterprisedb(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Replace uses of deprecated Python module distutils.sysconfig
Date: 2022-01-23 22:59:32
Message-ID: 20220123225932.hhpzfh4qsunguuqm@alap3.anarazel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
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(at)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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2022-01-23 23:07:47 Re: Replace uses of deprecated Python module distutils.sysconfig
Previous Message Andrew Dunstan 2022-01-23 22:38:26 Re: fairywren is generating bogus BASE_BACKUP commands