Skip to main content

pluMkdocs

A very, very hacky way to document multiple dispatch function implemented using the wonderful plum package

⚠️ Desclaimer

Have I mentioned that this is very hacky? It raises a whole lot of warnings, the vast majority of which I don't understand. Also, it is not heavly tested and only checked against mkdocs-material. It contains a lot of hard coded stuff and is not very flexible. It is also not very well documented.

I'm uploading this with the hope that someone will find it useful and will improve it. Contributions welcome :)

Also, I need this as a dependency for other projects, so I will probably not be able to maintain this very well.

How to use

For a quickstart, check out the example in example_module and the index.md page in the docs folder. To see it in action, cd into example_module and run mkdocs serve.

The source code contains something like this:

# Define some function to test
@dispatch.abstract
def foo(a, b):
    """Base description of the generic `foo` function"""
    pass

@dispatch
def foo(a: int, b: int):
    """Add two integers.

    Args:
        a (int): First integer.
        b (int): Second integer.
    
    Returns:
        int: Sum of a and b.
    """
    return a + b

@dispatch
def foo(a: str, b: str):
    """Concatenate two strings.

    Args:
        a (str): First string.
        b (str): Second string.
    
    Returns:
        str: Concatenation of a and b.
    """
    return a + b

...

You should see something like this in the documentation:

example

More details

This package exposes an implementations macro that can be used to list the dispatched implementations of a function in your mkdocs.

To use it, in your mkdocs.yml file, make sure to load the mkdocs-macros plugin using

plugins:
  macros:
    module_name: docs/macros

where docs/macros can be any path to a module that contains the macros. Then, in your docs/macros.py file, you can define the macros you want to use. If you don't have any other macro, you simply need to expose the function define_env from the plumkdocs module, like so:

from plumkdocs import define_env

__all__ = ['define_env']

If you have other macros, you can simply add the macro to your define_env function, like so:

from plumkdocs import mod_to_string

def define_env(env):
    @env.macro
    def implementations(module: str, function=None):
        return mod_to_string(module, function)

In both cases, you can then use the implementations macro in your markdown files, like so:

... some markdown ...

{{ implementations('my_package', 'foo') }}

... some more markdown ...

This will list all the implementations of the foo function in the my_package module. The docstrings will be (hopefully) correctly formatted, and the code will be highlighted using the pygments syntax highlighter. The signature of each method will also be displayed.

Examples

To see a working example, check out the jaxdf and jwave documentation.

Metadata

Release files for plumkdocs 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for plumkdocs 1.0.1
File Size Uploaded
plumkdocs-1.0.1.tar.gz 136.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for plumkdocs 1.0.1
File Interpreter ABI Platform
plumkdocs-1.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 143.3 kB

Release files / plumkdocs-1.0.1.tar.gz

Download URL plumkdocs-1.0.1.tar.gz
Size 136.7 kB
Tags Source
SHA-256 checksum
How to use checksums
c66972249928e754d3c962530077cabae65bbd0a60ebcf293299b107c9724893
BLAKE2b-256 checksum
How to use checksums
c3e5a49e65c27c636d0a622bbaf3fa71d2abaac719c57fb517027a89f8754e76
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / plumkdocs-1.0.1-py3-none-any.whl

Download URL plumkdocs-1.0.1-py3-none-any.whl
Size 6.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f932307198ba9949af190518fdefab4e55ce9b01d0aad1523b0f495ca3ce0934
BLAKE2b-256 checksum
How to use checksums
ca2f868b0968c1f9a0e3237ccb8d6346ef1497d03ad7874b1364d896266c3d96
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files

1.0.0

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page