Skip to main content

Text file copyright notice linter and updater.

Project description

copyright2

License GitHub Actions Workflow Status

copyright2 (copyright-right) is a text file copyright notice lint and update tool to help keep the years listed in your copyright notices up to date with when they were modified.

Features

  • Supports any text file.
  • Configurable to match your specific copyright notice format.
  • Configurable to include/exclude specific files/directories.
  • Check mode which shows changes missing from files.
  • Fix mode which updates files with missing changes.
  • Intelligently simplifies copyright year expressions e.g. 2009,2010,2011,2013 to 2009-11,3.
  • Git path mode for using Git to identify which files to check in CI.
  • Configurable to quickly add current year to modified files when using Git path mode.

Getting Started

Prerequisites

  • Python 3.10 or later

Installation

Install using your favourite package manager e.g.

pip install copyright2
poetry install copyright2

or, if using as an application only, install in isolation e.g.

pipx install copyright2
uv tool install copyright2

Usage

Configuration

Create a .copyrightrc.yaml at the top level of your project and describe your copyright notice and specify some files to manage using regular expressions.

By default, no files or directories are included and no changes are made to included files.

# .copyrightrc.yaml
root: yes
copyright: "Copyright \(c\) {ts}"
include_dirs:
  - .*  # All directories.
include_files:
  - README.md$
simplify: yes  # Simplify copyright year expression.

Options specified in .copyrightrc.yaml of subdirectories take precedence for that directory.

# src/.copyrightrc.yaml
include_files:
  - .*\.py$  # All .py files in this directory and below.
# src/ext/.copyrightrc.yaml
include_files:
  - .*\.(c|h)$  # Only .c, .h files in this directory and below.

Run (development)

Check files that will be managed by copyright

examples/readme$ copyright list
README.md
src/readme.py
src/ext/readme.h
src/ext/readme.c
4

then scan for changes that need to be made to any copyright notices

examples/readme$ copyright check
README.md: notice not found
src/ext/readme.h: 2: simplified timestamp expression
2

and fix them

examples/readme$ copyright fix
README.md: notice not found
fixing src/readme.py... ok
fixing src/ext/readme.h... ok
2

examples/readme$ git diff
diff --git a/examples/readme/src/readme.py b/examples/readme/src/readme.py
index 65785b6..cb2603b 100644
--- a/examples/readme/src/readme.py
+++ b/examples/readme/src/readme.py
@@ -1 +1 @@
-"""Copyright (c) 2023,2024,2025."""
+"""Copyright (c) 2023-5."""

Run (CI)

The check command will only return 0 if no required changes are detected.

To restrict the check to only files which have changed between the previous and current commit

examples/readme$ copyright list --find-path git HEAD~1
src/readme.py
1

To ensure that the current year has been added to files which have changed between the previous and current commit, add the --add-now flag

examples/readme$ copyright check --find-path git HEAD~1 --add-now
src/readme.py: 1: added year 2024 to timestamp
1

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

copyright2-0.1.1.tar.gz (14.6 kB view details)

Uploaded Source

Built Distribution

copyright2-0.1.1-py3-none-any.whl (11.9 kB view details)

Uploaded Python 3

File details

Details for the file copyright2-0.1.1.tar.gz.

File metadata

  • Download URL: copyright2-0.1.1.tar.gz
  • Upload date:
  • Size: 14.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.5

File hashes

Hashes for copyright2-0.1.1.tar.gz
Algorithm Hash digest
SHA256 30ed53fc763e8a0250e1ff76de24262d82206dac2e047110426257c0e29746b5
MD5 4d804a7afb4781894d85fd9fa7b3aa2e
BLAKE2b-256 c436a43a4e834b90608ea00b322069470726ca3c31d2053dca92f82ee38edef8

See more details on using hashes here.

File details

Details for the file copyright2-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: copyright2-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 11.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.5

File hashes

Hashes for copyright2-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c08c5621968cea4de1740eca50dfb28e9111c32f0d03d2ec83fe20065f2843ae
MD5 96d351e1d78abcc8d10899ae1b444f14
BLAKE2b-256 041c5b732dfd7d695c0ac9ec02d1d41d29b4efd23e849cecb07f1de8d3abd3e6

See more details on using hashes here.

Supported by

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