Skip to main content

The sweet way to catch outdated docstrings

Project description

Dolce

Because broken docs leave a bitter taste.

Dolce is a tool designed to help you maintain high-quality docstrings in your Python code. It leverages Large Language Models (LLMs) to ensure that your docstrings are consistent with your code.

Installation

pip install pydolce

Usage

dolce check # Check docstrings in all python files in the current directory and subdirectories
dolce check src # Check in specific directory
dolce check src/myproject/main.py # Check in specific file

Example

dolce check tests/samples

outputs:

[ ERROR ] tests/samples/wrong_descr.py:1 add
  ![#f03c15]- DOC300: Docstring states the function does something that the code does not do. (The docstring claims the function multiplies integers, but the code performs addition.)[/#f03c15]
[ ERROR ] tests/samples/behavior.py:4 post_multiplication
  - DOC300: Docstring states the function does something that the code does not do. (The docstring summary 'Add two integers' does not match the code which performs multiplication and an HTTP POST request.)
  - DOC301: Docstring omits a critical behavior that the code performs. (The code performs a critical behavior (HTTP POST request) but the docstring does not mention this behavior.)
[ ERROR ] tests/samples/typos.py:1 add
  - DOC200: Docstring description contains spelling errors. (The docstring DESCRIPTION contains typo: 'intgers' instead of 'integers'.)
  - DOC201: Docstring parameter description contains spelling errors. (The parameter 'a' description contains typo: 'Te' instead of 'The'.)
[ ERROR ] tests/samples/simple.py:1 fibonacci
  - SIG203: parameters missing
  - SIG503: return missing from docstring
[  OK   ] tests/samples/simple.py:6 subtract

Summary:
✓ Correct: 1
✗ Incorrect: 4

Configure

Right now dolce can be configured via pyproject.toml file. You can specify which rules to check and which to ignore. By default it will check all rules.

[tool.dolce]
target = [
  # Set of rules to check
  "DOC300",
]
disable = [
  # Set of rules to ignore
  "SIG201",
]

Rules checked with LLM

Some rules require an LLM to check docstrings (e.g., docstring spelling, docstring description vs code behavior, etc.). By default dolce will try to run locally qwen3:8b model via ollama provider. You can visit the Ollama site for installation instructions.

qwen3:8b has relatively good performance while fitting in an RTX 4060 GPU (8GB VRAM). However, if you want to use a different model or provider you can configure the default options in the pyproject.toml of your project like this:

[tool.dolce]
url = "http://localhost:11434"
model = "codestral"
provider = "ollama"
api_key = "YOUR_API_KEY_ENVIROMENT_VAR"

Signature check

Signature check is done vía docsig. If you add a [tool.docsig] config section in your pyproject.toml file, dolce will load it to configure the signature check.

# Example from docsign documentation 
# https://docsig.readthedocs.io/en/latest/usage/configuration.html
[tool.docsig]
check-dunders = false
check-overridden = false
check-protected = false
disable = [
    "SIG101",
    "SIG102",
    "SIG402",
]
target = [
    "SIG202",
    "SIG203",
    "SIG201",
]

To be implemented

  • Add cache system to avoid re-checking unchanged code
  • Support for ignoring specific code segments, files, directories, etc
  • Support parallel requests ... much more!

📦 For Developers

Make sure you have the following tools installed before working with the project:

  • uv → Python project and environment management
  • make → run common project tasks via the Makefile

Getting Started

Install dependencies into a local virtual environment:

uv sync --all-groups

This will create a .venv folder and install everything declared in pyproject.toml.

Then, you can activate the environment manually depending on your shell/OS:

  • Linux / macOS (bash/zsh):

    source .venv/bin/activate
    
  • Windows (PowerShell):

    .venv\Scripts\Activate.ps1
    
  • Windows (cmd.exe):

    .venv\Scripts\activate.bat
    

Running

uv run dolce check path/to/your/code

Linting, Formatting, and Type Checking

make qa

Runs Ruff for linting and formatting, and Mypy for type checking.

Running Unit Tests

Before running tests, override any required environment variables in the .env.test file.

make test

Executes the test suite using Pytest.

Building the Project

make build

Generates a distribution package inside the dist/ directory.

Cleaning Up

make clean

Removes build artifacts, caches, and temporary files to keep your project directory clean.

Building docs

make docs

Generates the project documentation inside the dist/docs folder.

When building the project (make build) the docs will also be generated automatically and included in the distribution package.

🤝 Contributing

Contributions are welcome! Please ensure all QA checks and tests pass before opening a pull request.


🚀 Project starter provided by Cookie Pyrate

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

pydolce-0.1.2.tar.gz (15.7 kB view details)

Uploaded Source

Built Distribution

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

pydolce-0.1.2-py3-none-any.whl (14.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pydolce-0.1.2.tar.gz
  • Upload date:
  • Size: 15.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.17

File hashes

Hashes for pydolce-0.1.2.tar.gz
Algorithm Hash digest
SHA256 8effb4b57e948685a37e96cd708ff3ba0ffc50c815439557809b58ff3fd6eaa3
MD5 b3568c53230035fcd5c3f9946acc015b
BLAKE2b-256 05dd0bfb098785d8555359f348602a04ddaf816ebac545bcd9821a45b2be5446

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pydolce-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 14.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.17

File hashes

Hashes for pydolce-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 72b5180b3fa0771098c9f125b5f52ccc2bdfd3564e0c449e9635ecc234a23330
MD5 a46fa7e28fa132c9f131cf600242e09d
BLAKE2b-256 fa1df33993c4fa466d5d3d0308afe95d3755b86c1ee4fa0594c3a28fa7afda69

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