Simplify Python bindings and package builds

Read each input path through one opened stream, including gzip detection, and
use direct numeric converter lookup while preserving byte-order handling and
caller data. Read the package version from installed metadata and report range
errors consistently as ValueError.

Require the supplied Cargo.lock instead of generating it during builds, use
the standard sdist command, and update package checks and development guides.

Validation: 15 Python tests pass against source and the rebuilt installed
wheel; the source archive and platform wheel build successfully.
This commit is contained in:
Jan Petykiewicz 2026-11-16 20:44:56 -08:00
commit a723ba2265

View file

@ -8,7 +8,6 @@ import tomllib
from setuptools import Distribution, setup
from setuptools.command.build_py import build_py
from setuptools.command.sdist import sdist
from wheel.bdist_wheel import bdist_wheel
@ -16,14 +15,12 @@ ROOT = Path(__file__).resolve().parent
VERSION = tomllib.loads((ROOT / "Cargo.toml").read_text())["package"]["version"]
def ensure_lockfile():
if not (ROOT / "Cargo.lock").is_file():
subprocess.run(["cargo", "generate-lockfile"], cwd=ROOT, check=True)
if not (ROOT / "Cargo.lock").is_file():
raise FileNotFoundError("Source builds require the supplied Cargo.lock")
class CargoBuild(build_py):
def run(self):
ensure_lockfile()
super().run()
result = subprocess.run(
["cargo", "build", "--release", "--lib", "--locked", "--message-format=json"],
@ -51,12 +48,6 @@ class CargoBuild(build_py):
shutil.copy2(library, Path(self.build_lib) / "pheon" / library.name)
class CargoSdist(sdist):
def run(self):
ensure_lockfile()
super().run()
class NativeDistribution(Distribution):
def has_ext_modules(self):
return True
@ -72,5 +63,5 @@ class NativeWheel(bdist_wheel):
setup(
version=VERSION,
distclass=NativeDistribution,
cmdclass={"build_py": CargoBuild, "sdist": CargoSdist, "bdist_wheel": NativeWheel},
cmdclass={"build_py": CargoBuild, "bdist_wheel": NativeWheel},
)