-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add autobuild script and instructions
- Loading branch information
Showing
2 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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,52 @@ | ||
import subprocess | ||
from pathlib import Path | ||
import os | ||
|
||
import click | ||
from livereload import Server | ||
|
||
@click.command() | ||
@click.argument("pathsource", default=".", type=Path) | ||
@click.option("-o", "--outputdir", default="_build/html", type=Path, show_default=True) | ||
@click.option("-p", "--port", default=8002, type=click.INT, show_default=True) | ||
def main(pathsource: Path, outputdir: Path, port: int): | ||
""" | ||
Script to serve a jupyter-book site, which rebuilds when files have | ||
changed and live-reloads the site. Basically `mkdocs serve` | ||
but for jupyter-book. Use by calling `python jb-serve.py [OPTIONS] [PATH_SOURCE]`. | ||
\b | ||
Args | ||
---- | ||
PATHSOURCE: Directory in `jb build <dir>` | ||
outputdir: Directory where HTML output is generated. `jb` defaults to `_build/html` | ||
port: Port to host the webserver. Default is 8002 | ||
\b | ||
Refs | ||
---- | ||
+ https://github.com/executablebooks/sphinx-autobuild/issues/99#issuecomment-722319104 | ||
+ mkdocs docs on github | ||
""" | ||
|
||
def build(): | ||
subprocess.run(["jb", "clean", pathsource]) | ||
subprocess.run(["jb", "build", pathsource]) | ||
|
||
# Build if not exists upon startup | ||
if not os.path.exists(outputdir): | ||
build() | ||
|
||
server = Server() | ||
|
||
# Globbing for all supported file types under jupyter-book | ||
# Ignore unrelated files | ||
server.watch(str(pathsource / "docs/*"), build) | ||
server.watch(str(pathsource / "images/*"), build) | ||
server.watch(str(pathsource / "_config.yml"), build) | ||
server.watch(str(pathsource / "_toc.yml"), build) | ||
|
||
server.serve(root=outputdir, port=port) | ||
|
||
if __name__ == "__main__": | ||
main() |