Tool to automatically add, update, or delete multi-format copyright headers
Project description
cr-manager -- the Copyright Header Manager
A tool to automatically add, update, or delete multi-format copyright headers in source files.
- Features
- Install
- Action Modes
- Running as pre-commit Hooks
- Running as Binary
- Running as CLI Tool
- Help Message
Features
- Add: Insert copyright headers for multiple file types.
- Update: Force update or insert headers if missing.
- Check: Verify the presence and correctness of headers.
- Delete: Remove detected copyright headers from files.
- Supports recursive directory traversal and filetype auto-detection or override.
- Supports combined author-info and copyright headers.
Install
[!TIP]
- enable the ansicolor in Windows terminal for better output experience.
reg add HKCU\Console /v VirtualTerminalLevel /t REG_DWORD /d 1
Install as Binary
via pipx
[!TIP|label:pipx installation]
$ python3 -m pip install pipx $ python3 -m pipx ensurepath
$ pipx install --force "git+https://github.com/marslo/cr-manager"
# upgrade
$ pipx upgrade cr-manager
# swith python version
$ pipx reinstall cr-manager --python /path/to/python3.x
# -- Linux/MacOS -- #
$ VERSION="$(curl -fsSL https://api.github.com/repos/marslo/cr-manager/releases/latest | jq -r .tag_name)"
# linux
$ curl -fsSL -o cr-manager https://github.com/marslo/cr-manager/releases/download/${VERSION}/cr-manager-linux
$ chmod +x cr-manager
# macos
$ curl -fsSL -o cr-manager https://github.com/marslo/cr-manager/releases/download/${VERSION}/cr-manager-macos
$ chmod +x cr-manager
# -- Windows - running in cmd -- #
> powershell -NoProfile -Command "$v=(Invoke-WebRequest -Uri 'https://api.github.com/repos/marslo/cr-manager/releases/latest' -UseBasicParsing | ConvertFrom-Json).tag_name; Invoke-WebRequest -Uri ('https://github.com/marslo/cr-manager/releases/download/'+$v+'/cr-manager.exe') -OutFile 'cr-manager.exe'; Write-Host ('Downloaded '+$v)"
Install as pre-commit Hook
# if `COPYRIGHT` file can be found in the root directory of this repository
---
repos:
- repo: https://github.com/marslo/cr-manager
rev: v3.0.1
hooks:
- id: cr-manager
args: ["--update"]
# or specify the copyright file to use, and only check specific files/folders
---
repos:
- repo: https://github.com/marslo/cr-manager
rev: v3.0.1
hooks:
- id: cr-manager
args: ["--update", "--copyright", "/path/to/COPYRIGHT"]
files: ^(jenkinsfile/|.*\.(groovy|py|sh)$)
# only check the copyright headers without modifying files after commit
---
repos:
- repo: https://github.com/marslo/cr-manager
rev: v3.0.1
hooks:
- id: cr-manager
args: ["--check"]
stages: [post-commit]
Install as Local Package
# clone the repo
$ git clone git@github.com:marslo/cr-manager.git
# install via pip
# - in global --
$ python3 -m pip install --upgrade --editable .
# - in local --
$ python3 -m pip install --upgrade --user --editable .
# or install via pipx
$ pipx install --editable [--force] .
# verify
$ cr-manager --help
$ cr-manager --version
Action Modes
[!TIP] without any action mode specified, the default action is to add copyright headers.
| OPTION | DESCRIPTION |
|---|---|
| Add mode: Automatically adds copyright headers to files. | |
--check |
Check mode: Verifies file copyright status (match, mismatch, or not found). |
--delete |
Delete mode: Removes detected copyright headers from files. |
--update |
Update mode: Forces replacement of copyright or adds it if missing. |
Supported File Types and Formats
[!TIP]
- check Running as CLI tool first to install necessary dependencies via
poetry install.
| FILETYPE | SUFFIXES |
|---|---|
python, shell, bash, sh, dockerfile |
.py, .sh, .dockerfile |
# without venv
$ poetry run cr-manager --filetype python
# with venv
$ cr-manager --filetype python
result
#===============================================================================
# Copyright © 2025 marslo #
# Licensed under the MIT License, Version 2.0 #
#===============================================================================
| FILETYPE | SUFFIXES |
|---|---|
jenkinsfile, groovy, gradle, java |
.groovy, .java |
# without venv
$ poetry run cr-manager --filetype java
# with venv
$ cr-manager --filetype groovy
result
/**
*******************************************************************************
* Copyright © 2025 marslo *
* Licensed under the MIT License, Version 2.0 *
*******************************************************************************
**/
| FILETYPE | SUFFIXES |
|---|---|
c, cpp, c++, cxx, h, hpp, hxx |
.c, .cpp, .cxx, .h, .hpp, .hxx |
# without venv
$ poetry run cr-manager --filetype c
# with venv
$ cr-manager --filetype cpp
result
/**
* Copyright © 2025 marslo
* Licensed under the MIT License, Version 2.0
*/
Running as pre-commit Hooks
Install pre-commit Hooks
$ pre-commit install --install-hooks
Running Manually
[!TIP] without hook, you can run the cr-manager manually for all files in the repository.
$ pre-commit run cr-manager --all-files
# or particular file
$ pre-commit run cr-manager --files path/to/file
Running Automatcially
$ git commit -m "your commit message"
Unsupported Filetype
$ python -m cli.crm [--update] --filetype python /path/to/file.txt
Running as Binary
Add New Copyright Headers
# single file
$ cr-manager /path/to/file
# files recursively in directories
$ cr-manager --recursive /path/to/directory
# add to non-supported suffixes with supplied filetype
# -- e.e. add to .txt files as python files --
$ cr-manager --filetype python /path/to/file.txt
Update Existing Copyright Headers
[!TIP]
--filetype <TYPE>can be used to force a specific filetype for the update action, overriding auto-detection.
# single file
$ cr-manager --update /path/to/file
# files recursively in directories
$ cr-manager --update --recursive /path/to/directory
Delete Existing Copyright Headers
[!TIP]
--filetype <TYPE>can be used to force a specific filetype for the update action, overriding auto-detection.
# single file
$ cr-manager --delete /path/to/file
# files recursively in directories
$ cr-manger --delete --recursive /path/to/directory
Debug Mode
# *add* without modifying files
$ cr-manager --debug /path/to/file
$ *update* without modifying files
$ cr-manager --update --debug /path/to/file
# *delete* without modifying files
$ cr-manager --delete --debug /path/to/file
Running as CLI Tool
| COMMAND | DESCRIPTION |
|---|---|
$ poetry run python -m cli.crm <cmd> |
requires $ poetry install |
$ python -m cli.crm <cmd> |
requires $ poetry install && source "$(poetry env info --path)/bin/activate" |
$ cr-manager <cmd> |
requires $ poetry install && source "$(poetry env info --path)/bin/activate"or pip install --user -e .or pipx install . |
Poetry Setup
Install Poetry
| ENVIRONMENT | COMMAND |
|---|---|
| linux | curl -sSL https://install.python-poetry.org | python3 - |
| windows | (Invoke-WebRequest -Uri https://install.python-poetry.org -UseBasicParsing).Content | py - |
| pip | pip install poetry |
| pipx | pipx install poetry |
| macOS | brew install poetry |
Init Poetry Environment
[!NOTE] it will:
- create a virtual environment in the current directory
- install the
cr-managerpackage and its dependencies- to enable the pylint in pyproject.toml:
$ poetry add --dev pylint
$ poetry install
- clean up the poetry environment
$ poetry env remove python # - or - $ poetry env remove --all # clear cache $ poetry cache clear pypi --all $ poetry cache clear virtualenvs --all
Run as CLI
-
run in the poetry environment
$ poetry run python -m cli.crm --help
-
run in the virtual environment
to show/check the current venv:
$ echo "${VIRTUAL_ENV}" /Users/marslo/Library/Caches/pypoetry/virtualenvs/cr-manager-Uc1EBq6P-py3.13
to show the package in current venv
$ which -a cr-manager ~/Library/Caches/pypoetry/virtualenvs/cr-manager-Uc1EBq6P-py3.13/bin/cr-manager
# to activate the virtual environment $ source "$(poetry env info --path)/bin/activate" # run as cli $ python -m cli.crm --help # run as package $ cr-manager --help
Help Message
$ poetry run python3 -m cli.crm --help
USAGE
python3 -m cli.crm [--check | --delete | --update] [--copyright FILE] [--filetype TYPE]
[-r|--recursive] [--debug] [--verbose] [-h|--help] [-v|--version]
FILES ...
A tool to automatically add, update, or delete multi-format copyright headers.
POSITIONAL ARGUMENTS:
FILES ... List of target files or directories to process.
ACTION MODES (default is add):
-c, --check Check mode: Verifies file copyright status (match, mismatch, or not found).
-d, --delete Delete mode: Removes detected copyright headers from files.
-u, --update Update mode: Forces replacement of copyright or adds it if missing.
OPTIONS:
--copyright FILE Specify the copyright template file path (default: COPYRIGHT).
-t, --filetype TYPE Force override a filetype instead of auto-detection.
If provided, displays a formatted preview for that type. Supported: bash, c,
c++, cpp, cxx, dockerfile, gradle, groovy, h, hpp, hxx, java, jenkinsfile,
python, sh, shell
-r, --recursive If FILES includes directories, process their contents recursively.
--debug Debug mode: Preview the result of an action without modifying files.
--verbose Show a detailed processing summary.
-h, --help Show this help message and exit.
-v, --version Show program's version number and exit.
Project details
Release history Release notifications | RSS feed
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 cr_manager-3.0.3.tar.gz.
File metadata
- Download URL: cr_manager-3.0.3.tar.gz
- Upload date:
- Size: 20.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.2.1 CPython/3.14.0 Darwin/25.1.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
43c58cf4dadf816e19a6a036202ef5a59571ff2f50408ff3436d782d5c60eb98
|
|
| MD5 |
bf1422c5221428abd4434e8c78f39dcb
|
|
| BLAKE2b-256 |
def791d59a3d0adc4896225b6940cdd14b0987826fecb3980de7682537e32237
|
File details
Details for the file cr_manager-3.0.3-py3-none-any.whl.
File metadata
- Download URL: cr_manager-3.0.3-py3-none-any.whl
- Upload date:
- Size: 19.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.2.1 CPython/3.14.0 Darwin/25.1.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bb3e733122faaf0a772aa618d9c45a0e0134763d874a057e0b3268400bbaa6ba
|
|
| MD5 |
aade1840dc040bad2a24a70b3c5cb281
|
|
| BLAKE2b-256 |
61601984cba61fc428928df42a7692a96b8ec9c690be758ffefd95a383ea2daa
|