-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #461 from JaxGaussianProcesses/fix-doc-build
Update docs build process
- Loading branch information
Showing
54 changed files
with
218 additions
and
170 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 |
---|---|---|
|
@@ -29,7 +29,7 @@ jobs: | |
- name: Install Poetry | ||
uses: snok/[email protected] | ||
with: | ||
version: 1.4.0 | ||
version: 1.5.1 | ||
|
||
# Configure Poetry to use the virtual environment in the project | ||
- name: Setup Poetry | ||
|
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
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 |
---|---|---|
|
@@ -152,4 +152,4 @@ package-lock.json | |
node_modules/ | ||
|
||
docs/api | ||
docs/examples/*.md | ||
docs/_examples |
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 |
---|---|---|
@@ -1,20 +1,96 @@ | ||
""" Convert python files in "examples" directory to markdown files using jupytext and nbconvert. | ||
There's only a minor inconvenience with how supporting files are handled by nbconvert, | ||
see https://github.com/jupyter/nbconvert/issues/1164. But these will be under a private | ||
directory `_examples` in the docs folder, so it's not a big deal. | ||
""" | ||
from argparse import ArgumentParser | ||
from pathlib import Path | ||
import subprocess | ||
from concurrent.futures import ThreadPoolExecutor, as_completed | ||
import shutil | ||
|
||
EXCLUDE = ["utils.py"] | ||
|
||
EXECUTE = False | ||
EXCLUDE = ["docs/examples/utils.py"] | ||
ALLOW_ERRORS = False | ||
|
||
def process_file(file: Path, out_file: Path | None = None, execute: bool = False): | ||
"""Converts a python file to markdown using jupytext and nbconvert.""" | ||
|
||
for file in Path("docs/").glob("examples/*.py"): | ||
if file.as_posix() in EXCLUDE: | ||
continue | ||
out_dir = out_file.parent | ||
command = f"cd {out_dir.as_posix()} && " | ||
|
||
out_file = file.with_suffix(".md") | ||
out_file = out_file.relative_to(out_dir).as_posix() | ||
|
||
command = "jupytext --to markdown " | ||
command += f"{'--execute ' if EXECUTE else ''}" | ||
command += f"{'--allow-errors ' if ALLOW_ERRORS else ''}" | ||
command += f"{file} --output {out_file}" | ||
if execute: | ||
command += f"jupytext --to ipynb {file} --output - " | ||
command += ( | ||
f"| jupyter nbconvert --to markdown --execute --stdin --output {out_file}" | ||
) | ||
else: | ||
command = f"jupytext --to markdown {file} --output {out_file}" | ||
|
||
subprocess.run(command, shell=True, check=False) | ||
|
||
|
||
def is_modified(file: Path, out_file: Path): | ||
"""Check if the output file is older than the input file.""" | ||
return out_file.exists() and out_file.stat().st_mtime < file.stat().st_mtime | ||
|
||
|
||
def main(args): | ||
# project root directory | ||
wdir = Path(__file__).parents[2] | ||
|
||
# output directory | ||
out_dir: Path = args.outdir | ||
out_dir.mkdir(exist_ok=True, parents=True) | ||
|
||
# copy directories in "examples" to output directory | ||
for dir in wdir.glob("examples/*"): | ||
if dir.is_dir(): | ||
(out_dir / dir.name).mkdir(exist_ok=True, parents=True) | ||
for file in dir.glob("*"): | ||
# copy, not move! | ||
shutil.copy(file, out_dir / dir.name / file.name) | ||
|
||
# list of files to be processed | ||
files = [f for f in wdir.glob("examples/*.py") if f.name not in EXCLUDE] | ||
|
||
# process only modified files | ||
if args.only_modified: | ||
files = [f for f in files if is_modified(f, out_dir / f"{f.stem}.md")] | ||
|
||
print(files) | ||
|
||
# process files in parallel | ||
with ThreadPoolExecutor(max_workers=args.max_workers) as executor: | ||
futures = [] | ||
for file in files: | ||
out_file = out_dir / f"{file.stem}.md" | ||
futures.append( | ||
executor.submit( | ||
process_file, file, out_file=out_file, execute=args.execute | ||
) | ||
) | ||
|
||
for future in as_completed(futures): | ||
try: | ||
future.result() | ||
except Exception as e: | ||
print(f"Error processing file: {e}") | ||
|
||
|
||
if __name__ == "__main__": | ||
project_root = Path(__file__).parents[2] | ||
|
||
parser = ArgumentParser() | ||
parser.add_argument("--max_workers", type=int, default=4) | ||
parser.add_argument("--execute", action="store_true") | ||
parser.add_argument("--only_modified", action="store_true") | ||
parser.add_argument( | ||
"--outdir", type=Path, default=project_root / "docs" / "_examples" | ||
) | ||
args = parser.parse_args() | ||
|
||
main(args) |
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
File renamed without changes.
File renamed without changes
File renamed without changes
2 changes: 1 addition & 1 deletion
2
docs/_static/css/gpjax_theme.css → docs/static/css/gpjax_theme.css
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
nav .bd-links a:hover{ | ||
color: #B5121B | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes
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
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
Oops, something went wrong.