Skip to content

Commit

Permalink
load_pyproject: Prefer the stdlib's TOML parser when available
Browse files Browse the repository at this point in the history
  • Loading branch information
nbraud committed Nov 22, 2023
1 parent ceeef19 commit 1c09b17
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 7 additions & 2 deletions bork/filesystem.py
Original file line number Diff line number Diff line change
@@ -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():
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

0 comments on commit 1c09b17

Please sign in to comment.