Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

load_pyproject: Prefer the stdlib's TOML parser when available #344

Merged
merged 2 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -27,7 +27,7 @@ classifiers = [
dependencies = [
"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