Skip to content

Commit fd7d2af

Browse files
authored
Merge branch 'main' into modern
2 parents 6264467 + e9b163d commit fd7d2af

File tree

7 files changed

+15
-11
lines changed

7 files changed

+15
-11
lines changed

README.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,16 @@ Usage—you are responsible for ensuring build requirements are available:
2222
.. code-block:: python
2323
2424
import os
25-
import tomli
25+
try:
26+
import tomllib # Python >= 3.11 - standard library
27+
except ImportError:
28+
import tomli as tomllib # Python <= 3.10
29+
2630
from pyproject_hooks import BuildBackendHookCaller
2731
2832
src = 'path/to/source' # Folder containing 'pyproject.toml'
2933
with open(os.path.join(src, 'pyproject.toml'), 'rb') as f:
30-
build_sys = tomli.load(f)['build-system']
34+
build_sys = tomllib.load(f)['build-system']
3135
3236
print(build_sys['requires']) # List of static requirements
3337
# The caller is responsible for installing these and running the hooks in

dev-requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
pytest
22
flake8
33
testpath
4-
tomli
54
setuptools>=30
5+
tomli ; python_version<'3.11'

doc/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
tomli
1+
tomli ; python_version<'3.11'

src/pyproject_hooks/_impl.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ def __init__(self, traceback):
3030
class BackendInvalid(Exception):
3131
"""Will be raised if the backend is invalid."""
3232
def __init__(self, backend_name, backend_path, message):
33+
super().__init__(message)
3334
self.backend_name = backend_name
3435
self.backend_path = backend_path
35-
self.message = message
3636

3737

3838
class HookMissing(Exception):

tests/test_call_hooks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from unittest.mock import Mock
88

99
import pytest
10-
import tomli
1110
from testpath import assert_isfile, modified_env
1211
from testpath.tempdir import TemporaryDirectory, TemporaryWorkingDirectory
1312

@@ -17,6 +16,7 @@
1716
UnsupportedOperation,
1817
default_subprocess_runner,
1918
)
19+
from pyproject_hooks._compat import tomllib
2020

2121
SAMPLES_DIR = pjoin(dirname(abspath(__file__)), 'samples')
2222
BUILDSYS_PKGS = pjoin(SAMPLES_DIR, 'buildsys_pkgs')
@@ -25,7 +25,7 @@
2525
def get_hooks(pkg, **kwargs):
2626
source_dir = pjoin(SAMPLES_DIR, pkg)
2727
with open(pjoin(source_dir, 'pyproject.toml'), 'rb') as f:
28-
data = tomli.load(f)
28+
data = tomllib.load(f)
2929
return BuildBackendHookCaller(
3030
source_dir, data['build-system']['build-backend'], **kwargs
3131
)

tests/test_hook_fallbacks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
from os.path import join as pjoin
33

44
import pytest
5-
import tomli
65
from testpath import assert_isfile, modified_env
76
from testpath.tempdir import TemporaryDirectory
87

98
from pyproject_hooks import BuildBackendHookCaller, HookMissing
9+
from pyproject_hooks._compat import tomllib
1010

1111
SAMPLES_DIR = pjoin(dirname(abspath(__file__)), 'samples')
1212
BUILDSYS_PKGS = pjoin(SAMPLES_DIR, 'buildsys_pkgs')
@@ -15,7 +15,7 @@
1515
def get_hooks(pkg):
1616
source_dir = pjoin(SAMPLES_DIR, pkg)
1717
with open(pjoin(source_dir, 'pyproject.toml'), 'rb') as f:
18-
data = tomli.load(f)
18+
data = tomllib.load(f)
1919
return BuildBackendHookCaller(source_dir, data['build-system']['build-backend'])
2020

2121

tests/test_inplace_hooks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
from os.path import join as pjoin
33

44
import pytest
5-
import tomli
65
from testpath import modified_env
76

87
from pyproject_hooks import BackendInvalid, BuildBackendHookCaller
8+
from pyproject_hooks._compat import tomllib
99

1010
SAMPLES_DIR = pjoin(dirname(abspath(__file__)), 'samples')
1111
BUILDSYS_PKGS = pjoin(SAMPLES_DIR, 'buildsys_pkgs')
@@ -15,7 +15,7 @@
1515
def get_hooks(pkg, backend=None, path=None):
1616
source_dir = pjoin(SAMPLES_DIR, pkg)
1717
with open(pjoin(source_dir, 'pyproject.toml'), 'rb') as f:
18-
data = tomli.load(f)
18+
data = tomllib.load(f)
1919
if backend is None:
2020
backend = data['build-system']['build-backend']
2121
if path is None:

0 commit comments

Comments
 (0)