Skip to content

kraken.std.docs

kraken.std.docs.tasks.mkdocs.mkdocs

mkdocs(
    *,
    requirements: Sequence[str] = "mkdocs>=1.5.3,<2.0.0",
    mkdocs_root: Path | str | None = None,
    watch_files: Sequence[Path | str] = (),
    task_prefix: str = "mkdocs",
    project: Project | None = None
) -> tuple[MkDocsTask, MkDocsTask]
Source code in kraken/std/docs/tasks/mkdocs.py
def mkdocs(
    *,
    requirements: Sequence[str] = ("mkdocs>=1.5.3,<2.0.0"),
    mkdocs_root: Path | str | None = None,
    watch_files: Sequence[Path | str] = (),
    task_prefix: str = "mkdocs",
    project: Project | None = None,
) -> tuple[MkDocsTask, MkDocsTask]:
    project = project or Project.current()

    mkdocs_bin = pex_build(
        console_script="mkdocs",
        requirements=requirements,
        project=project,
        venv="prepend",
    ).output_file.map(str)

    build_dir = (project.build_directory / task_prefix / "_site").absolute()

    build_task = project.task(f"{task_prefix}.build", MkDocsTask)
    build_task.mkdocs_root = project.directory / (mkdocs_root or "")
    build_task.mkdocs_bin = mkdocs_bin
    build_task.args = ["build", "-d", str(build_dir), "--strict"]

    port = int(os.environ.get("MKDOCS_PORT", "8000"))
    watch_files = [(project.directory / x).absolute() for x in watch_files]

    serve_task = project.task(f"{task_prefix}.serve", MkDocsTask)
    build_task.mkdocs_root = project.directory / (mkdocs_root or "")
    serve_task.mkdocs_bin = mkdocs_bin
    serve_args = ["serve", "-a", f"localhost:{port}"]
    for w in watch_files:
        serve_args += ["-w", str(w)]
    serve_task.args = serve_args

    return build_task, serve_task

kraken.std.docs.tasks.novella.novella

novella(
    *,
    project: Project | None = None,
    name: str = "novella",
    novella_version: str,
    additional_requirements: Sequence[str] = (),
    docs_dir: str | Path | None = None,
    build_args: Sequence[str] = (),
    build_task: str | None = None,
    build_group: str | None = None,
    serve_args: Sequence[str] | None = None,
    serve_task: str | None = None
) -> tuple[NovellaTask, NovellaTask | None]
Source code in kraken/std/docs/tasks/novella.py
def novella(
    *,
    project: Project | None = None,
    name: str = "novella",
    novella_version: str,
    additional_requirements: Sequence[str] = (),
    docs_dir: str | Path | None = None,
    build_args: Sequence[str] = (),
    build_task: str | None = None,
    build_group: str | None = None,
    serve_args: Sequence[str] | None = None,
    serve_task: str | None = None,
) -> tuple[NovellaTask, NovellaTask | None]:
    project = project or Project.current()
    novella_bin = pex_build(
        console_script="novella",
        requirements=[f"novella{novella_version}", *additional_requirements],
        project=project,
        venv="prepend",
    ).output_file

    if docs_dir is not None:
        docs_dir = project.directory / docs_dir

    if build_task is None:
        assert name is not None, "need one of build_task/name"
        build_task = name

    _build_task = project.task(build_task, NovellaTask)
    _build_task.novella_bin = novella_bin
    _build_task.docs_dir = docs_dir
    _build_task.args = build_args
    if build_group is not None:
        project.group(build_group).add(_build_task)

    if serve_args is not None:
        if serve_task is None:
            assert name is not None, "need one of serve_task/name"
            serve_task = f"{name}.serve"
        _serve_task = project.task(serve_task, NovellaTask)
        _serve_task.novella_bin = novella_bin
        _serve_task.docs_dir = docs_dir
        _serve_task.args = serve_args
    else:
        _serve_task = None

    return _build_task, _serve_task