File: generate_js_fixtures.py

package info (click to toggle)
sphinx 9.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 28,732 kB
  • sloc: python: 109,394; javascript: 37,318; perl: 449; makefile: 183; sh: 37; xml: 19; ansic: 2
file content (40 lines) | stat: -rwxr-xr-x 1,071 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env python3
from __future__ import annotations

import shutil
import subprocess
from pathlib import Path

SPHINX_ROOT = Path(__file__).resolve().parent.parent
TEST_JS_FIXTURES = SPHINX_ROOT / 'tests' / 'js' / 'fixtures'
TEST_JS_ROOTS = [
    directory
    for directory in (SPHINX_ROOT / 'tests' / 'js' / 'roots').iterdir()
    if (directory / 'conf.py').exists()
]


def build(srcdir: Path) -> None:
    cmd = (
        'sphinx-build',
        '--fresh-env',
        '--quiet',
        *('--builder', 'html'),
        f'{srcdir}',
        f'{srcdir}/_build',
    )
    subprocess.run(cmd, check=True, capture_output=True)


for directory in TEST_JS_ROOTS:
    searchindex = directory / '_build' / 'searchindex.js'
    destination = TEST_JS_FIXTURES / directory.name / 'searchindex.js'

    print(f'Building {directory} ... ', end='')
    build(directory)
    print('done')

    print(f'Copying {searchindex} to {destination} ... ', end='')
    destination.parent.mkdir(exist_ok=True, parents=True)
    shutil.copy2(searchindex, destination)
    print('done')