Module documentation¶
βοΈ File Header Management¶
To ensure consistency, all Python source files must include a standardized header containing metadata like copyright, license, and authors. We use a script to automate the checking and fixing of these headers.
By default, the script runs in check mode (dry run) and will NOT modify any files unless explicitly told to do so with fix flags.
π Checking Headers (No Modifications)¶
These commands only check files and report issues without making any changes:
-
make check-headers
: Scans all Python files inmcpgateway/
andtests/
and reports any files with missing or incorrect headers. This is the default behavior. -
make check-headers-diff
: Same ascheck-headers
but also shows a diff preview of what would be changed. -
make check-headers-debug
: Checks headers with additional debug information (file permissions, shebang status, etc.). -
make check-header
: Check a specific file or directory without modifying it.
π§ Fixing Headers (Will Modify Files)¶
β οΈ WARNING: These commands WILL modify your files. Always commit your changes before running fix commands.
-
make fix-all-headers
: Automatically fixes all Python files with incorrect headers across the entire project. -
make fix-all-headers-no-encoding
: Fix all headers but don't require the encoding line (# -*- coding: utf-8 -*-
). -
make fix-all-headers-custom
: Fix all headers with custom configuration options. -
make interactive-fix-headers
: Scans all files and prompts for confirmation before applying each fix. This gives you full control over which files are modified. -
make fix-header
: Fix headers for a specific file or directory with various options.# Fix a single file make fix-header path="mcpgateway/main.py" # Fix all files in a directory make fix-header path="tests/unit/" # Fix with specific authors make fix-header path="mcpgateway/models.py" authors="John Doe, Jane Smith" # Fix with custom shebang requirement make fix-header path="scripts/" shebang=always # Fix without encoding line make fix-header path="lib/helper.py" encoding=no # Combine multiple options make fix-header path="mcpgateway/" authors="Team Alpha" shebang=auto encoding=no
π Header Format¶
The standardized header format is:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Module Description.
Location: ./relative/path/to/file.py
Copyright 2025
SPDX-License-Identifier: Apache-2.0
Authors: Author Name(s)
Your module documentation continues here...
"""
βοΈ Configuration Options¶
authors
: Specify author name(s) for the headershebang
: Control shebang requirementauto
(default): Only required for executable filesalways
: Always require shebang linenever
: Never require shebang line
encoding
: Set tono
to skip encoding line requirementyear
: Override copyright year (forfix-all-headers-custom
)license
: Override license identifier (forfix-all-headers-custom
)debug
: Set to1
to show debug information (for check commands)diff
: Set to1
to show diff preview (for check commands)
πͺ Pre-commit Integration¶
For use with pre-commit hooks:
# Check only (recommended for pre-commit)
make pre-commit-check-headers
# Fix mode (use with caution)
make pre-commit-fix-headers
π‘ Best Practices¶
- Always run
check-headers
first to see what needs to be fixed - Commit your code before running fix commands to allow easy rollback
- Use
interactive-fix-headers
when you want to review each change - Use
check-headers-diff
to preview changes before applying them - Executable scripts should have shebang lines - the script detects this automatically in
auto
mode