Tool for validating and updating documentation in nbdev projects for use with the fastcore.docments module.
Project description
cjm-nbdev-docments
Overview
cjm-nbdev-docments helps nbdev users adopt and maintain the
fastcore.docments
documentation style. Instead of traditional docstrings, docments uses
inline parameter documentation, making code more concise and readable.
What is docments style?
Instead of this:
def add(x, y):
"""Add two numbers.
Args:
x: First number
y: Second number
Returns:
Sum of x and y
"""
return x + y
Docments style looks like this:
def add(
x: int, # First number
y: int # Second number
) -> int: # Sum of x and y
"Add two numbers"
return x + y
Key Features
- 🔍 Comprehensive Scanning: Automatically scans all exported functions and classes in your nbdev notebooks
- ✅ Compliance Checking: Verifies that all parameters and return values have proper documentation
- 📊 Detailed Reports: Generate text or JSON reports showing compliance status
- 🔧 Auto-fix Support: Automatically add TODO placeholders for missing documentation
- 🔄 Docstring Conversion: Convert existing Google/NumPy/Sphinx style docstrings to docments format
- 💻 CLI Interface: Easy-to-use command-line tool integrated with nbdev workflow
Installation
Install latest from the GitHub repository:
$ pip install git+https://github.com/cj-mills/cjm-nbdev-docments.git
or from conda
$ conda install -c cj-mills cjm_nbdev_docments
or from pypi
$ pip install cjm_nbdev_docments
Quick Start
Basic Usage
Check your nbdev project for documentation compliance:
# Check all notebooks in your project
nbdev-docments
# Get detailed report including compliant functions
nbdev-docments --verbose
# Save report to a file
nbdev-docments --output compliance-report.txt
Auto-fixing Non-compliant Code
Automatically add TODO placeholders for missing documentation:
# Preview what would be fixed
nbdev-docments --fix --dry-run
# Apply fixes
nbdev-docments --fix
Converting Existing Docstrings
Convert traditional docstrings to docments format:
# Convert Google/NumPy/Sphinx style docstrings
nbdev-docments --fix --convert-docstrings
Detailed Usage Examples
Checking a Single Function
You can check individual functions for compliance:
from cjm_nbdev_docments.core import check_function
def example_func(x, y):
return x + y
check_function(example_func)
Checking a Specific Notebook
Check a single notebook file:
from cjm_nbdev_docments.core import check_notebook
check_notebook("00_core.ipynb")
Programmatic Usage
For integration into your own tools:
from cjm_nbdev_docments.report import check_project, generate_json_report
# Check entire project
results = check_project()
# Generate JSON report
report = generate_json_report(results)
# Process results programmatically
for notebook, data in report['by_notebook'].items():
print(f"{notebook}: {len(data['non_compliant'])} issues")
What Gets Checked?
The tool checks for:
- Function/Method Documentation:
- Presence of a docstring
- Documentation for each parameter (except
self) - Documentation for return values (when return type is annotated)
- Type Hints:
- Missing type annotations for parameters
- Missing return type annotations
- Class Documentation:
- Presence of class docstrings
- TODO Tracking:
- Identifies documentation with TODO placeholders
- Helps track documentation debt
CLI Reference
nbdev-docments [OPTIONS]
Options:
--nbs-path PATH Path to notebooks directory (defaults to nbdev config)
--format {text,json} Output format (default: text)
--output, -o PATH Save report to file instead of printing
--verbose, -v Show compliant definitions in text report
--quiet, -q Only show summary (exit code indicates compliance)
--todos-only Show only functions with TODO placeholders
--fix Auto-fix non-compliant functions by adding placeholder docs
--convert-docstrings Convert existing Google/NumPy/Sphinx docstrings to docments format
--dry-run Show what would be fixed without making changes
-h, --help Show help message and exit
Exit Codes
0: All checked definitions are compliant1: One or more definitions are non-compliant
Module Overview
The package consists of five main modules:
1. Core (cjm_nbdev_docments.core)
Core functionality for checking docments compliance. This module
provides: -
DocmentsCheckResult:
Data class for storing compliance check results -
check_definition:
Check a function/class for compliance -
check_function:
Check a single function object -
check_notebook:
Check all definitions in a notebook
2. Scanner (cjm_nbdev_docments.scanner)
Scans nbdev notebooks for exported functions and classes. Key
functions: -
scan_notebook:
Extract all exported definitions from a notebook -
scan_project:
Scan all notebooks in an nbdev project -
get_export_cells:
Find cells with nbdev export directives
3. Report (cjm_nbdev_docments.report)
Generates compliance reports for docments validation. Provides: -
check_project:
Check all definitions in a project -
generate_text_report:
Create human-readable compliance reports -
generate_json_report:
Create machine-readable JSON reports
4. Autofix (cjm_nbdev_docments.autofix)
Automatically adds placeholder documentation to non-compliant functions.
Features: - fix_notebook: Add TODO placeholders for missing
documentation - generate_fixed_source: Generate corrected source
code - Docstring conversion from Google/NumPy/Sphinx to docments format
5. CLI (cjm_nbdev_docments.cli)
Command-line interface for docments compliance checking. The
nbdev-docments command provides easy access to all functionality.
Documentation
Documentation can be found hosted on this GitHub repository’s pages. Additionally you can find package manager specific guidelines on conda and pypi respectively.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cjm_nbdev_docments-0.0.1.tar.gz.
File metadata
- Download URL: cjm_nbdev_docments-0.0.1.tar.gz
- Upload date:
- Size: 29.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
af7d2fc1ab58c5db69d9ed2fe542061a8871f74e6d1b683e4211d13806a46f6f
|
|
| MD5 |
6c3d5c37677577181a81a6d3c9e0187c
|
|
| BLAKE2b-256 |
3df7c4fa893ad1ce0549b45a4f1b5b2e4e2c4b3901707c5d820d55036f9f9446
|
File details
Details for the file cjm_nbdev_docments-0.0.1-py3-none-any.whl.
File metadata
- Download URL: cjm_nbdev_docments-0.0.1-py3-none-any.whl
- Upload date:
- Size: 28.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
693111b87fc7142177575178acc2bebc8cad290d574d114f0768a7b574ff145b
|
|
| MD5 |
3df9912c7c756737c1e187fb41473c17
|
|
| BLAKE2b-256 |
eac9578957c9944fa47ffc703c146a08737c2b4ccbd055095bf394e94f21d750
|