Skip to content

Commit 4a4959c

Browse files
committed
Fix URL for requests documentation when retreived from cache.
1 parent f4cbb28 commit 4a4959c

8 files changed

+17
-12
lines changed

seed_intersphinx_mapping/__init__.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
The functions formerly in ``seed_intersphinx_mapping.core`` can now be found here.
1010
"""
1111
#
12-
# Copyright © 2020-2021 Dominic Davis-Foster <dominic@davis-foster.co.uk>
12+
# Copyright © 2020-2022 Dominic Davis-Foster <dominic@davis-foster.co.uk>
1313
#
1414
# Permission is hereby granted, free of charge, to any person obtaining a copy
1515
# of this software and associated documentation files (the "Software"), to deal
@@ -39,7 +39,6 @@
3939
# 3rd party
4040
import dist_meta
4141
import requests
42-
from apeye.requests_url import RequestsURL
4342
from dist_meta.metadata_mapping import MetadataMapping
4443
from domdf_python_tools.compat import importlib_resources
4544
from domdf_python_tools.utils import stderr_writer
@@ -101,7 +100,7 @@ def get_sphinx_doc_url(pypi_name: str) -> str:
101100
"""
102101
Returns the URL to the given project's Sphinx documentation.
103102
104-
Not all projects include this URL in their distributions
103+
Not all projects include this URL in their distributions,
105104
and therefore it may not be possible to determine it from PyPI.
106105
107106
Responses are cached to prevent overloading the PyPI server.
@@ -131,7 +130,7 @@ def get_sphinx_doc_url(pypi_name: str) -> str:
131130
for key, value in _get_project_links(pypi_name).items():
132131

133132
# Follow redirects to get actual URL
134-
r = RequestsURL(value).head(allow_redirects=True, timeout=10)
133+
r = requests.head(value, allow_redirects=True, timeout=10)
135134
if r.status_code != 200: # pragma: no cover
136135
raise ValueError(f"Documentation URL not found: HTTP Status {r.status_code}.")
137136

@@ -142,7 +141,7 @@ def get_sphinx_doc_url(pypi_name: str) -> str:
142141
else: # pragma: no cover
143142
objects_inv_url = f"{docs_url}/objects.inv"
144143

145-
r = requests.head(objects_inv_url)
144+
r = requests.head(objects_inv_url, allow_redirects=True, timeout=10)
146145
if r.status_code != 200:
147146
raise ValueError(f"objects.inv not found at url {objects_inv_url}: HTTP Status {r.status_code}.")
148147

@@ -184,6 +183,12 @@ def seed_intersphinx_mapping(*requirements: Union[Requirement, str]) -> Dict[str
184183

185184
try:
186185
doc_url = get_sphinx_doc_url(project_name)
186+
187+
if doc_url == "https://docs.python-requests.org/en/latest/":
188+
# Stale cached response from before the domain change
189+
cache.clear()
190+
doc_url = get_sphinx_doc_url(project_name)
191+
187192
intersphinx_mapping[project_name] = (doc_url, None)
188193
except (ValueError, requests.exceptions.ConnectionError, requests.exceptions.Timeout):
189194
# Couldn't get it from PyPI, trying fallback mapping

tests/test_integration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def test_integration(the_app):
2626
assert the_app.env.config.intersphinx_mapping == {
2727
"domdf-python-tools": ("domdf-python-tools", (domdf_python_tools_url, (None, ))),
2828
"packaging": ("packaging", ("https://packaging.pypa.io/en/latest/", (None, ))),
29-
"requests": ("requests", ("https://docs.python-requests.org/en/latest/", (None, ))),
29+
"requests": ("requests", ("https://requests.readthedocs.io/en/latest/", (None, ))),
3030
"pandas": ("pandas", ("https://pandas.pydata.org/pandas-docs/stable/", (None, ))),
3131
}
3232
assert the_app.env.config.pkg_requirements_source == "requirements"

tests/test_seeding.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"domdf-python-tools": ("https://domdf-python-tools.readthedocs.io/en/latest/", None),
2424
"numpy": ("https://numpy.org/doc/1.23/", None),
2525
"packaging": ("https://packaging.pypa.io/en/latest/", None),
26-
"requests": ("https://docs.python-requests.org/en/latest/", None),
26+
"requests": ("https://requests.readthedocs.io/en/latest/", None),
2727
"slumber": ("https://slumber.readthedocs.io/en/v0.6.0/", None),
2828
"sphinx": ("https://www.sphinx-doc.org/en/3.x/", None),
2929
}

tests/test_seeding_/test_sphinx_seed_intersphinx_mapping_list_mocked.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ packaging:
88
- - null
99
requests:
1010
- requests
11-
- - https://docs.python-requests.org/en/latest/
11+
- - https://requests.readthedocs.io/en/latest/
1212
- - null
1313
slumber:
1414
- slumber

tests/test_seeding_/test_sphinx_seed_intersphinx_mapping_mocked_example_requirements_a_flit_.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ packaging:
1212
- - null
1313
requests:
1414
- requests
15-
- - https://docs.python-requests.org/en/latest/
15+
- - https://requests.readthedocs.io/en/latest/
1616
- - null
1717
slumber:
1818
- slumber

tests/test_seeding_/test_sphinx_seed_intersphinx_mapping_mocked_example_requirements_a_pyproject_.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ packaging:
1212
- - null
1313
requests:
1414
- requests
15-
- - https://docs.python-requests.org/en/latest/
15+
- - https://requests.readthedocs.io/en/latest/
1616
- - null
1717
slumber:
1818
- slumber

tests/test_seeding_/test_sphinx_seed_intersphinx_mapping_mocked_example_requirements_a_pyproject_toml_.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ packaging:
1212
- - null
1313
requests:
1414
- requests
15-
- - https://docs.python-requests.org/en/latest/
15+
- - https://requests.readthedocs.io/en/latest/
1616
- - null
1717
slumber:
1818
- slumber

tests/test_seeding_/test_sphinx_seed_intersphinx_mapping_mocked_example_requirements_a_requirements_.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ packaging:
1212
- - null
1313
requests:
1414
- requests
15-
- - https://docs.python-requests.org/en/latest/
15+
- - https://requests.readthedocs.io/en/latest/
1616
- - null
1717
slumber:
1818
- slumber

0 commit comments

Comments
 (0)