Skip to content

Commit d37868e

Browse files
committed
Emit warning if the documentation cannot be found for a given project.
1 parent e316c93 commit d37868e

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

seed_intersphinx_mapping/core.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import functools
3131
import json
3232
import re
33+
import warnings
3334
from typing import Any, Dict, Optional, Pattern, Tuple, Union
3435

3536
# 3rd party
@@ -141,12 +142,12 @@ def seed_intersphinx_mapping(base_dir: PathLike) -> Dict[str, Tuple[str, Optiona
141142
try:
142143
doc_url = get_sphinx_doc_url(project_name)
143144
intersphinx_mapping[project_name] = (doc_url, None)
144-
except ValueError:
145+
except (ValueError, requests.exceptions.ConnectionError):
145146
# Couldn't get it from PyPI, trying fallback mapping
146147
if project_name in fallback_mapping():
147148
doc_url = fallback_mapping()[project_name]
148149
intersphinx_mapping[project_name] = (doc_url, None)
149-
# TODO: perhaps emit warning?
150-
# TODO: handle user being offline
150+
else:
151+
warnings.warn(f"Unable to determine documentation url for project {project_name}")
151152

152153
return intersphinx_mapping

tests/test_seeding.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,7 @@
2626
)
2727
def test_seed_intersphinx_mapping(tmpdir, contents, expects):
2828
(PathPlus(tmpdir) / "requirements.txt").write_text(contents)
29-
assert seed_intersphinx_mapping(tmpdir) == expects
29+
30+
with pytest.warns(UserWarning) as w:
31+
assert seed_intersphinx_mapping(tmpdir) == expects
32+
assert len(w) == 1

0 commit comments

Comments
 (0)