Skip to main content

Mosheh, automatic and elegant documentation of Python code with MkDocs.

Project description

Logo Mosheh
Mosheh

PyPI - Version GitHub License GitHub Actions Workflow Status

Changelog

PyPI

Mosheh, automatic and elegant documentation of Python code with MkDocs.

Inspirated by cargodoc - a Rust tool for code documenting - and using MkDocs + Material MkDocs, Mosheh is an easy, fast, plug-and-play tool which saves time while automating the process of documenting the source code of a Python codebase.

Project/Codebase PLoC Mosheh's Exec Time
Mosheh ~4k 0.303s
scikit-learn ~862k ███████████ 11.783s
NumPy ~204k ████████████ 12.205

PLoC: Python Lines of Code

Specs: Mint 21.3 | Aspire A515-54 | Intel i7-10510U (8) @ 4.900GHz | RAM 19817MiB

<script src="https://asciinema.org/a/vyqIEXYLEup4SyWawQ4l2Ccs3.js" id="asciicast-vyqIEXYLEup4SyWawQ4l2Ccs3" async="true"></script>

This is not an alternative to MkDocs, but a complement based on it, since Mosheh lists all files you points to, saves every single notorious definition statement on each file iterated, all using Python ast native module for handling the AST and then generating a modern documentation respecting the dirs and files hierarchy.

At the moment, Mosheh documents only Python files (.py, .pyi), where the stuff documented for each file is shown below:

  • Imports ast.Import | ast.ImportFrom

    • Type Native | TrdParty | Local
    • Path (e.g. math.sqrt)
    • Code
  • Constants ast.Assign | ast.AnnAssign

    • Name (token name)
    • Typing Annotation (datatype)
    • Value (literal or call)
    • Code
  • Classes ast.ClassDef

    • Description (docstring)
    • Name (class name)
    • Parents (inheritance)
    • Methods Defined (nums and names)
    • Code
  • Funcs ast.FunctionDef | ast.AsyncFunctionDef

    • Description (docstring)
    • Name (func name)
    • Type Func | Method | Generator | Coroutine
    • Parameters (name, type, default)
    • Return Type (datatype)
    • Raises (exception throw)
    • Code
  • Assertions ast.Assert

    • Test (assertion by itself)
    • Message (opt. message in fail case)
    • Code

Stack

Python

uv Ruff Material for MkDocs

GitHub GitHub Pages GitHub Actions

Contributing

Before getting access to the To-Do List, Coding Style or even forking the project, we strongly recommend reading Mosheh's Guidelines

Arch

Mosheh's architecture can be interpreted in two ways: the directory structure and the interaction of the elements that make it up. A considerable part of a project is - or at least should be - that elements that are dispensable for its functionality are in fact dispensable, such as the existence of automated tests; they are important so that any existing quality process is kept to a minimum acceptable level, but if all the tests are deleted, the tool still works.

Here it is no different, a considerable part of Mosheh is, in fact, completely dispensable; follow below the structure of directories and relevant files that are part of this project:

.
├── mosheh/                     # Mosheh's source-code   ├── commands/*              # Logics for each command   ├── handlers/*              # Codebase handlers for each file   ├── doc/*                   # Documentation build logics   ├── types/                  # Custom data types      ├── basic.py            # Basic types (e.g. "type Token = str")      ├── contracts.py        # Contracts to ensure correct typing      ├── enums.py            # Enums for standardizing assignments      └── jsoncfg.py          # JSON for structuring commands config   ├── codebase.py             # Codebase reading logic   ├── constants.py            # Constants to be evaluated   ├── main.py                 # Entrypoint   └── utils.py                # Utilities
│
├── tests/                      # Template dir for testing   ├── DOC                     # Doc output dir   ├── PROJECT                 # Template project dir   └── unittest                # Automated tests
│
├── documentation/              # Mosheh's documentation dir   ├── docs/                   # Dir containing .md files and assets   ├── mkdocs.yml              # MkDocs's config file   └── mosheh.json             # Mosheh's exec config file
│
├── pyproject.toml              # Mosheh's config file for almost everything
├── uv.lock                     # uv's lockfile for dealing with dependencies
├── .python-version             # Default Python's version to use
│
├── .github/                    # Workflows and social stuff
│
├── LICENSE                     # Legal stuff, A.K.A donut sue me
│
└── .gitignore                  # Git "exclude" file

It is to be expected that if the tests/ directory is deleted, Mosheh's core will not be altered in any way, so much so that when a tool is downloaded via pip or similar, the tool is not accompanied by tests, licenses, development configuration files or workflows. So, to help you understand how the mosheh/ directory works, here's how the functional elements interact with each other:

Flowchart diagram

Usage

After installing Mosheh as a development dependency, create the documentation folder if not exists and run mosheh init [--path .]; this will result in a mosheh.json config file just as below:

{
  "documentation": {
    "projectName": "Mosheh",
    "repoName": "mosheh",
    "repoUrl": "https://github.com/lucasgoncsilva/mosheh",
    "editUri": "blob/main/documentation/docs",
    "siteUrl": "https://lucasgoncsilva.github.io/mosheh/",
    "logoPath": "./path/to/logo.svg",
    "readmePath": "./path/to/README.md",
    "codebaseNavPath": "Codebase"
  },
  "io": {
    "rootDir": "./app/",
    "outputDir": "./path/to/output/"
  }
}

After making sure the data on that JSON reflects the desired (more about this file at the official documentation), running mosheh create [--json .] results in a documentation following the default MkDocs structure with Material MkDocs as theme, with the codebase documented over "Codebase" named-section.

Development

Installing Dependencies

# Automatically handles everything with .venv
uv sync

Running Locally

# For running using uv and dealing with Mosheh as a module
uv run mosheh -h

Building Locally

# Build pip-like file
uv build

Testing

# Run all the testing workflow
uv run task test

Lint

# Run all the linting workflow
uv run task lint

Generate Self Document

# Generate Mosheh's Codebase Documentation
uv run task makedoc

License

This project is under MIT License. A short and simple permissive license with conditions only requiring preservation of copyright and license notices. Licensed works, modifications, and larger works may be distributed under different terms and without source code.

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

mosheh-2.0.0.tar.gz (127.0 kB view details)

Uploaded Source

Built Distribution

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

mosheh-2.0.0-py3-none-any.whl (43.4 kB view details)

Uploaded Python 3

File details

Details for the file mosheh-2.0.0.tar.gz.

File metadata

  • Download URL: mosheh-2.0.0.tar.gz
  • Upload date:
  • Size: 127.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.2

File hashes

Hashes for mosheh-2.0.0.tar.gz
Algorithm Hash digest
SHA256 da7a0c9c0b89e39d7c7e8f0b541a25d56e5bf8b5507a68890f1f0314df04c993
MD5 e2fcea7f429feda3e0c31b4107a78d4c
BLAKE2b-256 ec8a9f8decbcb7a066ec077ac095dd32c1e27292003f55206605c5b1acb04792

See more details on using hashes here.

File details

Details for the file mosheh-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: mosheh-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 43.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.2

File hashes

Hashes for mosheh-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4846516d83c18f476bc4b52a8aff45e1db12deaae49e21e013845081a324c6ac
MD5 e649118ee22b6d66d94ef9402909d23e
BLAKE2b-256 18daeed9a6242fd99f2494d93d76641cd4101df8c104c5b1ccda7868f05c469d

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