-
Notifications
You must be signed in to change notification settings - Fork 243
chore(file-headers): add script to verify and fix file headers #656
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore(file-headers): add script to verify and fix file headers #656
Conversation
Signed-off-by: Arnav Bhattacharya <[email protected]>
Signed-off-by: Arnav Bhattacharya <[email protected]>
Really great work on this! Thank you for contributing. I will work on the fixes outlined below, then merge. β Overall AssessmentThis is a well-implemented feature that addresses the need for consistent file headers across the Python codebase. The script uses Python's AST module for safe parsing and modification, which is the correct approach. π Code Quality ChecklistPasses testing
Implementation Quality
Code Structure
Integration
π§ Issues to Address1. Line Length Warning
|
Signed-off-by: Mihai Criveti <[email protected]>
Signed-off-by: Mihai Criveti <[email protected]>
Signed-off-by: Mihai Criveti <[email protected]>
Signed-off-by: Mihai Criveti <[email protected]>
Signed-off-by: Mihai Criveti <[email protected]>
Signed-off-by: Mihai Criveti <[email protected]>
Signed-off-by: Mihai Criveti <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to merge! Also added (inactive) github actions, closes #315
π Summary of All Changes
1. Script Behavior Changes π
- Default mode is now CHECK - Running without flags won't modify any files
- Explicit
--fix
flag required - Must use--fix --path <path>
to modify specific files --fix
validates--path
- Script now errors if--fix
is used without--path
- Clear mode indicators - Script prints which mode it's running in at startup
2. New Script Features β¨
- Shebang control:
--require-shebang auto|always|never
(auto = only for executable files) - Encoding control:
--no-encoding
to skip encoding line requirement - Debug mode:
--debug
shows file permissions, shebang status, etc. - Diff preview:
--show-diff
shows what would change in check mode - Custom config:
--copyright-year
,--license
for project-specific needs - Better path validation: Ensures paths are within project boundaries
- Author validation: Ensures non-empty author strings
- Executable detection: Automatically determines if files need shebang based on permissions
3. Makefile Enhancements π§
- Dynamic help integration - Follows your
# help:
pattern, no separate help target - New targets added:
check-headers-debug
- Check with debug infocheck-headers-diff
- Check with diff previewfix-all-headers-no-encoding
- Fix without encoding requirementfix-all-headers-custom
- Fix with custom year/license/shebangpre-commit-check-headers
- For pre-commit integrationpre-commit-fix-headers
- For pre-commit fixing
- Enhanced parameters:
shebang=auto|always|never
for shebang controlencoding=no
to skip encoding linedebug=1
anddiff=1
for check commandsyear=YYYY
andlicense=...
for custom configs
4. Safety Improvements π‘οΈ
- No accidental modifications - Check mode by default
- Clear warnings when running fix commands
- Error suppression removed from Makefile (proper exit codes)
- Path validation prevents processing files outside project
- Better error messages throughout
5. Documentation Updates π
- Reorganized by safety - Check modes (safe) vs Fix modes (modifies)
- All new features documented with examples
- Configuration options explained in detail
- Best practices section added
- Pre-commit integration documented
- Header format example included
6. Code Quality Improvements π―
- Full Google-style docstrings with examples
- Complete type annotations using Python's typing module
- Extensive doctests for all functions
- Better error handling with specific exceptions
- Cleaner code structure with modular functions
- Constants for configuration
Signed-off-by: Mihai Criveti <[email protected]>
Signed-off-by: Arnav Bhattacharya [email protected]
β¨ Feature / Enhancement PR
π Epic / Issue
Link to the epic or parent issue:
Closes #317
π Summary
This PR introduces a script to automate checking and fixing file headers for Python source files, ensuring consistent metadata like copyright, license, and file location. It also adds
make
targets for easy execution and updates the development documentation.π§ͺ Checks
make lint
passesmake test
passesπ Notes
This change addresses the need for consistent file headers, which improves code navigation and maintainability.
Key Additions:
/.github/tools/fix_file_headers.py
that can scan, check, and fix file headers in both interactive and automated modes.Makefile
for easy header management:make check-headers
: Performs a dry run to find files with incorrect headers.make fix-all-headers
: Automatically fixes all incorrect headers.make interactive-fix-headers
: Prompts for confirmation before fixing each file.make fix-header path="..."
: Fixes a specific file or directory.make fix-header path="..." authors="..."
: Fixes a specific file or directory, with an option to override the author.CONTRIBUTING.md
has been updated to include the new file header requirements.make
targets are now in the development documentation atdocs/docs/development/documentation.md
.This implementation uses Python's
ast
module to safely parse and modify docstrings, preserving existing content while enforcing the new standard.