|
3 | 3 | import shutil
|
4 | 4 | import sys
|
5 | 5 | from pathlib import Path
|
6 |
| -from subprocess import check_call |
| 6 | +from subprocess import call |
7 | 7 | from tempfile import TemporaryDirectory
|
8 | 8 |
|
9 | 9 | ROOT = Path(__file__).parent.parent
|
10 | 10 | DOCS = ROOT / "docs"
|
11 | 11 |
|
| 12 | +CHECK_INI = """ |
| 13 | +[pytest] |
| 14 | +addopts = |
| 15 | + --check-links |
| 16 | + -k "not ipynb {extra_k}" |
12 | 17 |
|
13 |
| -def docs(watch=False, check=False): |
| 18 | +junit_family = xunit2 |
| 19 | +
|
| 20 | +filterwarnings = |
| 21 | + ignore::PendingDeprecationWarning |
| 22 | +""" |
| 23 | + |
| 24 | + |
| 25 | +def docs(watch=False, check=False, local_only=False): |
14 | 26 | """ build (and test) docs.
|
15 | 27 |
|
16 | 28 | because readthedocs, this gets called twice from inside sphinx
|
17 | 29 | """
|
18 | 30 | if watch:
|
19 |
| - check_call(["sphinx-autobuild", ".", "_build"], cwd=DOCS) |
20 |
| - return 0 |
| 31 | + return call(["sphinx-autobuild", ".", "_build"], cwd=DOCS) |
21 | 32 |
|
22 |
| - if check: |
| 33 | + elif check: |
| 34 | + ini = CHECK_INI.format(extra_k="and not http" if local_only else "") |
23 | 35 | # do this in a temporary directory to avoid surprises
|
24 | 36 | with TemporaryDirectory() as td:
|
25 | 37 | tdp = Path(td)
|
26 | 38 | dest = tdp / "a" / "deep" / "path"
|
27 | 39 | dest.parent.mkdir(parents=True)
|
28 |
| - shutil.copytree(DOCS / "_build", dest) |
29 |
| - check_call(["pytest-check-links", "-vv", "-k", "not ipynb"], cwd=dest) |
| 40 | + shutil.copytree(DOCS / "_build" / "html", dest) |
| 41 | + (dest / "pytest.ini").write_text(ini) |
30 | 42 |
|
31 |
| - check_call(["sphinx-build", "-M", "html", ".", "_build"], cwd=DOCS) |
32 |
| - return 0 |
| 43 | + return call(["pytest"], cwd=dest) |
| 44 | + else: |
| 45 | + return call(["sphinx-build", "-M", "html", ".", "_build"], cwd=DOCS) |
33 | 46 |
|
34 | 47 |
|
35 | 48 | if __name__ == "__main__":
|
36 |
| - sys.exit(docs(watch="--watch" in sys.argv, check="--check" in sys.argv)) |
| 49 | + sys.exit( |
| 50 | + docs( |
| 51 | + watch="--watch" in sys.argv, |
| 52 | + check="--check" in sys.argv, |
| 53 | + local_only="--local-only" in sys.argv, |
| 54 | + ) |
| 55 | + ) |
0 commit comments