Browse Source

Use tomllib in Python 3.11+

pull/143/head
Taneli Hukkinen 3 months ago
parent
commit
716169172e
  1. 2
      README.rst
  2. 6
      pep517/_compat.py
  3. 5
      pep517/build.py
  4. 7
      pep517/check.py
  5. 5
      pep517/envbuild.py
  6. 2
      pyproject.toml

2
README.rst

@ -26,7 +26,7 @@ Usage—you are responsible for ensuring build requirements are available:
from pep517.wrappers import Pep517HookCaller
src = 'path/to/source' # Folder containing 'pyproject.toml'
with open(os.path.join(src, 'pyproject.toml')) as f:
with open(os.path.join(src, 'pyproject.toml'), 'rb') as f:
build_sys = tomli.load(f)['build-system']
print(build_sys['requires']) # List of static requirements

6
pep517/_compat.py

@ -0,0 +1,6 @@
import sys
if sys.version_info >= (3, 11):
import tomllib
else:
import tomli as tomllib

5
pep517/build.py

@ -6,8 +6,7 @@ import os
import shutil
import tempfile
import tomli
from ._compat import tomllib
from .envbuild import BuildEnvironment
from .wrappers import Pep517HookCaller
@ -32,7 +31,7 @@ def load_system(source_dir):
"""
pyproject = os.path.join(source_dir, 'pyproject.toml')
with open(pyproject, 'rb') as f:
pyproject_data = tomli.load(f)
pyproject_data = tomllib.load(f)
return pyproject_data['build-system']

7
pep517/check.py

@ -12,8 +12,7 @@ from os.path import join as pjoin
from subprocess import CalledProcessError
from tempfile import mkdtemp
import tomli
from ._compat import tomllib
from .colorlog import enable_colourful_output
from .envbuild import BuildEnvironment
from .wrappers import Pep517HookCaller
@ -144,14 +143,14 @@ def check(source_dir):
try:
with open(pyproject, 'rb') as f:
pyproject_data = tomli.load(f)
pyproject_data = tomllib.load(f)
# Ensure the mandatory data can be loaded
buildsys = pyproject_data['build-system']
requires = buildsys['requires']
backend = buildsys['build-backend']
backend_path = buildsys.get('backend-path')
log.info('Loaded pyproject.toml')
except (tomli.TOMLDecodeError, KeyError):
except (tomllib.TOMLDecodeError, KeyError):
log.error("Invalid pyproject.toml", exc_info=True)
return False

5
pep517/envbuild.py

@ -9,8 +9,7 @@ from subprocess import check_call
from sysconfig import get_paths
from tempfile import mkdtemp
import tomli
from ._compat import tomllib
from .wrappers import LoggerWrapper, Pep517HookCaller
log = logging.getLogger(__name__)
@ -21,7 +20,7 @@ def _load_pyproject(source_dir):
os.path.join(source_dir, 'pyproject.toml'),
'rb',
) as f:
pyproject_data = tomli.load(f)
pyproject_data = tomllib.load(f)
buildsys = pyproject_data['build-system']
return (
buildsys['requires'],

2
pyproject.toml

@ -9,7 +9,7 @@ author-email = "thomas@kluyver.me.uk"
home-page = "https://github.com/pypa/pep517"
description-file = "README.rst"
requires = [
"tomli >=1.1.0",
"tomli >=1.1.0;python_version<'3.11'",
"importlib_metadata;python_version<'3.8'",
"zipp;python_version<'3.8'",
]

Loading…
Cancel
Save