Skip to content

Commit 58b8caf

Browse files
committed
Remove unused code from Link
1 parent 8379c76 commit 58b8caf

File tree

2 files changed

+3
-138
lines changed

2 files changed

+3
-138
lines changed

src/poetry/core/packages/utils/link.py

+2-65
Original file line numberDiff line numberDiff line change
@@ -4,62 +4,27 @@
44
import re
55
import urllib.parse as urlparse
66

7-
from typing import Any
8-
97
from poetry.core.packages.utils.utils import path_to_url
108
from poetry.core.packages.utils.utils import splitext
119

1210

1311
class Link:
14-
def __init__(
15-
self,
16-
url: str,
17-
comes_from: Any | None = None,
18-
requires_python: str | None = None,
19-
metadata: str | bool | None = None,
20-
) -> None:
12+
def __init__(self, url: str) -> None:
2113
"""
2214
Object representing a parsed link from https://pypi.python.org/simple/*
2315
2416
url:
2517
url of the resource pointed to (href of the link)
26-
comes_from:
27-
instance of HTMLPage where the link was found, or string.
28-
requires_python:
29-
String containing the `Requires-Python` metadata field, specified
30-
in PEP 345. This may be specified by a data-requires-python
31-
attribute in the HTML link tag, as described in PEP 503.
32-
metadata:
33-
String of the syntax `<hashname>=<hashvalue>` representing the hash
34-
of the Core Metadata file. This may be specified by a
35-
data-dist-info-metadata attribute in the HTML link tag, as described
36-
in PEP 658.
3718
"""
3819

3920
# url can be a UNC windows share
4021
if url.startswith("\\\\"):
4122
url = path_to_url(url)
4223

4324
self.url = url
44-
self.comes_from = comes_from
45-
self.requires_python = requires_python if requires_python else None
46-
47-
if isinstance(metadata, str):
48-
metadata = {"true": True, "": False, "false": False}.get(
49-
metadata.strip().lower(), metadata
50-
)
51-
52-
self._metadata = metadata
5325

5426
def __str__(self) -> str:
55-
if self.requires_python:
56-
rp = f" (requires-python:{self.requires_python})"
57-
else:
58-
rp = ""
59-
if self.comes_from:
60-
return f"{self.url} (from {self.comes_from}){rp}"
61-
else:
62-
return str(self.url)
27+
return str(self.url)
6328

6429
def __repr__(self) -> str:
6530
return f"<Link {self!s}>"
@@ -149,34 +114,6 @@ def subdirectory_fragment(self) -> str | None:
149114

150115
_hash_re = re.compile(r"(sha1|sha224|sha384|sha256|sha512|md5)=([a-f0-9]+)")
151116

152-
@property
153-
def has_metadata(self) -> bool:
154-
if self._metadata is None:
155-
return False
156-
return bool(self._metadata) and (self.is_wheel or self.is_sdist)
157-
158-
@property
159-
def metadata_url(self) -> str | None:
160-
if self.has_metadata:
161-
return f"{self.url_without_fragment.split('?', 1)[0]}.metadata"
162-
return None
163-
164-
@property
165-
def metadata_hash(self) -> str | None:
166-
if self.has_metadata and isinstance(self._metadata, str):
167-
match = self._hash_re.search(self._metadata)
168-
if match:
169-
return match.group(2)
170-
return None
171-
172-
@property
173-
def metadata_hash_name(self) -> str | None:
174-
if self.has_metadata and isinstance(self._metadata, str):
175-
match = self._hash_re.search(self._metadata)
176-
if match:
177-
return match.group(1)
178-
return None
179-
180117
@property
181118
def hash(self) -> str | None:
182119
match = self._hash_re.search(self.url)

tests/packages/utils/test_utils_link.py

+1-73
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,11 @@ def file_checksum() -> str:
1818
return make_checksum()
1919

2020

21-
@pytest.fixture()
22-
def metadata_checksum() -> str:
23-
return make_checksum()
24-
25-
26-
def make_url(
27-
ext: str, file_checksum: str | None = None, metadata_checksum: str | None = None
28-
) -> Link:
21+
def make_url(ext: str, file_checksum: str | None = None) -> Link:
2922
file_checksum = file_checksum or make_checksum()
3023
return Link(
3124
"https://files.pythonhosted.org/packages/16/52/dead/"
3225
f"demo-1.0.0.{ext}#sha256={file_checksum}",
33-
metadata=f"sha256={metadata_checksum}" if metadata_checksum else None,
3426
)
3527

3628

@@ -40,12 +32,6 @@ def test_package_link_hash(file_checksum: str) -> None:
4032
assert link.hash == file_checksum
4133
assert link.show_url == "demo-1.0.0.whl"
4234

43-
# this is legacy PEP 503, no metadata hash is present
44-
assert not link.has_metadata
45-
assert not link.metadata_url
46-
assert not link.metadata_hash
47-
assert not link.metadata_hash_name
48-
4935

5036
@pytest.mark.parametrize(
5137
("ext", "check"),
@@ -60,61 +46,3 @@ def test_package_link_hash(file_checksum: str) -> None:
6046
def test_package_link_is_checks(ext: str, check: str) -> None:
6147
link = make_url(ext=ext)
6248
assert getattr(link, f"is_{check}")
63-
64-
65-
@pytest.mark.parametrize(
66-
("ext", "has_metadata"),
67-
[("whl", True), ("egg", False), ("tar.gz", True), ("zip", True)],
68-
)
69-
def test_package_link_pep658(
70-
ext: str, has_metadata: bool, metadata_checksum: str
71-
) -> None:
72-
link = make_url(ext=ext, metadata_checksum=metadata_checksum)
73-
74-
if has_metadata:
75-
assert link.has_metadata
76-
assert link.metadata_url == f"{link.url_without_fragment}.metadata"
77-
assert link.metadata_hash == metadata_checksum
78-
assert link.metadata_hash_name == "sha256"
79-
else:
80-
assert not link.has_metadata
81-
assert not link.metadata_url
82-
assert not link.metadata_hash
83-
assert not link.metadata_hash_name
84-
85-
86-
def test_package_link_pep658_no_default_metadata() -> None:
87-
link = make_url(ext="whl")
88-
89-
assert not link.has_metadata
90-
assert not link.metadata_url
91-
assert not link.metadata_hash
92-
assert not link.metadata_hash_name
93-
94-
95-
@pytest.mark.parametrize(
96-
("metadata", "has_metadata"),
97-
[
98-
("true", True),
99-
("false", False),
100-
("", False),
101-
],
102-
)
103-
def test_package_link_pep653_non_hash_metadata_value(
104-
file_checksum: str, metadata: str | bool, has_metadata: bool
105-
) -> None:
106-
link = Link(
107-
"https://files.pythonhosted.org/packages/16/52/dead/"
108-
f"demo-1.0.0.whl#sha256={file_checksum}",
109-
metadata=metadata,
110-
)
111-
112-
if has_metadata:
113-
assert link.has_metadata
114-
assert link.metadata_url == f"{link.url_without_fragment}.metadata"
115-
else:
116-
assert not link.has_metadata
117-
assert not link.metadata_url
118-
119-
assert not link.metadata_hash
120-
assert not link.metadata_hash_name

0 commit comments

Comments
 (0)