Created
July 9, 2024 09:36
-
-
Save Cadair/c67a05f4e3bd9b3c1a6acdc5ecc4d8de to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import urllib.request | |
from pathlib import Path | |
import nox | |
BUILD_DIR = Path("./.build") | |
def clone_or_pull(session, *, target_dir, url, ref): | |
# Clone or update sunpy | |
target_dir.mkdir(exist_ok=True, parents=True) | |
if not (target_dir / ".git").exists(): | |
session.run("git", "clone", "--branch", ref, url, target_dir, external=True) | |
else: | |
session.run("git", "-C", target_dir, "switch", ref, external=True) | |
session.run("git", "-C", target_dir, "pull", "origin", ref, external=True) | |
def doc2dash(session, docs_dir, *, name, icon=None, online_url): | |
args = [ | |
"--name", name, | |
"--destination", ".", | |
"--force", | |
"--verbose", | |
"--enable-js", | |
"--online-redirect-url", online_url, | |
] | |
if icon is not None: | |
args += ["--icon", icon] | |
session.run( | |
"doc2dash", | |
*args, | |
docs_dir, | |
) | |
@nox.session(python=["3.10"], reuse_venv=True) | |
def sunpy(session): | |
""" | |
Build the sunpy docs. | |
""" | |
sunpy_dir = BUILD_DIR / "sunpy" | |
clone_or_pull( | |
session, | |
target_dir=sunpy_dir, | |
url="[email protected]:sunpy/sunpy.git", | |
ref="main", | |
) | |
# Install packages | |
session.install("doc2dash") | |
session.install("-e", f"{sunpy_dir}[docs]") | |
docs = sunpy_dir / "docs" | |
docs_output = docs / "_build" / "html" | |
session.run( | |
"sphinx-build", | |
"-j", "auto", | |
"--color", | |
"-W", | |
"--keep-going", | |
"-D", "plot_gallery=0", | |
"-b", "html", | |
"-d", docs / "_build" / ".doctrees", | |
docs, | |
docs_output, | |
) | |
doc2dash( | |
session, | |
docs_output, | |
name="sunpy", | |
icon=docs_output / "_static" / "img" / "sunpy_icon_128x128.png", | |
online_url="https://docs.sunpy.org/en/latest", | |
) | |
@nox.session(reuse_venv=True) | |
def astropy(session): | |
""" | |
Build the astropy docs. | |
""" | |
astropy_dir = BUILD_DIR / "astropy" | |
clone_or_pull( | |
session, | |
target_dir=astropy_dir, | |
url="[email protected]:astropy/astropy.git", | |
ref="main" | |
) | |
# Install packages | |
session.install("doc2dash") | |
session.install("-e", f"{astropy_dir}[docs]") | |
docs = astropy_dir / "docs" | |
docs_output = docs / "_build" / "html" | |
session.run( | |
"sphinx-build", | |
"-j", "auto", | |
"--color", | |
"-W", | |
"--keep-going", | |
"-b", "html", | |
"-d", docs / "_build" / ".doctrees", | |
docs, | |
docs_output, | |
) | |
with open(docs / "astropy_logo.png", "wb") as fobj: | |
data = urllib.request.urlopen( | |
"https://raw.githubusercontent.com/astropy/astropy-logo/main/generated/astropy_logo_notext.png" | |
) | |
fobj.write(data.read()) | |
doc2dash( | |
session, | |
docs_output, | |
name="astropy", | |
icon=docs / "astropy_logo.png", | |
online_url="https://docs.astropy.org/en/latest", | |
) | |
@nox.session(reuse_venv=True) | |
def parfive(session): | |
""" | |
Build the parfive docs. | |
""" | |
parfive_dir = BUILD_DIR / "parfive" | |
clone_or_pull( | |
session, | |
target_dir=parfive_dir, | |
url="[email protected]:Cadair/parfive.git", | |
ref="main" | |
) | |
# Install packages | |
session.install("doc2dash") | |
session.install("-e", f"{parfive_dir}[docs]") | |
docs = parfive_dir / "docs" | |
docs_output = docs / "_build" / "html" | |
session.run( | |
"sphinx-build", | |
"-j", "auto", | |
"--color", | |
"-W", | |
"--keep-going", | |
"-b", "html", | |
"-d", docs / "_build" / ".doctrees", | |
docs, | |
docs_output, | |
) | |
doc2dash( | |
session, | |
docs_output, | |
name="parfive", | |
online_url="https://parfive.readthedocs.io/en/latest/", | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment