Skip to content

Development

This page documents the development workflow for maintaining Mathy source code, generated API documentation, MkDocs configuration, and documentation build output.

๐Ÿงญ Purpose

Mathy uses source-driven documentation. Python modules contain Google-style docstrings that are parsed by mkdocstrings and rendered into the API reference during the MkDocs build process.

Development work should preserve three standards:

Standard Requirement
Source correctness Python modules must parse and compile.
Documentation correctness Docstrings must be Google-style and compatible with griffe.
Build correctness mkdocs build must complete without documentation warnings.

๐Ÿงฑ Repository Structure

The recommended project structure is:

Mathy/
โ”œโ”€โ”€ mkdocs.yml
โ”œโ”€โ”€ requirements.txt
โ”œโ”€โ”€ data.py
โ”œโ”€โ”€ scalers.py
โ”œโ”€โ”€ encoders.py
โ”œโ”€โ”€ imputers.py
โ”œโ”€โ”€ transformers.py
โ”œโ”€โ”€ features.py
โ”œโ”€โ”€ clusters.py
โ”œโ”€โ”€ outliers.py
โ”œโ”€โ”€ regressions.py
โ”œโ”€โ”€ classifications.py
โ”œโ”€โ”€ forecasting.py
โ”œโ”€โ”€ docs/
โ”‚   โ”œโ”€โ”€ index.md
โ”‚   โ”œโ”€โ”€ architecture.md
โ”‚   โ”œโ”€โ”€ development.md
โ”‚   โ”œโ”€โ”€ user-guide/
โ”‚   โ”‚   โ”œโ”€โ”€ index.md
โ”‚   โ”‚   โ”œโ”€โ”€ data-preparation.md
โ”‚   โ”‚   โ”œโ”€โ”€ feature-engineering.md
โ”‚   โ”‚   โ”œโ”€โ”€ modeling.md
โ”‚   โ”‚   โ””โ”€โ”€ forecasting.md
โ”‚   โ””โ”€โ”€ api/
โ”‚       โ”œโ”€โ”€ index.md
โ”‚       โ”œโ”€โ”€ data.md
โ”‚       โ”œโ”€โ”€ scalers.md
โ”‚       โ”œโ”€โ”€ encoders.md
โ”‚       โ”œโ”€โ”€ imputers.md
โ”‚       โ”œโ”€โ”€ transformers.md
โ”‚       โ”œโ”€โ”€ features.md
โ”‚       โ”œโ”€โ”€ clusters.md
โ”‚       โ”œโ”€โ”€ outliers.md
โ”‚       โ”œโ”€โ”€ regressions.md
โ”‚       โ”œโ”€โ”€ classifications.md
โ”‚       โ””โ”€โ”€ forecasting.md
โ””โ”€โ”€ site/

The site/ directory is generated by MkDocs and should not be edited manually.

๐Ÿ Python Environment

Create and activate a virtual environment from the repository root.

python -m venv .venv
.\.venv\Scripts\Activate.ps1

Upgrade packaging tools.

python -m pip install --upgrade pip setuptools wheel

Install project and documentation dependencies.

pip install -r requirements.txt

๐Ÿ“ฆ Documentation Dependencies

The documentation build requires MkDocs, Material for MkDocs, and mkdocstrings.

At minimum, requirements.txt should include documentation dependencies similar to:

mkdocs
mkdocs-material
mkdocstrings[python]

If the source modules import scientific or machine-learning packages during documentation generation, the active environment must also include those runtime dependencies.

Common dependencies may include:

numpy
pandas
scipy
scikit-learn
statsmodels
matplotlib
seaborn

๐Ÿงพ MkDocs Configuration

The mkdocs.yml file controls the documentation site.

Key configuration areas include:

Section Purpose
site_name Sets the documentation site name.
theme Configures Material for MkDocs.
plugins Enables search and mkdocstrings.
markdown_extensions Enables enhanced Markdown rendering.
nav Defines the documentation navigation.
mkdocstrings options Controls API rendering from Python docstrings.

The API reference uses one Markdown file per Python module.

Example:

# Data

::: data

The directive tells mkdocstrings to load the data module and render documentation from the module, classes, methods, signatures, arguments, returns, and raises sections.

๐Ÿ“š Google-Style Docstring Standard

Mathy source documentation should use Google-style docstrings.

Recommended structure:

def method_name( self, value: object ) -> object:
    """Short imperative summary.

    Purpose:
        Describes what the method does, what state it uses, what state it changes, and how it
        fits into the Mathy workflow.

    Args:
        value: Description of the argument.

    Returns:
        object: Description of the returned value.

    Raises:
        Error: Raised when validation or wrapped estimator execution fails."""

โœ… Griffe-Compatible Section Rules

mkdocstrings uses griffe to parse Python docstrings. The parser is strict about Google-style sections.

Use this format:

Args:
    name: Description.

Use this format:

Attributes:
    attribute_name: Description.

Use this format:

Returns:
    TypeName: Description.

Use this format:

Raises:
    Error: Description.

Avoid this format in source files:

Args:
    name (type): Description.

Avoid continuation lines that look like new entries without a colon.

Avoid generic return text without a type when the function has no return annotation.

Incorrect:

Returns:
    Public member names exposed by the wrapper.

Correct:

Returns:
    list[str]: Public member names exposed by the wrapper.

๐Ÿงฏ Error-Handling Standard

Mathy source modules use wrapped exception logging where exception handlers already exist.

Standard pattern:

except Exception as e:
    exception = Error( e )
    exception.module = 'mathy'
    exception.cause = 'ClassName'
    exception.method = 'method_name( self, *args ) -> return_type'
    Logger( ).write( exception )
    raise exception

For methods with multiple parameters, use the compact *args method string:

exception.method = 'method_name( self, *args ) -> return_type'

For methods with one explicit parameter, the full stable signature may be used:

exception.method = 'transform( self, X: np.ndarray ) -> np.ndarray'

The method string must not contain:

  • live dataframe values
  • array contents
  • user input values
  • file paths
  • target values
  • runtime-specific object representations

๐Ÿงช Source Validation

After modifying a Python source file, validate it before building documentation.

Run syntax parsing:

python -m py_compile .\data.py

Run compile checks across the project:

python -m compileall .

For individual imports:

python -c "import data; print('data ok')"
python -c "import scalers; print('scalers ok')"
python -c "import encoders; print('encoders ok')"
python -c "import imputers; print('imputers ok')"
python -c "import transformers; print('transformers ok')"
python -c "import features; print('features ok')"
python -c "import clusters; print('clusters ok')"
python -c "import outliers; print('outliers ok')"
python -c "import regressions; print('regressions ok')"
python -c "import classifications; print('classifications ok')"
python -c "import forecasting; print('forecasting ok')"

๐Ÿ—๏ธ Documentation Build

Build the documentation from the repository root.

mkdocs build

A clean build should show:

INFO    -  Documentation built

Warnings should be treated as defects unless they are known upstream notices from Material for MkDocs.

๐Ÿ–ฅ๏ธ Local Documentation Server

Run the local documentation site:

mkdocs serve

Open the local site:

http://127.0.0.1:8000/

Use this during documentation review because it allows you to inspect navigation, API rendering, tables, code blocks, and page layout before deployment.

๐Ÿงน Cleaning Generated Output

MkDocs writes output to the site/ directory.

To force a clean build:

Remove-Item -Recurse -Force .\site -ErrorAction SilentlyContinue
mkdocs build

The site/ directory can be regenerated at any time.

๐Ÿ”Ž Troubleshooting MkDocs Warnings

Missing nav file

Warning:

A reference to 'docs/page.md' is included in the 'nav' configuration, which is not found

Cause:

The mkdocs.yml navigation references a Markdown file that does not exist under docs/.

Fix:

Create the file or remove the entry from nav.

Page exists but is not in nav

Warning:

The following pages exist in the docs directory, but are not included in the "nav" configuration

Cause:

A Markdown file exists under docs/, but mkdocs.yml does not include it in the navigation.

Fix:

Add the file to nav, remove the file, or intentionally accept the warning.

Griffe name parsing warning

Warning:

griffe: module.py:line: Failed to get 'name: description' pair

Cause:

A Google-style Args: or Attributes: section has malformed entries or wrapped lines that look like entries.

Fix:

Use this structure:

Args:
    name: Description.
Attributes:
    attribute_name: Description.

Griffe return warning

Warning:

No type or annotation for returned value

Cause:

A Returns: section lacks an explicit type and the function has no return annotation.

Fix:

Use this structure:

Returns:
    list[str]: Public member names exposed by the wrapper.

๐Ÿงญ Documentation Workflow

Use this sequence when changing source or documentation files:

1. Update Python source.
2. Confirm source parses and compiles.
3. Confirm docstrings are Google-style and griffe-compatible.
4. Update or add Markdown pages under docs/.
5. Confirm every docs page is included in mkdocs.yml nav.
6. Run mkdocs build.
7. Resolve warnings.
8. Run mkdocs serve.
9. Inspect the local site.
10. Commit the source and documentation changes.

๐Ÿงช Acceptance Checklist

Before considering a documentation update complete, confirm:

Check Required Result
Python source parses No syntax errors.
Python source compiles py_compile or compileall succeeds.
Imports work API modules can be imported by mkdocstrings.
MkDocs builds mkdocs build succeeds.
Griffe warnings resolved No malformed Google-style docstring warnings.
Navigation complete No missing or unlisted documentation page warnings.
API pages render Each module page renders correctly.
Local site reviewed Pages display correctly under mkdocs serve.

๐Ÿš€ Deployment Preparation

After local documentation builds cleanly, the documentation can be deployed through GitHub Pages.

Common deployment options include:

Option Description
mkdocs gh-deploy Builds and pushes the documentation site to the gh-pages branch.
GitHub Actions Automatically builds and deploys documentation on push.
Manual Pages configuration Uses repository settings to publish from the selected branch or workflow.

A typical manual deployment command is:

mkdocs gh-deploy

Use this only after the local build is clean.

Page Description
Architecture Project structure and module architecture.
User Guide Task-oriented usage documentation.
API Reference Source-generated API documentation.