Skip to content

Commit 54408d3

Browse files
authored
Merge pull request #13370 from sbidoul/tomllib-compat-sbi
DRY tomllib compatibility
2 parents af140b0 + 7be1d48 commit 54408d3

File tree

4 files changed

+10
-19
lines changed

4 files changed

+10
-19
lines changed

src/pip/_internal/pyproject.py

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,16 @@
11
import importlib.util
22
import os
3-
import sys
43
from collections import namedtuple
54
from typing import Any, List, Optional
65

7-
if sys.version_info >= (3, 11):
8-
import tomllib
9-
else:
10-
from pip._vendor import tomli as tomllib
11-
126
from pip._vendor.packaging.requirements import InvalidRequirement
137

148
from pip._internal.exceptions import (
159
InstallationError,
1610
InvalidPyProjectBuildRequires,
1711
MissingPyProjectBuildRequires,
1812
)
13+
from pip._internal.utils.compat import tomllib
1914
from pip._internal.utils.packaging import get_requirement
2015

2116

src/pip/_internal/req/req_dependency_group.py

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
1-
import sys
21
from typing import Any, Dict, Iterable, Iterator, List, Tuple
32

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

115
from pip._internal.exceptions import InstallationError
6+
from pip._internal.utils.compat import tomllib
127

138

149
def parse_dependency_groups(groups: List[Tuple[str, str]]) -> List[str]:

src/pip/_internal/utils/compat.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import sys
88
from typing import IO
99

10-
__all__ = ["get_path_uid", "stdlib_pkgs", "WINDOWS"]
10+
__all__ = ["get_path_uid", "stdlib_pkgs", "tomllib", "WINDOWS"]
1111

1212

1313
logger = logging.getLogger(__name__)
@@ -67,6 +67,12 @@ def open_text_resource(
6767
)
6868

6969

70+
if sys.version_info >= (3, 11):
71+
import tomllib
72+
else:
73+
from pip._vendor import tomli as tomllib
74+
75+
7076
# packages in the stdlib that may have installation metadata, but should not be
7177
# considered 'installed'. this theoretically could be determined based on
7278
# dist.location (py27:`sysconfig.get_paths()['stdlib']`,

tests/functional/test_lock.py

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
1-
import sys
21
import textwrap
32
from pathlib import Path
43

4+
from pip._internal.utils.compat import tomllib
55
from pip._internal.utils.urls import path_to_url
66

77
from ..lib import PipTestEnvironment, TestData
88

9-
if sys.version_info >= (3, 11):
10-
import tomllib
11-
else:
12-
from pip._vendor import tomli as tomllib
13-
149

1510
def test_lock_wheel_from_findlinks(
1611
script: PipTestEnvironment, shared_data: TestData, tmp_path: Path

0 commit comments

Comments
 (0)