Skip to content

Commit

Permalink
python bindings: fix builds for pre-pyproject setuptools
Browse files Browse the repository at this point in the history
openSUSE Leap only has setuptools 44, which predates support for
pyproject. This is fine, we just need to add the relevant metadata to
the setuptools invocation. To reduce the amount of places we duplicate
this information, just load pyproject.toml and read the values out (this
does add a dependency on toml for pre-3.11 Python versions but that's
fine).

Signed-off-by: Aleksa Sarai <[email protected]>
  • Loading branch information
cyphar committed Sep 17, 2024
1 parent 2d7324b commit dc51be7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion contrib/bindings/python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

[build-system]
requires = [
"setuptools>=68",
"setuptools>=61",
"wheel",
"cffi>=1.10.0"
]
Expand Down
20 changes: 20 additions & 0 deletions contrib/bindings/python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,27 @@

import setuptools

# This is only needed for backwards compatibility with older versions.
def parse_pyproject():
try:
import tomllib
openmode = "rb"
except ImportError:
# For pre-3.11 Python support.
import toml as tomllib
openmode = "r"

with open("pyproject.toml", openmode) as f:
return tomllib.load(f)

pyproject = parse_pyproject()

setuptools.setup(
# For backwards-compatibility with pre-pyproject setuptools.
name=pyproject["project"]["name"],
version=pyproject["project"]["version"],
install_requires=pyproject["project"]["dependencies"],
# Configure cffi building.
ext_package="pathrs",
platforms=["Linux"],
cffi_modules=["pathrs/pathrs_build.py:ffibuilder"],
Expand Down

0 comments on commit dc51be7

Please sign in to comment.