|
2 | 2 |
|
3 | 3 | import optparse |
4 | 4 | import pathlib |
| 5 | +import urllib.parse |
5 | 6 | from dataclasses import dataclass |
6 | 7 | from typing import TYPE_CHECKING, Callable, Iterable, Iterator, Set, cast |
7 | 8 |
|
@@ -140,6 +141,10 @@ def _relativize_comes_from_location(original_comes_from: str, /) -> str: |
140 | 141 | # split on the space |
141 | 142 | prefix, space_sep, suffix = original_comes_from.partition(" ") |
142 | 143 |
|
| 144 | + # if the value part is a remote URI for pip, return the original |
| 145 | + if _is_remote_pip_uri(suffix): |
| 146 | + return original_comes_from |
| 147 | + |
143 | 148 | file_path = pathlib.Path(suffix) |
144 | 149 |
|
145 | 150 | # if the path was not absolute, normalize to posix-style and finish processing |
@@ -169,11 +174,26 @@ def _normalize_comes_from_location(original_comes_from: str, /) -> str: |
169 | 174 | # split on the space |
170 | 175 | prefix, space_sep, suffix = original_comes_from.partition(" ") |
171 | 176 |
|
| 177 | + # if the value part is a remote URI for pip, return the original |
| 178 | + if _is_remote_pip_uri(suffix): |
| 179 | + return original_comes_from |
| 180 | + |
172 | 181 | # convert to a posix-style path |
173 | 182 | suffix = pathlib.Path(suffix).as_posix() |
174 | 183 | return f"{prefix}{space_sep}{suffix}" |
175 | 184 |
|
176 | 185 |
|
| 186 | +def _is_remote_pip_uri(value: str) -> bool: |
| 187 | + """ |
| 188 | + Test a string to see if it is a URI treated as a remote file in ``pip``. |
| 189 | + Specifically this means that it's a 'file', 'http', or 'https' URI. |
| 190 | +
|
| 191 | + The test is performed by trying a URL parse and reading the scheme. |
| 192 | + """ |
| 193 | + scheme = urllib.parse.urlsplit(value).scheme |
| 194 | + return scheme in {"file", "http", "https"} |
| 195 | + |
| 196 | + |
177 | 197 | def create_wheel_cache(cache_dir: str, format_control: str | None = None) -> WheelCache: |
178 | 198 | kwargs: dict[str, str | None] = {"cache_dir": cache_dir} |
179 | 199 | if PIP_VERSION[:2] <= (23, 0): |
|
0 commit comments