Skip to content

Commit ca52f3e

Browse files
committed
Use stdlib tomllib instead of tomli for Python 3.11+
1 parent 69e257a commit ca52f3e

File tree

4 files changed

+13
-8
lines changed

4 files changed

+13
-8
lines changed

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ packages = find:
2929
install_requires =
3030
packaging>=20.0
3131
setuptools
32-
tomli>=1.0.0 # keep in sync
3332
typing-extensions
3433
importlib-metadata;python_version < '3.8'
34+
tomli>=1.0.0;python_version < '3.11' # keep in sync
3535
python_requires = >=3.7
3636
package_dir =
3737
=src

src/setuptools_scm/_integration/pyproject_reading.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
import sys
34
import warnings
45
from typing import Any
56
from typing import Callable
@@ -28,8 +29,11 @@ def project_name(self) -> str | None:
2829
return self.project.get("name")
2930

3031

31-
def lazy_tomli_load(data: str) -> TOML_RESULT:
32-
from tomli import loads
32+
def lazy_toml_load(data: str) -> TOML_RESULT:
33+
if sys.version_info >= (3, 11):
34+
from tomllib import loads
35+
else:
36+
from tomli import loads
3337

3438
return loads(data)
3539

@@ -40,7 +44,7 @@ def read_pyproject(
4044
_load_toml: TOML_LOADER | None = None,
4145
) -> PyProjectData:
4246
if _load_toml is None:
43-
_load_toml = lazy_tomli_load
47+
_load_toml = lazy_toml_load
4448
with open(name, encoding="UTF-8") as strm:
4549
data = strm.read()
4650
defn = _load_toml(data)

testing/test_integration.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ def wd(wd: WorkDir) -> WorkDir:
2424

2525

2626
def test_pyproject_support(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
27-
pytest.importorskip("tomli")
27+
if sys.version_info <= (3, 10):
28+
pytest.importorskip("tomli")
2829
monkeypatch.delenv("SETUPTOOLS_SCM_DEBUG")
2930
pkg = tmp_path / "package"
3031
pkg.mkdir()
@@ -83,7 +84,8 @@ def test_pyproject_support(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> N
8384

8485
@with_metadata_in
8586
def test_pyproject_support_with_git(wd: WorkDir, metadata_in: str) -> None:
86-
pytest.importorskip("tomli")
87+
if sys.version_info <= (3, 10):
88+
pytest.importorskip("tomli")
8789
wd.write("pyproject.toml", PYPROJECT_FILES[metadata_in])
8890
wd.write("setup.py", SETUP_PY_FILES[metadata_in])
8991
wd.write("setup.cfg", SETUP_CFG_FILES[metadata_in])

tox.ini

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[tox]
2-
envlist=py{37,38,39,310}-{test,selfcheck},check_readme,check-dist,check-bootstrap
2+
envlist=py{37,38,39,310,311}-{test,selfcheck},check_readme,check-dist,check-bootstrap
33

44
[pytest]
55
testpaths=testing
@@ -27,7 +27,6 @@ skip_install=
2727
deps=
2828
pytest
2929
setuptools >= 45
30-
tomli
3130
virtualenv>20
3231
typing_extensions
3332
commands=

0 commit comments

Comments
 (0)