-
Notifications
You must be signed in to change notification settings - Fork 0
Documentation Guide
This document outlines the documentation standards for the Canvas CLI project, covering both in-code documentation and external documentation. Following these guidelines ensures consistency and helps maintain high-quality, accessible documentation.
canvas-cli/
├── canvas_cli/ # Source code with in-code documentation
├── docs/ # Documentation directory
│ ├── testing_guide.md # Guide for running and writing tests
│ ├── documentation.md # This file - documentation standards
│ └── learning.md # Things I learned while working on this project
├── tests/ # Tests directory
└── README.md # Project overview and quick start
Each Python module should begin with a docstring that explains its purpose:
"""
Canvas API module
Handles communication with the Canvas REST API
"""Every class should have a docstring explaining its purpose and functionality:
class CanvasAPI:
"""Main class for interacting with the Canvas API
This class provides methods to communicate with the Canvas LMS API,
handling authentication, requests, and response parsing.
"""Document all functions and methods using the following format:
def submit_assignment(course_id, assignment_id, file_path):
"""Submit an assignment file to Canvas
Args:
course_id (int): The Canvas course ID
assignment_id (int): The Canvas assignment ID
file_path (str): Path to the file to submit
Returns:
dict: The submission response from Canvas
Raises:
ValueError: If the file doesn't exist or can't be read
RequestException: If the API request fails
"""Use comments to explain complex logic, workarounds, or non-obvious decisions:
# Use a fallback method for Windows systems where curses is not available
if not CURSES_AVAILABLE:
return text_select_course_and_assignment()Mark incomplete functionality with TODO comments that include context:
# TODO: Add support for quiz submissions (waiting for API endpoint documentation)The project README should include:
- Brief project description
- Installation instructions
- Quick start guide
- Basic usage examples
- Links to more detailed documentation
For each major feature, provide:
- Overview of what the feature does
- Command syntax and options
- Example usages
- Common issues and solutions
Example:
## Clone Command
The `clone` command downloads assignment descriptions and related files from Canvas.
### Basic Usage
`canvas clone -cid 12345 -aid 67890`
### Options
- `-cid, --course_id` - Canvas course ID
- `-aid, --assignment_id` - Canvas assignment ID
- `-o, --output` - Output filename (default: README.md)
- `-pdf` - Download linked PDFs
- `-cdl, --convert_links` - Add clean download links| Endpoint | Method | Description | Parameters | Returns |
|---|---|---|---|---|
/courses |
GET | Lists all active courses for the current user |
enrollment_state=active, include[]=favorites, per_page=100
|
Array of course objects sorted by favorite status and name |
/courses/{course_id} |
GET | Gets detailed information about a specific course | Optional properties in params | Course object with details |
/courses/{course_id}/assignments |
GET | Lists all assignments for a specific course | per_page=100 |
Array of assignment objects sorted by status and due date |
/courses/{course_id}/assignments/{assignment_id} |
GET | Gets detailed information about a specific assignment | None | Assignment object with details |
/courses/{course_id}/assignments/{assignment_id}/submissions/self |
GET | Gets the current user's submission for a specific assignment | None | Submission object with details |
/courses/{course_id}/assignments/{assignment_id}/submissions/self/files |
POST | Initiates file upload for assignment submission |
name, size, content_type, on_duplicate
|
Upload URL and parameters |
{upload_url from previous response} |
POST | Uploads file data to specified URL | Upload parameters from previous response | File ID and other file details |
/courses/{course_id}/assignments/{assignment_id}/submissions |
POST | Submits an assignment with uploaded file(s) |
submission_type, file_ids
|
Submission confirmation |
-
enrollment_state=active: Filters courses by enrollment state -
include[]=favorites: Includes information about whether courses are favorited -
per_page=100: Limits results to 100 courses per page
-
name: Filename of the submission -
size: Size in bytes of the file -
content_type: MIME type of the file (default: "application/octet-stream") -
on_duplicate: Action to take if file already exists (default: "overwrite")
-
submission_type: Type of submission (e.g., "online_upload") -
file_ids: Array of file IDs to include in the submission
All API requests require an authentication token provided in the Authorization header:
Authorization: Bearer {token}
The application handles API responses by:
- Sorting and filtering results for better usability
- Error handling with detailed error messages
- Converting date strings to readable format
Documentation should be updated when:
- Adding a new feature
- Changing existing functionality
- Fixing bugs that affect user experience
- Improving or clarifying existing documentation
Before submitting changes, ensure:
- All new functionality is documented
- Affected existing documentation is updated
- Code examples are accurate and tested
- Spelling and grammar are correct
- Formatting is consistent
Consider using these tools to enhance documentation:
- Sphinx - For generating comprehensive HTML documentation
- mkdocs - For simple, readable documentation sites
- doctest - For testing code examples in docstrings
We use Google-style docstrings for consistency:
def function_with_types_in_docstring(param1, param2):
"""Example function with types documented in the docstring.
Args:
param1 (int): The first parameter.
param2 (str): The second parameter.
Returns:
bool: The return value. True for success, False otherwise.
"""