Pre-commit hook to check and auto-add copyright notices with multi-format and regex support
Project description
SNY Copyright Checker
A powerful pre-commit hook that automatically checks and adds copyright notices to your source files with support for multiple file formats and intelligent year management.
Key Features
- ✨ Multi-Format Support - Different copyright formats for each file type (Python, C, SQL, JavaScript, etc.)
- 🔧 Auto-Fix - Automatically adds missing copyright notices
- 🧠 Smart Replacement - Intelligently updates similar copyrights while preserving year history
- 🎯 Git-Aware - Manages copyright years based on Git history
- 🚀 Quick Setup - Interactive wizard for first-time configuration
- 🔄 Line Ending Safe - Preserves CRLF/LF line endings
- 🚫 Ignore Files - Respects
.gitignoreand.copyrightignorepatterns - 📁 Hierarchical Templates - Different copyrights per directory for monorepos
Quick Start
1. Install
pip install sny-copyright-checker
2. Configure
Run the interactive setup wizard:
sny-copyright-checker init
The wizard will guide you through license selection, company details, file type configuration, and automatically creates or updates .pre-commit-config.yaml for you.
3. Use
As Pre-commit Hook
Add to your .pre-commit-config.yaml:
repos:
- repo: https://github.com/mu-triv/sny-copyright-checker
rev: v1.0.8
hooks:
- id: sny-copyright-checker
args: [--notice=copyright.txt]
Install and run:
pre-commit install
git commit -m "Your changes" # Hook runs automatically
Command Line
# Check and fix files
sny-copyright-checker file1.py file2.js
# Check only (no modifications)
sny-copyright-checker --no-fix *.py
# Replace outdated copyrights
sny-copyright-checker --replace --changed-only
Documentation
- USER_GUIDE.md - Complete usage guide with all features and options
- QUICKSTART.md - Step-by-step getting started guide
- INIT_WIZARD.md - Interactive setup wizard documentation
- EXAMPLES.md - Usage examples and common scenarios
- CHANGELOG.md - Version history and release notes
Advanced Features
- GIT_AWARE_YEAR_MANAGEMENT.md - Git-based year tracking
- HIERARCHICAL_TEMPLATES.md - Per-directory copyrights
- IGNORE_FILES.md - Ignore pattern configuration
- REPLACE_FEATURE.md - Smart copyright replacement
How It Works
- Detects file type by extension
- Checks for existing copyright using regex patterns
- Adds missing copyright with current year (if
--fixenabled) - Preserves existing copyrights and line endings
- Updates years based on Git history (Git-aware mode)
Template Example
Create a copyright.txt with your company details:
[VARIABLES]
SPDX_LICENSE = MIT
COMPANY = Your Company Name
YEAR_PATTERN = {regex:\d{4}(-\d{4})?}
[.py, .yaml, .yml, .sh]
# SPDX-License-Identifier: {SPDX_LICENSE}
# Copyright {YEAR_PATTERN} {COMPANY}
[.js, .ts, .go, .rs, .java]
// SPDX-License-Identifier: {SPDX_LICENSE}
// Copyright {YEAR_PATTERN} {COMPANY}
Or use sny-copyright-checker init to generate this automatically.
Supported Languages
Python • JavaScript • TypeScript • C • C++ • Java • Go • Rust • SQL • Shell • YAML • Markdown
Add more by editing your copyright.txt template.
Development
# Clone and install
git clone https://github.com/mu-triv/sny-copyright-checker.git
cd sny-copyright-checker
pip install -e .
# Run tests
pytest tests/
License
MIT License - see LICENSE file for details.
Author
Tri VU Khac (khactri.vu@sony.com)
Sony Group Corporation
R&D Center Europe Brussels Laboratory
Acknowledgments
- Inspired by leoll2/copyright_notice_precommit
- Built for pre-commit framework
Support
- Repository: https://github.com/mu-triv/sny-copyright-checker
- Issues: https://github.com/mu-triv/sny-copyright-checker/issues
- PyPI: https://pypi.org/project/sny-copyright-checker/
For complete documentation, see USER_GUIDE.md.
Project details
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 sny_copyright_checker-1.0.8.tar.gz.
File metadata
- Download URL: sny_copyright_checker-1.0.8.tar.gz
- Upload date:
- Size: 103.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b8174afbbc54ff0c2056f0d1256b1ac87616a4b2eb6341957f48559bddf82459
|
|
| MD5 |
6856800c1a3b903c2648bb134c975790
|
|
| BLAKE2b-256 |
f61e298623a6a7e1e1728219df0c53faac7700a578e3a36d4bba66b3c72e6e4a
|
File details
Details for the file sny_copyright_checker-1.0.8-py3-none-any.whl.
File metadata
- Download URL: sny_copyright_checker-1.0.8-py3-none-any.whl
- Upload date:
- Size: 31.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dc3d8d768cb3185b374407276ef5b861ded554ae9ae2cbbc4756c82fe861aeba
|
|
| MD5 |
62992de7d7115b05bf78bc85869f8a9f
|
|
| BLAKE2b-256 |
64d74b7964cbc91093f9b4e686d947a528747be693a6284644840a4d31eb6f47
|