Skip to content

Commit

Permalink
[Meson,CI] Fix check-python-platlib for Python 3.12
Browse files Browse the repository at this point in the history
And add bookworm (Debian 12) and noble (Ubuntu 24.04 LTS) to
check-python-platlib.

Signed-off-by: Wojtek Porczyk <woju@invisiblethingslab.com>
  • Loading branch information
woju committed Oct 14, 2024
1 parent 6f7c14c commit 91c90b4
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 9 deletions.
11 changes: 11 additions & 0 deletions .ci/check-python-platlib-debian12.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM debian:bookworm

ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update && apt-get install -y \
python3 \
python3-distutils \
python3-setuptools

COPY scripts/get-python-platlib.py /get-python-platlib.py
RUN mkdir -p "$(python3 /get-python-platlib.py /usr/local)"
10 changes: 10 additions & 0 deletions .ci/check-python-platlib-ubuntu24.04.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM ubuntu:24.04

ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update && apt-get install -y \
python3 \
python3-setuptools

COPY scripts/get-python-platlib.py /get-python-platlib.py
RUN mkdir -p "$(python3 /get-python-platlib.py /usr/local)"
2 changes: 2 additions & 0 deletions .ci/check-python-platlib.jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ node() {
checkout scm

[
'debian12',
'debian11',
'ubuntu24.04',
'ubuntu22.04',
'ubuntu20.04',
'almalinux9',
Expand Down
28 changes: 19 additions & 9 deletions scripts/get-python-platlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
sure to ``mkdir -p`` all suspected paths; that's also why we can't ``assert``
that result is in ``sys.path``.
- PEP-632 deprecates ``distutils`` package (3.10-3.11 ``DeprecationWarning``,
not installed in 3.12).
not installed in 3.12). UPDATE 26.09.2024: Ubuntu 24.04 has Python 3.12 with
no ``distutils``, but setuptools ships vendored copy for now.
References
==========
Expand All @@ -53,37 +54,46 @@
'''

import argparse
import distutils.command.install
import distutils.sysconfig
import distutils.util
import pathlib
import sys
import sysconfig

try:
import distutils.command.install as distutils_command_install
import distutils.sysconfig as distutils_sysconfig
import distutils.util as distutils_util
except ImportError:
import setuptools._distutils.command.install as distutils_command_install
import setuptools._distutils.sysconfig as distutils_sysconfig
import setuptools._distutils.util as distutils_util

def get_platlib(prefix):
is_debian = (
'deb_system' in sysconfig.get_scheme_names() or
'deb_system' in distutils.command.install.INSTALL_SCHEMES)
'deb_system' in distutils_command_install.INSTALL_SCHEMES)

# this takes care of `/` at the end, though not `/usr/../usr/local`
is_usr_local = pathlib.PurePosixPath(prefix).as_posix() == '/usr/local'

if is_debian and is_usr_local:
# 1) try sysconfig; it works on bookworm and jammy
platlib1 = sysconfig.get_path('platlib')
try:
platlib1 = sysconfig.get_path('platlib', 'deb_system')
except KeyError:
platlib1 = None

if platlib1 in sys.path:
return platlib1

# 2) if system is too old for sysconfig, then distutils should work
return distutils.util.subst_vars(
distutils.command.install.INSTALL_SCHEMES['unix_local']['platlib'],
return distutils_util.subst_vars(
distutils_command_install.INSTALL_SCHEMES['unix_local']['platlib'],
{
'platbase': '/usr',
'py_version_short': '.'.join(map(str, sys.version_info[:2])),
})

return distutils.sysconfig.get_python_lib(plat_specific=True, prefix=prefix)
return distutils_sysconfig.get_python_lib(plat_specific=True, prefix=prefix)


argparser = argparse.ArgumentParser()
Expand Down

0 comments on commit 91c90b4

Please sign in to comment.