Skip to main content

CLI to auto-generate C doc comments using Tree-sitter and Ollama

Project description

AutoDoc

CLI tool that generates documentation comments for source code using Tree-sitter parsing and a local Ollama model. Initially supports C (.c, .h).

Requirements

  • Python 3.12+
  • uv for environment management
  • Ollama running locally with a compatible code model (e.g., qwen2.5-coder:7b)

Install

Development Installation

# Clone the repository
git clone https://github.com/pierrelgol/autodoc-cli.git
cd autodoc-cli

# Create virtual environment and install in development mode
uv venv --python 3.12.11
uv pip install -e .[dev]

Production Installation

# Install from PyPI (when published)
uv pip install autodoc

# Or install from local wheel
uv pip install dist/autodoc-0.1.0-py3-none-any.whl

Usage

# Basic usage
autodoc /path/to/target --model qwen2.5-coder:7b

# Dry run to see what would be changed
autodoc /path/to/target --dry-run

# Use a different model
autodoc /path/to/target --model llama3.1:8b

# Specify a custom database location
autodoc /path/to/target --db /path/to/custom.db

# Example: Generate documentation for a C project
autodoc /path/to/c-project --model qwen2.5-coder:7b

By default, a SQLite DB .autodoc.sqlite will be created in the target directory to track function body hashes for change detection.

How it works

  • Tree-sitter is used to parse C files into ASTs. No regex is used for detection.
  • For each function:
    • If a doc comment exists and the function hash matches the DB, the function is skipped.
    • If a doc exists but the hash changed, the doc is regenerated and replaced.
    • If no doc exists, a new doc comment is generated and inserted above the function.
  • Edits are applied directly to the source files and are idempotent.

Example

Before running autodoc:

int calculate_fibonacci(int n) {
    if (n <= 1) {
        return n;
    }
    return calculate_fibonacci(n - 1) + calculate_fibonacci(n - 2);
}

After running autodoc . --model qwen2.5-coder:7b:

/**
 * Calculates the nth Fibonacci number using recursion.
 *
 * @param n The position in the Fibonacci sequence (0-based).
 * @return The Fibonacci number at position n.
 */
int calculate_fibonacci(int n) {
    if (n <= 1) {
        return n;
    }
    return calculate_fibonacci(n - 1) + calculate_fibonacci(n - 2);
}

Notes

  • Only C is supported currently. Additional languages can be added by implementing the LanguageAdapter interface in autodoc/adapters.
  • Ensure Ollama is running locally: ollama serve and that the model is available: ollama pull qwen2.5-coder:7b.
  • If you prefer uvx, be aware that uvx autodoc may resolve to the PyPI package named autodoc. Use the local script instead: .venv/bin/autodoc.

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

autodoc_cli-0.2.1.tar.gz (51.5 kB view details)

Uploaded Source

Built Distribution

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

autodoc_cli-0.2.1-py3-none-any.whl (19.2 kB view details)

Uploaded Python 3

File details

Details for the file autodoc_cli-0.2.1.tar.gz.

File metadata

  • Download URL: autodoc_cli-0.2.1.tar.gz
  • Upload date:
  • Size: 51.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.11

File hashes

Hashes for autodoc_cli-0.2.1.tar.gz
Algorithm Hash digest
SHA256 9401f8e18c13156dc5a2010c1e7377f354764cd19da8e72dd56277ef7f9aa1e1
MD5 71006e7c35ca34a2f78e216d7bc9199e
BLAKE2b-256 5bc602528edf114950d6fca310512dca8066698a124070763dbe3ad55044632b

See more details on using hashes here.

File details

Details for the file autodoc_cli-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: autodoc_cli-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 19.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.11

File hashes

Hashes for autodoc_cli-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f987227c01b9e0e40f22e0e8d8b22c16b171d65c7213aa52e0216a6b25991876
MD5 e837bba72f021d29990da6b903a5ad7a
BLAKE2b-256 b1e9d0785ff051f9bd4220d76ea84a3a633c9ae1351e120cb4869c315cba63ca

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