| 1 |
import os |
| 2 |
import shutil |
| 3 |
import sys |
| 4 |
from pathlib import Path |
| 5 |
|
| 6 |
import click |
| 7 |
from spin import util |
| 8 |
from spin.cmds import meson |
| 9 |
|
| 10 |
|
| 11 |
@click.command() |
| 12 |
@click.option( |
| 13 |
"--build-dir", |
| 14 |
default="build", |
| 15 |
help="Build directory; default is `$PWD/build`" |
| 16 |
) |
| 17 |
@click.option( |
| 18 |
"--clean", |
| 19 |
is_flag=True, |
| 20 |
help="Clean previously built docs before building" |
| 21 |
) |
| 22 |
def docs(build_dir, clean=False): |
| 23 |
""" |
| 24 |
📖 Build documentation |
| 25 |
""" |
| 26 |
if clean: |
| 27 |
doc_dir = Path("./doc/build").absolute() |
| 28 |
if doc_dir.is_dir(): |
| 29 |
print(f"Removing `{doc_dir}`") |
| 30 |
shutil.rmtree(doc_dir) |
| 31 |
|
| 32 |
site_path = meson._get_site_packages() |
| 33 |
if site_path is None: |
| 34 |
print("No built scikit-misc found; run `./spin build` first.") |
| 35 |
sys.exit(1) |
| 36 |
|
| 37 |
util.run(["pip", "install", "-q", "-r", "requirements/docs.txt"]) |
| 38 |
|
| 39 |
PYTHONPATH = os.environ.get("PYTHONPATH", "") |
| 40 |
os.environ["SPHINXOPTS"] = "-W" |
| 41 |
os.environ['PYTHONPATH'] = f'{site_path}{os.sep}:{PYTHONPATH}' |
| 42 |
util.run(["make", "-C", "doc", "html"], replace=True) |
| 43 |
|
| 44 |
|
| 45 |
@click.command() |
| 46 |
@click.option( |
| 47 |
"--build-dir", |
| 48 |
default="build", |
| 49 |
help="Build directory; default is `$PWD/build`" |
| 50 |
) |
| 51 |
def coverage(build_dir): |
| 52 |
""" |
| 53 |
📊 Generate coverage report |
| 54 |
""" |
| 55 |
site_path = meson._get_site_packages() |
| 56 |
util.run([ |
| 57 |
"python", |
| 58 |
"-m", |
| 59 |
"coverage", |
| 60 |
"report", |
| 61 |
"--data-file", |
| 62 |
f"{site_path}/.coverage", |
| 63 |
], replace=True) |
| 64 |
|
| 65 |
|
| 66 |
@click.command() |
| 67 |
@click.option( |
| 68 |
"--build-dir", |
| 69 |
default="build", |
| 70 |
help="Build directory; default is `$PWD/build`" |
| 71 |
) |
| 72 |
def coverage_html(build_dir): |
| 73 |
""" |
| 74 |
📊 Generate HTML coverage report |
| 75 |
""" |
| 76 |
site_path = meson._get_site_packages() |
| 77 |
util.run([ |
| 78 |
"python", |
| 79 |
"-m", |
| 80 |
"coverage", |
| 81 |
"html", |
| 82 |
"--data-file", |
| 83 |
f"{site_path}/.coverage", |
| 84 |
], replace=True) |
| 85 |
|
| 86 |
|
| 87 |
@click.command() |
| 88 |
def sdist(): |
| 89 |
""" |
| 90 |
📦 Build a source distribution in `build/meson-dist/`. |
| 91 |
""" |
| 92 |
|
| 93 |
|
| 94 |
util.run([ |
| 95 |
"python", |
| 96 |
"-m", |
| 97 |
"build", |
| 98 |
"--no-isolation", |
| 99 |
"--skip-dependency-check", |
| 100 |
"--sdist", |
| 101 |
".", |
| 102 |
], replace=True) |