diff --git a/news/12797.vendor.rst b/news/12797.vendor.rst new file mode 100644 index 00000000000..7842883ddba --- /dev/null +++ b/news/12797.vendor.rst @@ -0,0 +1 @@ +Use tomllib from the stdlib if available, rather than tomli diff --git a/src/pip/_internal/pyproject.py b/src/pip/_internal/pyproject.py index 8de36b873ed..b9b9e3f19d9 100644 --- a/src/pip/_internal/pyproject.py +++ b/src/pip/_internal/pyproject.py @@ -1,9 +1,14 @@ import importlib.util import os +import sys from collections import namedtuple from typing import Any, List, Optional -from pip._vendor import tomli +if sys.version_info >= (3, 11): + import tomllib +else: + from pip._vendor import tomli as tomllib + from pip._vendor.packaging.requirements import InvalidRequirement, Requirement from pip._internal.exceptions import ( @@ -61,7 +66,7 @@ def load_pyproject_toml( if has_pyproject: with open(pyproject_toml, encoding="utf-8") as f: - pp_toml = tomli.loads(f.read()) + pp_toml = tomllib.loads(f.read()) build_system = pp_toml.get("build-system") else: build_system = None diff --git a/src/pip/_vendor/__init__.py b/src/pip/_vendor/__init__.py index 50537ab9de1..748622eaf19 100644 --- a/src/pip/_vendor/__init__.py +++ b/src/pip/_vendor/__init__.py @@ -111,6 +111,7 @@ def vendored(modulename): vendored("rich.text") vendored("rich.traceback") vendored("tenacity") - vendored("tomli") + if sys.version_info < (3, 11): + vendored("tomli") vendored("truststore") vendored("urllib3")