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
46 changes: 46 additions & 0 deletions docs/_scripts/macros.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# License: MIT
# Copyright © 2023 Frequenz Energy-as-a-Service GmbH

"""This module defines macros for use in Markdown files."""

import pathlib

from markdown.extensions import toc
from mkdocs_macros import plugin as macros


def define_env(env: macros.MacrosPlugin) -> None:
"""Define the hook to create macro functions for use in Markdown.
Args:
env: The environment to define the macro functions in.
"""

def _slugify(text: str) -> str:
"""Slugify a text.
Args:
text: The text to slugify.
Returns:
The slugified text.
"""
# The type of the return value is not defined for the markdown library.
# Also for some reason `mypy` thinks the `toc` module doesn't have a
# `slugify_unicode` function, but it definitely does.
return toc.slugify_unicode(text, "-") # type: ignore[attr-defined,no-any-return]

@env.macro # type: ignore[misc]
def glossary(term: str) -> str:
"""Create a link to the glossary entry for the given term.
Args:
term: The term to link to.
Returns:
The Markdown link to the glossary entry for the given term.
"""
current_path = pathlib.Path(env.page.file.src_uri)
glossary_path = pathlib.Path("intro/glossary.md")
link_path = glossary_path.relative_to(current_path.parent)
return f"[{term}]({link_path}#{_slugify(term)})"
File renamed without changes.
6 changes: 4 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ python3 -m venv .venv

This will create the virtual environment and activate it automatically for you.

Now you can install the SDK by using `pip`:
Now you can install the SDK by using `pip` (if you don't have `pip` installed
you can follow [the official
instructions](https://pip.pypa.io/en/stable/installation/)):

```sh
python3 -m pip install frequenz-sdk
Expand All @@ -63,5 +65,5 @@ $ python3
Python 3.11.4 (main, Jun 7 2023, 10:13:09) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import frequenz.sdk
>>>
>>>
```
7 changes: 5 additions & 2 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,13 @@ markdown_extensions:
plugins:
- gen-files:
scripts:
- docs/mkdocstrings_autoapi.py
- docs/_scripts/mkdocstrings_autoapi.py
- literate-nav:
nav_file: SUMMARY.md
- macros:
module_name: docs/_scripts/macros
on_undefined: strict
on_error_fail: true
- mike:
canonical_version: latest
- mkdocstrings:
Expand Down Expand Up @@ -120,5 +124,4 @@ plugins:
# Preview controls
watch:
- "src"
- README.md
- CONTRIBUTING.md
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ dev-mkdocs = [
"mike == 1.1.2",
"mkdocs-gen-files == 0.5.0",
"mkdocs-literate-nav == 0.6.1",
"mkdocs-macros-plugin == 1.0.4",
"mkdocs-material == 9.3.1",
"mkdocs-section-index == 0.3.7",
"mkdocstrings[python] == 0.23.0",
"frequenz-repo-config[lib] == 0.6.1",
]
Expand Down Expand Up @@ -176,6 +176,7 @@ module = [
"async_solipsism.*",
"grpc.aio",
"grpc.aio.*",
"mkdocs_macros.*",
# There is a stubs package available, but it's not working:
# https://github.com/eggplants/networkx-stubs/issues/1
"networkx",
Expand Down