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 eaa5c0f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
7 changes: 4 additions & 3 deletions contrib/bindings/python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@

[build-system]
requires = [
"setuptools>=68",
"cffi>=1.10.0",
"setuptools>=61",
"toml>=0.10", # TODO: Remove this once we only support Python >= 3.11.
"wheel",
"cffi>=1.10.0"
]
build-backend = "setuptools.build_meta"

Expand Down Expand Up @@ -50,7 +51,7 @@ classifiers = [

requires-python = ">= 3.8"
dependencies = [
"cffi>=1.10.0"
"cffi>=1.10.0",
]

[project.urls]
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:
# TODO: Remove this once we only support Python >= 3.11.
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 eaa5c0f

Please sign in to comment.