From 1c09b170cdb2cb29c93858e649220ab5ca6db77b Mon Sep 17 00:00:00 2001 From: nicoo Date: Wed, 22 Nov 2023 14:51:40 +0000 Subject: [PATCH] load_pyproject: Prefer the stdlib's TOML parser when available --- bork/filesystem.py | 9 +++++++-- pyproject.toml | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/bork/filesystem.py b/bork/filesystem.py index b776682..5e142f9 100644 --- a/bork/filesystem.py +++ b/bork/filesystem.py @@ -1,7 +1,10 @@ from pathlib import Path import shutil -import toml # type: ignore +try: + import tomllib +except ImportError: + import toml as tomllib # type: ignore def load_pyproject(): @@ -11,7 +14,9 @@ def load_pyproject(): Will synthesize data if a legacy setuptools project is detected. """ try: - return toml.load('pyproject.toml') + pyproject = Path.cwd() / 'pyproject.toml' + return tomllib.loads(pyproject.read_text()) # Mildly inefficient, but portable + except FileNotFoundError: if Path('setup.py').exists() or Path('setup.cfg').exists(): # Legacy project, use setuptools' legacy backend diff --git a/pyproject.toml b/pyproject.toml index b003ac1..2200455 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -28,7 +28,7 @@ dependencies = [ "wheel~=0.41.2", "build~=1.0.3", "packaging~=21.3", - "toml~=0.10.2", + "toml~=0.10.2; python_version < '3.11'", "twine==4.0.1", "coloredlogs~=15.0.1", # pip is used by bork.builder._prepare_zipapp(),