Skip to content

Commit b7e3aea

Browse files
authored
Merge pull request #13356 from eli-schwartz/tomllib
Fix new dependency-groups feature to use the stdlib tomllib where possible
2 parents 8c678fe + f3a4de5 commit b7e3aea

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

news/13356.vendor.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix issues with using tomllib from the stdlib if available, rather than tomli

src/pip/_internal/req/req_dependency_group.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1+
import sys
12
from typing import Any, Dict, Iterable, Iterator, List, Tuple
23

3-
from pip._vendor import tomli
4+
if sys.version_info >= (3, 11):
5+
import tomllib
6+
else:
7+
from pip._vendor import tomli as tomllib
8+
49
from pip._vendor.dependency_groups import DependencyGroupResolver
510

611
from pip._internal.exceptions import InstallationError
@@ -65,10 +70,10 @@ def _load_pyproject(path: str) -> Dict[str, Any]:
6570
"""
6671
try:
6772
with open(path, "rb") as fp:
68-
return tomli.load(fp)
73+
return tomllib.load(fp)
6974
except FileNotFoundError:
7075
raise InstallationError(f"{path} not found. Cannot resolve '--group' option.")
71-
except tomli.TOMLDecodeError as e:
76+
except tomllib.TOMLDecodeError as e:
7277
raise InstallationError(f"Error parsing {path}: {e}") from e
7378
except OSError as e:
7479
raise InstallationError(f"Error reading {path}: {e}") from e

tests/unit/test_req_dependency_group.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def epipe_toml_load(*args: Any, **kwargs: Any) -> None:
120120
raise OSError(errno.EPIPE, "Broken pipe")
121121

122122
monkeypatch.setattr(
123-
"pip._internal.req.req_dependency_group.tomli.load", epipe_toml_load
123+
"pip._internal.req.req_dependency_group.tomllib.load", epipe_toml_load
124124
)
125125

126126
with pytest.raises(InstallationError, match=r"Error reading pyproject\.toml"):

0 commit comments

Comments
 (0)