Skip to main content
Ctrl+K

murky 0.0.6.dev11+g815acf9 documentation

  • create_release_notes
  • update_copyright_date
  • create_release_notes
  • update_copyright_date

Section Navigation

  • update_copyr...

update_copyright_date#

Update the copyright date in all (project) text files.

Show the updated copyright ynotices in the murky package:

update_copyright_date -dv /path/to/source/murky "Pete R. Jemian"

Make the changes:

update_copyright_date -v /path/to/source/murky "Pete R. Jemian"

Motivation#

A software project under active development and maintenance should edit its copyright notice annually to include (or extend) to the current year. This task is often neglected as a project matures when the number of files to be updated increases. Sometimes, the copyright notice in some files is missed.

How does it work?#

The code looks through all text files for lines with a copyright notice. The search is independent of upper or lower case. Consider these examples:

# Copyright (C) 1988-2020 Free Software Foundation, Inc.
Copyright (C) 2008-2022 NeXus International Advisory Committee (NIAC)
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
# Copyright (c) 2006, 2008 Junio C Hamano
Copyright (C) 2000, 2001, 2002, 2007, 2008 Free Software Foundation, Inc.
copyright = "(c) 2014-2024, Project Copyright Owner"
Copyright 2015 Jane Doe
Copyright (c) 1215, 1871, 1973, 1975-1991, 2024 Some Project Owner

The code edits the list or range of years to include the current year. For example, when run in 2024, the years in these examples are:

before

after

1988-2020

1988-2024

2008-2022

2008-2024

2007

2007-2024

2006, 2008

2006, 2008, 2024

2000, 2001, 2002, 2007, 2008

2000, 2001, 2002, 2007, 2008, 2024

2000

2000-2024

2014-2024

2014-2024 (same, so file is not changed)

2015

2015-2024

1215, 1871, 1914-1918, 2008

1215, 1871, 1914-1918, 2008, 2024

Copyright notices share a common format. [1]

Generally, a copyright notice will read something like “Copyright 2015 Jane Doe.”

The list or range of years is identified by matching common text before and after the text that describes the years. It is common that the text before the years is the text representation of the copyright symbol ("(C)"). The text after the years is the name of the copyright owner. The years are four digit numbers.

[1]

See How to Make a Copyright Notice: https://www.wikihow.com/Make-a-Copyright-Notice

Example#

Consider a file with this copyright notice:

Copyright (c) 1215, 1871, 1973, 1975-1991 Some Project Owner

In 2024, executing command:

update_copyright_date.py -s "(c)" . Owner

updates the years in the copyright notice to:

Copyright (c) 1215, 1871, 1973, 1975-1991, 2024 Some Project Owner

Note

This is a comparable bash shell command to find (but not replace) all matching lines:

$ grep -iIR "(c)" | grep -i Owner

Command Positional Arguments#

root_dir

Directory with the text files with copyrights to be updated. A value of . means the current directory. The value can be a relative path (such as . or ../project) or an absolute path (such as /home/user/Documents/project/).

owner

The text to be matched that appears after the years. Typically, the name of the copyright owner.

Command Options#

Command line options may be combined as long as any parameters required by an option appear in the correct order.

  • -v is the same as --verbose

  • -vv is the same as -v -v or --verbose --verbose

  • -dvvs "(C)" is the same as --dry-run -vv --symbol "(C)" (Note that the s option must come last since its required parameter must appear next.)

-h, --help#

Help for how to use the command-line program:

$ update_copyright_date --help
usage: update_copyright_date [-h] [-s [SYMBOL]] [-y [YEAR]] [-i] [-d] [-v] [-q] [-V] root_dir owner

Update the copyright date in all project text files.

positional arguments:
root_dir              project root directory
owner                 Copyright owner text

options:
-h, --help            show this help message and exit
-s [SYMBOL], --symbol [SYMBOL]
                        Copyright symbol text. Default: '(C)'
-y [YEAR], --year [YEAR]
                        Final copyright year. Default: '2024'
-d, --dry-run         Don't update any files. Default: False
-v, --verbose         verbose output (repeat for increased verbosity)
-q, --quiet           quiet output (show errors only), overrides -v option
-V, --version         show program's version number and exit

Finds text files in ``ROOT_DIR`` and all its subdirectories. In each file, looks
for lines that contain the pattern of ``SYMBOL YEARS OWNER`` (case-independent)
and updates ``YEARS`` to include the current year. YEARS is a list or range of
4-digit numbers.
$

The --help option overrides any other options.

-s, --symbol#

The text to be matched that appears before the years. The default SYMBOL is (C), common to many copyright notices.

$ update_copyright_date . Owner
$

which is equivalent to:

$ update_copyright_date --symbol "(C)" . Owner
$

Quotes are necessary around the (C) to indicate to the shell that SYMBOL is verbatim text and not a shell expansion.

To match Copyright 2015 Jane Doe, use these definitions of SYMBOL and OWNER in the command line:

$ update_copyright_date --symbol Copyright . "Jane Doe"
$

Quotes are necessary around the text Jane Doe to indicate to the shell that SYMBOL has both words.

-y, --year#

The new year to be added. The default is the current year.

$ update_copyright_date -d --year 2125 . Jemian
$

-d, --dry-run#

A dry run shows what changes will be made without modifying any files.

$ update_copyright_date -dry-run . Jemian
$

-v, --verbose#

Increase the level of progress messages. Warnings and errors will always be reported. Use once to add information messages. Use twice to add both information and debugging messages. More than two will be the same two.

$ update_copyright_date -d -v . Jemian
No changes necessary: .../murky/pyproject.toml
No changes necessary: .../murky/murky/murky_tool.py
No changes necessary: .../murky/murky/update_copyright_date.py
No changes necessary: .../murky/murky/murky_create.sh
No changes necessary: .../murky/murky/create_release_notes.py
$

-q, --quiet#

Do not write anything to the console, except for warnings and error messages. This option overrides any --verbose options.

$ update_copyright_date -d -v . Jemian
No changes necessary: .../murky/pyproject.toml
No changes necessary: .../murky/murky/murky_tool.py
No changes necessary: .../murky/murky/update_copyright_date.py
No changes necessary: .../murky/murky/murky_create.sh
No changes necessary: .../murky/murky/create_release_notes.py
$

-V, --version#

Software version of this application. The --version option overrides any other options except --help.

$ update_copyright_date --version
$

Source Code Documentation#

Update the copyright date in all project text files.

Finds text files in ROOT_DIR and all its subdirectories. In each file, looks for lines that contain the pattern of SYMBOL YEARS OWNER (case-independent) and updates YEARS to include the current year. YEARS is a list or range of 4-digit numbers.

Command Line Application

main()

Entry point for command-line update_copyright_date application.

command_args()

Get the command-line arguments, handle syntax errors.

Public API

find_source_files(path)

Return a list of all files in path and all of its subdirectories.

update(filename, owner[, symbol, dry_run, year])

Update the copyright year in filename.

Internal Functions

find_years_indices(line, symbol, owner)

Return the start and end indices of the copyright years in the text.

is_recognized_text_file(path)

Is the file on this path acceptable as text?

qualify_inputs(root_path)

Raise error if this program cannot continue, based on the inputs.

revise_copyright_line(line, symbol, owner, year)

Update the copyright year on this line.

setup_logging(verbosity)

Set up the logging subsystem.

sift_file_list(file_list)

From a list of all files, return a list of the files recognized as text.

UnexpectedSeparatorError

Separator between years in copyright notice was not expected.

YearsNotFound

Did not find list or range of years in matching copyright line.

exception murky.update_copyright_date.UnexpectedSeparatorError#

Separator between years in copyright notice was not expected.

exception murky.update_copyright_date.YearsNotFound#

Did not find list or range of years in matching copyright line.

murky.update_copyright_date.command_args()#

Get the command-line arguments, handle syntax errors.

murky.update_copyright_date.find_source_files(path)#

Return a list of all files in path and all of its subdirectories.

murky.update_copyright_date.find_years_indices(line, symbol, owner)#

Return the start and end indices of the copyright years in the text.

murky.update_copyright_date.is_recognized_text_file(path)#

Is the file on this path acceptable as text?

murky.update_copyright_date.main()#

Entry point for command-line update_copyright_date application.

  • source directory named as command line argument

  • target directory is specified (or defaults to present working directory)

murky.update_copyright_date.qualify_inputs(root_path)#

Raise error if this program cannot continue, based on the inputs.

murky.update_copyright_date.revise_copyright_line(line, symbol, owner, year)#

Update the copyright year on this line.

PARAMETERS

linestr

Line of text that contains a copyright notice.

symbolstr

The text to be found before the text with the years.

ownerstr

The text to be found after the text with the years.

yearstr

Line of text that contains a copyright notice.

murky.update_copyright_date.setup_logging(verbosity)#

Set up the logging subsystem.

See:

https://xahteiwi.eu/resources/hints-and-kinks/python-cli-logging-options/

murky.update_copyright_date.sift_file_list(file_list)#

From a list of all files, return a list of the files recognized as text.

murky.update_copyright_date.update(filename, owner, symbol='(C)', dry_run=False, year='2024')#

Update the copyright year in filename.

previous

create_release_notes

On this page
  • Motivation
  • How does it work?
  • Example
  • Command Positional Arguments
  • Command Options
    • -h, --help
    • -s, --symbol
    • -y, --year
    • -d, --dry-run
    • -v, --verbose
    • -q, --quiet
    • -V, --version
  • Source Code Documentation
    • UnexpectedSeparatorError
    • YearsNotFound
    • command_args()
    • find_source_files()
    • find_years_indices()
    • is_recognized_text_file()
    • main()
    • qualify_inputs()
    • revise_copyright_line()
    • setup_logging()
    • sift_file_list()
    • update()
Show Source

© Copyright (c) 2014-2024, Pete R. Jemian.

Created using Sphinx 7.2.6.

Built with the PyData Sphinx Theme 0.15.2.