-
Notifications
You must be signed in to change notification settings - Fork 135
Improve test_docs pre-check with Intersphinx URLs #419
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
lola831
wants to merge
5
commits into
BerkeleyLearnVerify:main
Choose a base branch
from
lola831:fix-docs-ci-intersphinx
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ff17187
Check intersphinx inventories before building docs
lola831 d6c0f4d
Ignore 403 intersphinx responses; skip only on network failures
lola831 fb41ac0
Simplify Intersphinx connectivity check for docs build
lola831 fee1792
simplify docs connectivity check
lola831 356686a
Address PR review comments
lola831 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| """Shared Intersphinx configuration for Scenic's documentation. | ||
|
|
||
| This module defines ``intersphinx_mapping``, which is imported from | ||
| ``docs/conf.py`` and reused from ``tests/test_docs.py`` to check | ||
| connectivity to all configured external documentation sites. | ||
| """ | ||
|
|
||
| intersphinx_mapping = { | ||
| "python": ("https://docs.python.org/3", None), | ||
| "matplotlib": ("https://matplotlib.org/stable/", None), | ||
| "numpy": ("https://numpy.org/doc/stable/", None), | ||
| "scipy": ("https://docs.scipy.org/doc/scipy/", None), | ||
| "sphinx": ("https://www.sphinx-doc.org/en/master/", None), | ||
| "pytest": ("https://docs.pytest.org/en/stable/", None), | ||
| "trimesh": ("https://trimesh.org/", None), | ||
| } | ||
|
|
||
|
|
||
| def iter_intersphinx_urls(): | ||
| """Yield the base URLs from the mapping.""" | ||
| for base_url, _ in intersphinx_mapping.values(): | ||
| yield base_url |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,28 +1,47 @@ | ||
| import os | ||
| import socket | ||
| import subprocess | ||
| from urllib.error import URLError | ||
| from urllib.request import Request, urlopen | ||
|
|
||
| import pytest | ||
|
|
||
| from docs.intersphinx_config import iter_intersphinx_urls | ||
|
|
||
| pytest.importorskip("sphinx") | ||
|
|
||
|
|
||
| def _check_intersphinx_connectivity(timeout=10.0): | ||
| """Check that Intersphinx sites are reachable before building docs.""" | ||
| problems = [] | ||
|
|
||
| for url in iter_intersphinx_urls(): | ||
| # Some docs hosts don't like the default Python-urllib user-agent. | ||
| req = Request(url, headers={"User-Agent": "Mozilla/5.0"}) | ||
| try: | ||
| with urlopen(req, timeout=timeout): | ||
| pass | ||
| except (URLError, TimeoutError) as e: | ||
| # We've seen slow HTTPS responses raise a bare TimeoutError from the | ||
| # SSL layer instead of being wrapped in URLError, so catch both here | ||
| # to avoid flaky failures when docs hosts are slow or unresponsive. | ||
| problems.append(f"{url} ({e})") | ||
|
|
||
| if problems: | ||
| pytest.skip( | ||
| "Some Intersphinx sites are not reachable; skipping docs build:\n" | ||
| + "\n".join(problems) | ||
| ) | ||
|
|
||
|
|
||
| @pytest.mark.slow | ||
| def test_build_docs(): | ||
| """Test that the documentation builds, and run doctests. | ||
| We do this in a subprocess since the Sphinx configuration file activates the veneer | ||
| and has other side-effects that aren't reset afterward. | ||
| """ | ||
| try: | ||
| socket.getaddrinfo("docs.python.org", 80) | ||
| except OSError: | ||
| pytest.skip("cannot connect to python.org for Intersphinx") | ||
| """Test that the documentation builds and doctests pass.""" | ||
| _check_intersphinx_connectivity() | ||
|
|
||
| oldDirectory = os.getcwd() | ||
| old_directory = os.getcwd() | ||
lola831 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| try: | ||
| os.chdir("docs") | ||
| subprocess.run(["make", "clean", "html", "SPHINXOPTS=-W"], check=True) | ||
| subprocess.run(["make", "doctest", "SPHINXOPTS=-W"], check=True) | ||
| finally: | ||
| os.chdir(oldDirectory) | ||
| os.chdir(old_directory) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.