Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .copier-answers.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Changes here will be overwritten by Copier
_commit: ebb6e1c
_commit: '4372075'
_src_path: https://github.com/python-project-templates/base.git
add_docs: false
add_extension: python
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ on:
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

permissions:
Expand Down
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ lint-py: ## lint python with ruff
python -m ruff format --check yardang

lint-docs: ## lint docs with mdformat and codespell
python -m mdformat --check README.md
python -m codespell_lib README.md
python -m mdformat --check README.md $(wildcard docs/src)
python -m codespell_lib README.md $(wildcard docs/src)

fix-py: ## autoformat python code with ruff
python -m ruff check --fix yardang
python -m ruff format yardang

fix-docs: ## autoformat docs with mdformat and codespell
python -m mdformat README.md
python -m codespell_lib --write README.md
python -m mdformat README.md $(wildcard docs/src)
python -m codespell_lib --write README.md $(wildcard docs/src)

lint: lint-py lint-docs ## run all linters
lints: lint
Expand All @@ -52,7 +52,7 @@ check-dist: ## check python sdist and wheel with check-dist
check-types: ## check python types with ty
ty check --python $$(which python)

checks: check-dist
checks: check-dist check-types

# Alias
check: checks
Expand Down
1 change: 0 additions & 1 deletion docs/src/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,3 @@ Use `js:autoclass` to document classes:
:members:

```

44 changes: 22 additions & 22 deletions docs/src/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pages = [
]
use-autoapi = true
```

## [`name`](https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-project)

The project name is taken from the standard section, or from the `cwd`.
Expand Down Expand Up @@ -101,22 +102,22 @@ theme = "fuma"
html_theme_options = { github_url = "https://github.com/you/project", toc_style = "clerk" }
```

| Option | Default | Description |
| --- | --- | --- |
| `layout` | `docs` | `docs` puts the header beside the sidebar; `notebook` spans it across the top. |
| `toc_style` | `normal` | `clerk` dims headings away from the current one. |
| `color_preset` | `neutral` | Accent colour: `neutral`, `amber`, `blue`, `emerald`, `purple`, `rose`. |
| `fonts` | `bundled` | `system` skips the bundled webfonts and uses the system stack. |
| `search` | `true` | Enables the search dialog and its index. |
| `sidebar_hide_name` | `false` | Hides the project name next to the logo. |
| `default_open_level` | `1` | Sidebar folder depth expanded by default. |
| `github_url` | — | Adds a GitHub link, and an "Edit this page" link. |
| `edit_page_url_template` | — | Overrides the edit link, e.g. `https://host/edit/main/{filename}`. |
| `nav_links` | — | Header links, as `[{title, url}]` or `"Title\|url, Title\|url"`. |
| `sidebar_tabs` | — | Navigator entries under the search box, as `[{title, url, description, icon, match}]`. |
| `announcement` | — | Banner text shown above the header. |
| `footer_text` | — | Extra line in the footer. |
| `light_css_variables` / `dark_css_variables` | — | CSS custom property overrides, e.g. `{ "color-fd-primary" = "#e11d48" }`. |
| Option | Default | Description |
| -------------------------------------------- | --------- | -------------------------------------------------------------------------------------- |
| `layout` | `docs` | `docs` puts the header beside the sidebar; `notebook` spans it across the top. |
| `toc_style` | `normal` | `clerk` dims headings away from the current one. |
| `color_preset` | `neutral` | Accent colour: `neutral`, `amber`, `blue`, `emerald`, `purple`, `rose`. |
| `fonts` | `bundled` | `system` skips the bundled webfonts and uses the system stack. |
| `search` | `true` | Enables the search dialog and its index. |
| `sidebar_hide_name` | `false` | Hides the project name next to the logo. |
| `default_open_level` | `1` | Sidebar folder depth expanded by default. |
| `github_url` | — | Adds a GitHub link, and an "Edit this page" link. |
| `edit_page_url_template` | — | Overrides the edit link, e.g. `https://host/edit/main/{filename}`. |
| `nav_links` | — | Header links, as `[{title, url}]` or `"Title\|url, Title\|url"`. |
| `sidebar_tabs` | — | Navigator entries under the search box, as `[{title, url, description, icon, match}]`. |
| `announcement` | — | Banner text shown above the header. |
| `footer_text` | — | Extra line in the footer. |
| `light_css_variables` / `dark_css_variables` | — | CSS custom property overrides, e.g. `{ "color-fd-primary" = "#e11d48" }`. |

#### Content components

Expand Down Expand Up @@ -400,7 +401,6 @@ language = "en"
pygments_style = "sphinx"
```


## [Myst](https://myst-parser.readthedocs.io/en/latest/#)

```toml
Expand Down Expand Up @@ -531,7 +531,6 @@ mindmap
Mermaid
```


## GitHub Admonitions

GitHub admonitions are automatically translated to sphinx.
Expand Down Expand Up @@ -835,7 +834,7 @@ rustdoc-fmt = { mylib-utils = "rst" }

The pages are generated for you, so your documentation files only need a toctree entry pointing at them:

````markdown
```markdown
# API Reference

\`\`\`{toctree}
Expand All @@ -844,7 +843,7 @@ The pages are generated for you, so your documentation files only need a toctree
/api/mylib/lib
/api/mylib-utils/lib
\`\`\`
````
```

## Sphinx-JS Integration

Expand Down Expand Up @@ -941,7 +940,7 @@ ts-type-bold = true

Then in your documentation files, you can use sphinx-js directives:

````markdown
```markdown
# API Reference

## Functions
Expand All @@ -959,7 +958,7 @@ Then in your documentation files, you can use sphinx-js directives:

\`\`\`{js:automodule} myModule
\`\`\`
````
```

## GitHub Wiki Integration

Expand Down Expand Up @@ -1123,6 +1122,7 @@ git push
```

The generated wiki includes:

- `Home.md` - The main landing page (converted from index.md)
- `_Sidebar.md` - Navigation sidebar with links to all pages
- `_Footer.md` - Footer with links to documentation and repository
Expand Down
5 changes: 1 addition & 4 deletions docs/src/home.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


<div style="display: flex; flex-direction: row; margin-top:50px;">
<a href="https://github.com/python-project-templates/yardang"><img src="https://github.com/python-project-templates/yardang/blob/main/docs/logo.png?raw=true" alt="yardang" width="120"></a>
<h1 style="margin-left: 20px;">yardang</h1>
Expand All @@ -15,7 +13,6 @@

[`yardang`](https://www.britannica.com/science/yardang) makes building [Sphinx](https://www.sphinx-doc.org/en/master/) easy.


::::{grid} 1 2 2 2
:margin: 4 4 0 0
:gutter: 1
Expand Down Expand Up @@ -49,6 +46,6 @@ Star, Fork, or contribute on GitHub.
:::
::::

-------------
______________________________________________________________________

*This library was generated using [copier](https://copier.readthedocs.io/en/stable/) from the [Base Python Project Template repository](https://github.com/python-project-templates/base).*
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ develop = [
"codespell",
"hatchling",
"mdformat",
"mdformat-frontmatter",
"mdformat-tables>=1",
"pytest",
"pytest-cov",
Expand Down Expand Up @@ -117,7 +118,7 @@ replace = 'version = "{new_version}"'
[tool.coverage.run]
branch = true
omit = [
"yardang/tests/integration/",
"yardang/tests/integration/*",
]

[tool.coverage.report]
Expand Down
32 changes: 16 additions & 16 deletions yardang/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,8 @@ def customize(args):
custom_css = custom_css if custom_css is not None else get_config_flex(section="custom-css", base=config_base)
custom_js = custom_js if custom_js is not None else get_config_flex(section="custom-js", base=config_base)
assets_dir = Path(__file__).parent
custom_css = _resolve_custom_asset(custom_css, theme, "css", assets_dir=assets_dir)
custom_js = _resolve_custom_asset(custom_js, theme, "js", assets_dir=assets_dir)
custom_css_content = _resolve_custom_asset(custom_css, theme, "css", assets_dir=assets_dir)
custom_js_content = _resolve_custom_asset(custom_js, theme, "js", assets_dir=assets_dir)

source_dir = source_dir or get_config_flex(section="source-dir", base=config_base)
existing_source = source_dir is not None
Expand Down Expand Up @@ -635,10 +635,10 @@ def customize(args):
html_output = Path(html_output_dir) if html_output_dir is not None else Path("docs/html")
styles_dir = html_output / "_static" / "styles"
styles_dir.mkdir(parents=True, exist_ok=True)
(styles_dir / "custom.css").write_text(custom_css or "")
(styles_dir / "custom.css").write_text(custom_css_content or "")
js_dir = html_output / "_static" / "js"
js_dir.mkdir(parents=True, exist_ok=True)
(js_dir / "custom.js").write_text(custom_js or "")
(js_dir / "custom.js").write_text(custom_js_content or "")

# append docs-specific ignores to gitignore
if not existing_source and Path(".gitignore").exists():
Expand All @@ -665,23 +665,23 @@ def customize(args):
@contextmanager
def generate_wiki_configuration(
*,
project: str = "",
title: str = "",
module: str = "",
description: str = "",
author: str = "",
copyright: str = "",
version: str = "",
theme: str = "furo",
docs_root: str = "",
root: str = "",
cname: str = "",
project: str | None = "",
title: str | None = "",
module: str | None = "",
description: str | None = "",
author: str | None = "",
copyright: str | None = "",
version: str | None = "",
theme: str | None = "furo",
docs_root: str | None = "",
root: str | None = "",
cname: str | None = "",
pages: list | None = None,
use_autoapi: bool | None = None,
autoapi_ignore: list | None = None,
custom_css: Path | None = None,
custom_js: Path | None = None,
config_base: str = "tool.yardang",
config_base: str | None = "tool.yardang",
previous_versions: bool | None = False,
adjust_arguments: Callable | None = None,
adjust_template: Callable | None = None,
Expand Down
8 changes: 4 additions & 4 deletions yardang/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ def build(
sleep(0.1)
if process.returncode != 0:
if pdb:
import pdb # noqa: T100
import pdb as debugger # noqa: T100

pdb.set_trace() # noqa: T100
debugger.set_trace() # noqa: T100
raise Exit(process.returncode)


Expand Down Expand Up @@ -170,9 +170,9 @@ def wiki(
sleep(0.1)
if process.returncode != 0:
if pdb:
import pdb # noqa: T100
import pdb as debugger # noqa: T100

pdb.set_trace() # noqa: T100
debugger.set_trace() # noqa: T100
raise Exit(process.returncode)

# Post-process for GitHub Wiki compatibility
Expand Down
4 changes: 3 additions & 1 deletion yardang/sphinx/llms.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from pathlib import Path
from typing import cast
from urllib.parse import urlsplit, urlunsplit

from docutils import nodes
from sphinx.application import Sphinx
from sphinx.builders import Builder
from sphinx_markdown_builder.builder import MarkdownBuilder
from sphinx_markdown_builder.translator import MarkdownTranslator

Expand Down Expand Up @@ -42,7 +44,7 @@ def __init__(self, app: Sphinx):
self.current_doc_name = ""

def create_translator(self, *args):
return self.app.registry.create_translator(self, *args)
return self.app.registry.create_translator(cast(Builder, self), *args)

@staticmethod
def get_target_uri(docname: str, typ: str | None = None) -> str:
Expand Down
7 changes: 4 additions & 3 deletions yardang/tests/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from typer import Exit

from yardang.build import generate_docs_configuration
from yardang.cli import build, debug
from yardang.cli import build, debug, wiki
from yardang.utils import get_config_flex


Expand All @@ -19,7 +19,8 @@ def test_cli():
debug()


def test_cli_pdb_on_failure(monkeypatch):
@pytest.mark.parametrize("command", [build, wiki])
def test_cli_pdb_on_failure(monkeypatch, command):
class FailedProcess:
returncode = 1

Expand All @@ -32,7 +33,7 @@ def poll():
monkeypatch.setattr("pdb.set_trace", lambda: traced.append(True))

with pytest.raises(Exit):
build(pdb=True)
command(pdb=True)

assert traced == [True]

Expand Down
5 changes: 3 additions & 2 deletions yardang/tests/test_llms.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,14 @@ def test_full_build_can_be_disabled(tmp_path, monkeypatch):
assert "llms-full.txt" not in (output / "llms.txt").read_text()


def test_explicit_builder_copies_downloads(tmp_path, monkeypatch):
@pytest.mark.parametrize("builder", ["html", "yardang-llms"])
def test_llms_builders_copy_downloads(tmp_path, monkeypatch, builder):
_write_project(tmp_path)
monkeypatch.chdir(tmp_path)
output = tmp_path / "llms"

with generate_docs_configuration() as conf_dir:
result = build_main(["-q", "-b", "yardang-llms", "-c", str(conf_dir), ".", str(output)])
result = build_main(["-q", "-b", builder, "-c", str(conf_dir), ".", str(output)])

assert result == 0
download = re.search(r"\]\(([^)]*_downloads/[^)]+)\)", (output / "index.html.md").read_text())
Expand Down
2 changes: 2 additions & 0 deletions yardang/tests/test_sphinx.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ def test_github_admonition_preserves_quoted_blank_lines(tmp_path, monkeypatch):

with generate_docs_configuration() as conf_dir:
spec = importlib.util.spec_from_file_location("yardang_test_conf", Path(conf_dir) / "conf.py")
assert spec is not None
assert spec.loader is not None
conf = importlib.util.module_from_spec(spec)
spec.loader.exec_module(conf)

Expand Down
2 changes: 1 addition & 1 deletion yardang/wiki.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ def _is_api_page(filename: str, content: str) -> bool:
return indicator_count >= 2


def extract_toctree_entries(content: str) -> list[tuple[str, str]]:
def extract_toctree_entries(content: str) -> list[tuple[str | None, str]]:
"""Extract toctree entries from markdown content.

Parses MyST-style toctree directives to find linked pages.
Expand Down