Skip to main content

Pre-commit hook to check and auto-add copyright notices with multi-format and regex support

Project description

SNY Copyright Checker

License: MIT Python 3.10+ PyPI version Tests

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 .gitignore and .copyrightignore patterns
  • 📁 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.7
    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

Advanced Features

How It Works

  1. Detects file type by extension
  2. Checks for existing copyright using regex patterns
  3. Adds missing copyright with current year (if --fix enabled)
  4. Preserves existing copyrights and line endings
  5. 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

Support


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

sny_copyright_checker-1.0.7.tar.gz (101.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sny_copyright_checker-1.0.7-py3-none-any.whl (30.7 kB view details)

Uploaded Python 3

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page