Skip to content

Commit

Permalink
Use the stdlib tomllib on python 3.11+
Browse files Browse the repository at this point in the history
Although a tomli copy is vendored, doing this conditional import allows:
- automatically upgrading the code, when the time comes to drop py3.10
  support

- slightly simplifying debundling support, as it's no longer necessary
  to depend on a tomli(-wheel)? package on sufficiently newer versions
  of python.
  • Loading branch information
eli-schwartz committed Jun 27, 2024
1 parent 47ffcdd commit 88c9f31
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions news/12797.vendor.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Use tomllib from the stdlib if available, rather than tomli
9 changes: 7 additions & 2 deletions src/pip/_internal/pyproject.py
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/pip/_vendor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

0 comments on commit 88c9f31

Please sign in to comment.