Skip to main content

Parses docstrings of all exported classes and methods of a python package and turns them into quarto markdown (qmd) files. Alongside, a basic structure for a quarto website is created, intended to easily document your python package with quarto.

Project description

Quarto Documentation for Python Packages

Small Python script to convert Python Google-Style docstrings to quarto files to be used to render a Python package documentation using a quarto website. This script started as the author was not happy with existing software to document Python packages, namely sphinx altough having a variety of features.

As sphinx has been used previously, this parser partially relies on the sphinx syntax for cross-referencing classes, functions, and methods.

Under the hood

Uses the Python standard libraries importlib to import all visible classes and functions of an existing package and inspect to inspect these objects. The Python package docstring_parser is used to parse Google style docstrings which are then converted into quarto .qmd files.

Usage

In the simplest case:

python3 makedocs.py <action> -p <package>

... where <action> can be init or document. init will initialize a new project and stores all necessary files in a directory _quarto. If initialized once, an error will be thrown if executed again to avoid overwriting changes made by the user. The argument --overwrite can be used to force-overwrite the existing quarto files as well as _quarto.yml. document will only update the man pages created from the Python docstrings as well as update the 'Function references' and 'Class references' section in the _quarto.yml file.

Additional options are available to change a few things. For more details see:

python3 makedocs.py --help

Cross referencing

Based on the syntax of sphinx, cross-referencing in the docstrings is done via :py:class:, :py:func: and :py:meth: followed by the name/path of the class, function, or method.

  • :py:class:\package.module.class`` references a class
  • :py:class:\class <package.module.class>`references a class but will only displayclass` (custom text) in the rendered quarto document.
  • :py:class\class`` expects the class to be in the same module as the class it is references from.

Similarely functions can be cross-referenced with the same system:

  • :py:func:\package.module.function`` references a func
  • :py:func:\function <package.module.function>`references a func but will only displayfunction` (custom text) in the rendered quarto document.
  • :py:func\function`` expects the func to be in the same module as the func it is references from.

Last but not least, sibling methods can be referenced within a class using:

  • :py:meth:\method``

The script does not validate if these references are valid, but will link to them in the quarto documents. quarto render will throw warnings if links cannot be resolved.

Examples

One additional feature is a special comment in the Example section of each Google style docstring. Whenver a line (code line) starts with #:, the example will be split at this point, resulting in multiple quarto code chunks allowing for 'in-line' (in-between chunks) output in the exercises. A line solely containing #: also initiales a new code chunk but will not be shown (hidden chunk splitter). As an example, this could look as follows in the docstring:

    Example:

    >>> # Basic addition
    >>> a = 10 + 3
    >>> a
    >>> #: Basic subtraction
    >>> 20 - 4
    >>> #:
    >>> 20 - 5

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyp2qmd-0.1.2.tar.gz (27.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyp2qmd-0.1.2-py3-none-any.whl (29.1 kB view details)

Uploaded Python 3

File details

Details for the file pyp2qmd-0.1.2.tar.gz.

File metadata

  • Download URL: pyp2qmd-0.1.2.tar.gz
  • Upload date:
  • Size: 27.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for pyp2qmd-0.1.2.tar.gz
Algorithm Hash digest
SHA256 c74ccb132549a9bbad6f95e51ee40d8639f2378e8f5fbc1b43e017a282e9d219
MD5 9d7a8326e842ca296dcc32a6285badc9
BLAKE2b-256 c035e7fa409dbaced84a7e6d52cae28ec358b4d7a4d38bc426d30b0223201549

See more details on using hashes here.

File details

Details for the file pyp2qmd-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: pyp2qmd-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 29.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for pyp2qmd-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 256929a03d038c684845b486eb2db32935db6f3e5168f12496deb0542291ded1
MD5 a2aa5b8c4cea0c4f26c7be00f9600e71
BLAKE2b-256 8a1fa88f8a852f3515a52e13c4b251555110bfd805fbc92ba1435be8d7aaaa70

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page