Skip to content

Commit

Permalink
Move pdoc command into noxfile
Browse files Browse the repository at this point in the history
  • Loading branch information
object-Object committed Nov 11, 2023
1 parent a538412 commit 90c951b
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 17 deletions.
11 changes: 2 additions & 9 deletions .github/workflows/pdoc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,11 @@ jobs:
python-version: '3.11'

- name: Install package
run: pip install -e .[pdoc] hatch
run: pip install nox

- name: Generate docs
timeout-minutes: 1
run: |
pdoc hexdoc \!hexdoc._cli \!hexdoc._export \!hexdoc._templates \
--edit-url hexdoc=https://github.com/object-Object/hexdoc/blob/main/src/hexdoc/ \
--favicon https://github.com/object-Object/hexdoc/raw/main/media/hexdoc.png \
--footer-text "Version: $(hatch version) ($(git rev-parse --short HEAD))" \
--logo https://github.com/object-Object/hexdoc/raw/main/media/hexdoc.svg \
--logo-link https://pypi.org/project/hexdoc/ \
--output-directory docs/
run: nox --session pdoc -- --output-directory docs/

- uses: actions/upload-pages-artifact@v2
with:
Expand Down
61 changes: 55 additions & 6 deletions noxfile.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
from typing import Mapping

import nox

nox.options.sessions = ["tests"]
PDOC_FAVICON = "https://github.com/object-Object/hexdoc/raw/main/media/hexdoc.png"
PDOC_LOGO_LINK = "https://pypi.org/project/hexdoc/"
PDOC_LOGO = "https://github.com/object-Object/hexdoc/raw/main/media/hexdoc.svg"
PDOC_EDIT_URL = "https://github.com/object-Object/hexdoc/blob/main/src/hexdoc/"

nox.options.reuse_existing_virtualenvs = True

@nox.session(reuse_venv=True)
def hexdoc(session: nox.Session):
session.install(".")
session.run("hexdoc", *session.posargs)
nox.options.sessions = ["tests"]


@nox.session(reuse_venv=True)
@nox.session
def tests(session: nox.Session):
session.run("pip", "uninstall", "hexdoc-mod", "-y")
session.install("-e", ".[test]", "-e", "./test/_submodules/HexMod")
Expand All @@ -19,3 +22,49 @@ def tests(session: nox.Session):

# test cookiecutter last so the extra package install doesn't interfere
session.run("pytest", "--nox", *session.posargs)


@nox.session
def hexdoc(session: nox.Session):
session.install(".")
session.run("hexdoc", *session.posargs)


@nox.session
def pdoc(session: nox.Session):
session.install(".[pdoc]")

version = run_silent(session, "hatch", "version")
commit = run_silent(session, "git", "rev-parse", "--short", "HEAD", external=True)

session.run(
"pdoc",
"hexdoc",
"--favicon",
PDOC_FAVICON,
"--logo-link",
PDOC_LOGO_LINK,
"--logo",
PDOC_LOGO,
"--edit-url",
f"hexdoc={PDOC_EDIT_URL}",
"--footer-text",
f"Version: {version} ({commit})",
*session.posargs,
)


def run_silent(
session: nox.Session,
*args: str,
env: Mapping[str, str] | None = None,
external: bool = False,
):
output: str | None = session.run(
*args,
env=env,
silent=True,
external=external,
)
assert output
return output.strip()
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[build-system]
requires = [
"hatchling",
"hatch-version-commit",
"hatch-regex-commit",
]
build-backend = "hatchling.build"

Expand Down Expand Up @@ -62,6 +62,7 @@ dependencies = [
[project.optional-dependencies]
pdoc = [
"pdoc~=14.1",
"hatch",
]
test = [
"pyright",
Expand All @@ -74,7 +75,6 @@ dev = [
"hexdoc[pdoc,test]",
"ruff==0.1.4",
"pre-commit",
"hatch",
"nox",
]

Expand Down

0 comments on commit 90c951b

Please sign in to comment.