Skip to content

Fix new dependency-groups feature to use the stdlib tomllib where possible #13356

New issue

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

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

Already on GitHub? # to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions news/13356.vendor.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix issues with using tomllib from the stdlib if available, rather than tomli
11 changes: 8 additions & 3 deletions src/pip/_internal/req/req_dependency_group.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import sys
from typing import Any, Dict, Iterable, Iterator, List, Tuple

from pip._vendor import tomli
if sys.version_info >= (3, 11):
import tomllib
else:
from pip._vendor import tomli as tomllib

from pip._vendor.dependency_groups import DependencyGroupResolver

from pip._internal.exceptions import InstallationError
Expand Down Expand Up @@ -65,10 +70,10 @@ def _load_pyproject(path: str) -> Dict[str, Any]:
"""
try:
with open(path, "rb") as fp:
return tomli.load(fp)
return tomllib.load(fp)
except FileNotFoundError:
raise InstallationError(f"{path} not found. Cannot resolve '--group' option.")
except tomli.TOMLDecodeError as e:
except tomllib.TOMLDecodeError as e:
raise InstallationError(f"Error parsing {path}: {e}") from e
except OSError as e:
raise InstallationError(f"Error reading {path}: {e}") from e
2 changes: 1 addition & 1 deletion tests/unit/test_req_dependency_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def epipe_toml_load(*args: Any, **kwargs: Any) -> None:
raise OSError(errno.EPIPE, "Broken pipe")

monkeypatch.setattr(
"pip._internal.req.req_dependency_group.tomli.load", epipe_toml_load
"pip._internal.req.req_dependency_group.tomllib.load", epipe_toml_load
)

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