Skip to content

Commit e39d5d8

Browse files
committed
Pre-compile the regular expression, and set a timeout for the HTTP Requests
1 parent 06a7486 commit e39d5d8

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
apeye>=1.0.0
2-
cawdrey>=0.4.2
32
domdf-python-tools>=2.8.0
43
packaging>=20.9
54
requests>=2.24.0

seed_intersphinx_mapping/__init__.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,12 @@
3333
# stdlib
3434
import functools
3535
import json
36+
import re
3637
from typing import Dict, Optional, Tuple, Union
3738

3839
# 3rd party
3940
import requests
40-
from cawdrey.utils import search_dict
41+
from apeye.requests_url import RequestsURL
4142
from domdf_python_tools.compat import importlib_resources
4243
from domdf_python_tools.utils import stderr_writer
4344
from packaging.requirements import Requirement
@@ -55,6 +56,8 @@
5556

5657
__all__ = ["get_sphinx_doc_url", "fallback_mapping", "seed_intersphinx_mapping"]
5758

59+
_DOCUMENTATION_RE = re.compile(r"^[dD]oc(s|umentation)")
60+
5861

5962
@cache
6063
def get_sphinx_doc_url(pypi_name: str) -> str:
@@ -88,12 +91,12 @@ def get_sphinx_doc_url(pypi_name: str) -> str:
8891
:exc:`apeye.slumber_url.exceptions.HttpNotFoundError` if the project could not be found on PyPI.
8992
"""
9093

91-
docs_dict = search_dict(get_project_links(pypi_name), r"^[dD]oc(s|umentation)")
92-
93-
if docs_dict:
94+
for key, value in get_project_links(pypi_name).items():
95+
if not _DOCUMENTATION_RE.match(key):
96+
continue
9497

9598
# Follow redirects to get actual URL
96-
r = requests.head(list(docs_dict.values())[0], allow_redirects=True, timeout=10)
99+
r = RequestsURL(value).head(allow_redirects=True, timeout=10)
97100
if r.status_code != 200: # pragma: no cover
98101
raise ValueError(f"Documentation URL not found: HTTP Status {r.status_code}.")
99102

0 commit comments

Comments
 (0)