π Documentation GuidelinesΒΆ
This guide covers best practices for writing effective documentation for CLOE Toolbox components.
Principles of Writing Good Code DocumentationΒΆ
IntroductionΒΆ
Good documentation is very important for us to to make your code understandable and usable by others (and future you). Here are some tips to help you write useful docs.
Key PrinciplesΒΆ
- Keep It Clear and Simple: Use plain language. Avoid jargon unless itβs necessary and explain it if you do use it.
- Be Consistent: Stick to the same terms, style, and formatting throughout.
- Know Your Audience: Tailor your writing to who will be reading it. For non-professional developers, keep it simple and add plenty of examples.
- Cover Everything: Make sure your docs cover all bases β installation, usage, API details, and troubleshooting.
- Update Regularly: Keep your documentation up-to-date with any changes in your code.
Structure of Good Documentation for the websiteΒΆ
- Introduction: What does the building block do? Why does it exist?
- Getting Started: How to install it and a quick-start guide.
- Usage Examples: Practical examples of how to use the code.
- API Reference: Detailed info on functions, classes, and methods.
- FAQ/Troubleshooting: Common issues and questions.
- Contributing: How others can contribute to the project.
Writing Documentation with MkDocs for MaterialΒΆ
Introduction to MkDocsΒΆ
MkDocs is a tool for creating static websites specifically for documentation. The Material theme makes it look really nice and professional.
Setting Up MkDocsΒΆ
- Install MkDocs and the Material Theme:
- Create a New MkDocs Project:
Using Info Boxes and Code BoxesΒΆ
- Info Boxes: Use
!!!followed by a type (note, warning, etc.) to create info boxes.
- Code Boxes: Use triple backticks ``` to create code blocks.
Automating Documentation DeploymentΒΆ
The default copier Python package template includes an Azure DevOps Pipeline for uploading documentation. To set this up:
- Activate the pipeline
- Get in touch with CLOE product manager to connect the pipeline.
- Configure the pipeline to trigger on commits to your documentation branch.
Chapter 3: Documenting Code within PythonΒΆ
Inline Documentation with DocstringsΒΆ
Docstrings are super useful for explaining what your modules, classes, and functions do.
def example_function(param1: int, param2: str) -> bool:
"""
This function demonstrates an example.
Args:
param1 (int): The first parameter.
param2 (str): The second parameter.
Returns:
bool: The return value. True for success, False otherwise.
"""
return True
Using Mkdocstrings and Griffe-FieldzΒΆ
- Mkdocstrings: This plugin automatically extracts and renders docstrings in your MkDocs site.
-
Install mkdocstrings:
-
Configure
mkdocs.yml: -
Add placeholders in your markdown files:
-
Griffe-Fieldz: Enhances mkdocstrings with typing hints and Pydantic field descriptions.
-
Install griffe-fieldz:
-
Integrate with mkdocstrings in
mkdocs.yml:
Combining Pydantic with DocumentationΒΆ
Using Pydantic models helps you generate detailed class documentation without additional effort automatically.
from pydantic import BaseModel, Field
class User(BaseModel):
id: int = Field(..., description="The unique identifier for a user")
name: str = Field(..., description="The name of the user")
In your markdown file: