Skip to content

Commit 788358d

Browse files
committed
Minor nits
1 parent 9adf8e1 commit 788358d

2 files changed

Lines changed: 16 additions & 15 deletions

File tree

seed_intersphinx_mapping/__init__.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,13 @@
3535
import json
3636
import os.path
3737
import re
38-
from typing import Dict, List, Optional, Tuple, Union
38+
from typing import Dict, Optional, Tuple, Union
3939
from urllib.parse import urlparse
4040

4141
# 3rd party
4242
import dist_meta
4343
import requests
44+
from dist_meta.metadata_mapping import MetadataMapping
4445
from domdf_python_tools.compat import importlib_resources
4546
from domdf_python_tools.utils import stderr_writer
4647
from packaging.requirements import Requirement
@@ -61,7 +62,7 @@
6162
_DOCUMENTATION_RE = re.compile(r"^[dD]oc(s|umentation)")
6263

6364

64-
def _get_project_links(project_name: str) -> List[str]:
65+
def _get_project_links(project_name: str) -> MetadataMapping:
6566
"""
6667
Returns the web links for the given project.
6768
@@ -70,7 +71,7 @@ def _get_project_links(project_name: str) -> List[str]:
7071
:param project_name:
7172
"""
7273

73-
urls = []
74+
urls = MetadataMapping()
7475

7576
# Try a local package first
7677
try:
@@ -79,27 +80,25 @@ def _get_project_links(project_name: str) -> List[str]:
7980
raw_urls = metadata.get_all("Project-URL", default=())
8081

8182
for url in raw_urls:
82-
label, url = url.split(',', 1)
83+
label, url = map(str.strip, url.split(',', 1))
8384
if _DOCUMENTATION_RE.match(label):
84-
urls.append(url)
85+
urls[label] = url
8586

86-
urls.append(metadata.get("Home-Page", ''))
87+
urls["Home-Page"] = metadata.get("Home-Page", '')
8788

8889
except dist_meta.distributions.DistributionNotFoundError:
8990
# Fall back to PyPI
9091

9192
with PyPIJSON() as client:
9293
pypi_metadata = client.get_metadata(project_name).info
9394

94-
if "project_urls" in pypi_metadata and pypi_metadata["project_urls"]:
95+
if "project_urls" in pypi_metadata and pypi_metadata["project_urls"]:
96+
for label, url in pypi_metadata["project_urls"].items():
97+
if _DOCUMENTATION_RE.match(label):
98+
urls[label] = url
9599

96-
for label, url in pypi_metadata["project_urls"].items():
97-
if _DOCUMENTATION_RE.match(label):
98-
urls.append(url)
100+
urls["Homepage"] = pypi_metadata.get("home_page", '')
99101

100-
urls.append(pypi_metadata["home_page"])
101-
102-
urls = [url.strip() for url in filter(None, urls)]
103102
return urls
104103

105104

@@ -136,7 +135,10 @@ def get_sphinx_doc_url(pypi_name: str) -> str:
136135
"""
137136

138137
docs_urls = []
139-
for value in _get_project_links(pypi_name):
138+
for value in _get_project_links(pypi_name).values():
139+
if not value:
140+
continue
141+
140142
# Follow redirects to get actual URL
141143
r = requests.head(value, allow_redirects=True, timeout=10)
142144

tests/test_seeding.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ def test_sphinx_seed_intersphinx_mapping_mocked(
125125
advanced_data_regression.check(config.intersphinx_mapping)
126126

127127
err = capsys.readouterr().err
128-
129128
assert err.endswith("WARNING: Unable to determine documentation url for project sphinxcontrib-domaintools\n")
130129

131130

0 commit comments

Comments
 (0)