|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
3 | 3 | import optparse |
4 | | -import os.path |
5 | 4 | import pathlib |
6 | | -import sys |
7 | 5 | import urllib.parse |
8 | 6 | from dataclasses import dataclass |
9 | 7 | from typing import TYPE_CHECKING, Callable, Iterable, Iterator, Set, cast |
|
20 | 18 | from pip._internal.req.constructors import install_req_from_parsed_requirement |
21 | 19 | from pip._vendor.pkg_resources import Requirement |
22 | 20 |
|
| 21 | +from .path_compat import relative_to_walk_up |
| 22 | + |
23 | 23 | # The Distribution interface has changed between pkg_resources and |
24 | 24 | # importlib.metadata, so this compat layer allows for a consistent access |
25 | 25 | # pattern. In pip 22.1, importlib.metadata became the default on Python 3.11 |
@@ -154,7 +154,7 @@ def _relativize_comes_from_location(original_comes_from: str, /) -> str: |
154 | 154 | return f"{prefix} {file_path.as_posix()}" |
155 | 155 |
|
156 | 156 | # make it relative to the current working dir |
157 | | - suffix = _relative_to_walk_up(file_path, pathlib.Path.cwd()).as_posix() |
| 157 | + suffix = relative_to_walk_up(file_path, pathlib.Path.cwd()).as_posix() |
158 | 158 | return f"{prefix}{space_sep}{suffix}" |
159 | 159 |
|
160 | 160 |
|
@@ -212,18 +212,3 @@ def get_dev_pkgs() -> set[str]: |
212 | 212 | from pip._internal.commands.freeze import _dev_pkgs |
213 | 213 |
|
214 | 214 | return cast(Set[str], _dev_pkgs()) |
215 | | - |
216 | | - |
217 | | -def _relative_to_walk_up(path: pathlib.Path, start: pathlib.Path) -> pathlib.Path: |
218 | | - """ |
219 | | - Compute a relative path allowing for the input to not be a subpath of the start. |
220 | | -
|
221 | | - This is a compatibility helper for ``pathlib.Path.relative_to(..., walk_up=True)`` |
222 | | - on all Python versions. (``walk_up: bool`` is Python 3.12+) |
223 | | - """ |
224 | | - # prefer `pathlib.Path.relative_to` where available |
225 | | - if sys.version_info >= (3, 12): |
226 | | - return path.relative_to(start, walk_up=True) |
227 | | - |
228 | | - str_result = os.path.relpath(path, start=start) |
229 | | - return pathlib.Path(str_result) |
0 commit comments