| 1 |
#!/usr/bin/env python3 |
| 2 |
from __future__ import annotations |
| 3 |
|
| 4 |
import shutil |
| 5 |
import subprocess |
| 6 |
from pathlib import Path |
| 7 |
|
| 8 |
SPHINX_ROOT = Path(__file__).resolve().parent.parent |
| 9 |
TEST_JS_FIXTURES = SPHINX_ROOT / 'tests' / 'js' / 'fixtures' |
| 10 |
TEST_JS_ROOTS = [ |
| 11 |
directory |
| 12 |
for directory in (SPHINX_ROOT / 'tests' / 'js' / 'roots').iterdir() |
| 13 |
if (directory / 'conf.py').exists() |
| 14 |
] |
| 15 |
|
| 16 |
|
| 17 |
def build(srcdir: Path) -> None: |
| 18 |
cmd = ( |
| 19 |
'sphinx-build', |
| 20 |
'--fresh-env', |
| 21 |
'--quiet', |
| 22 |
*('--builder', 'html'), |
| 23 |
f'{srcdir}', |
| 24 |
f'{srcdir}/_build', |
| 25 |
) |
| 26 |
subprocess.run(cmd, check=True, capture_output=True) |
| 27 |
|
| 28 |
|
| 29 |
for directory in TEST_JS_ROOTS: |
| 30 |
searchindex = directory / '_build' / 'searchindex.js' |
| 31 |
destination = TEST_JS_FIXTURES / directory.name / 'searchindex.js' |
| 32 |
|
| 33 |
print(f'Building {directory} ... ', end='') |
| 34 |
build(directory) |
| 35 |
print('done') |
| 36 |
|
| 37 |
print(f'Copying {searchindex} to {destination} ... ', end='') |
| 38 |
destination.parent.mkdir(exist_ok=True, parents=True) |
| 39 |
shutil.copy2(searchindex, destination) |
| 40 |
print('done') |