Skip to content

Commit 1534c16

Browse files
committed
python: Make it compatible with python3.12
Python 3.12 removes distutils so it's mandatory to use setuptools with python >= 3.12. This patch prints a message when trying to run the setup.py script with a python >= 3.12 without setuptools and try to use the setuptools import by default. This patch also creates a new file, pyproject.toml [1], to prepare for building in modern systems. [1] https://peps.python.org/pep-0517/
1 parent 42e018b commit 1534c16

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

python/pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[build-system]
2+
requires = ["setuptools"]
3+
build-backend = "setuptools.build_meta"

python/setup.py.in

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,15 @@
55
import sys, os, subprocess
66

77
try:
8-
import setuptools
8+
from setuptools import setup, Extension
99
except ImportError:
10-
pass
11-
12-
from distutils.core import setup, Extension
10+
try:
11+
# Using distutils, for python < 3.12
12+
from distutils.core import setup, Extension
13+
except ImportError:
14+
# distutils is not present in python 3.12 and greater
15+
print("setuptools is required for python >= 3.12")
16+
sys.exit(1)
1317

1418
# Below ROOT, we expect to find include, include/libxml2, lib and bin.
1519
# On *nix, it is not needed (but should not harm),

0 commit comments

Comments
 (0)