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="git@github.com: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="git@github.com: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="git@github.com: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/", )