Skip to main content

setup_headers

Automatic maintenance of licensing information in headers of source files.

Searches a project directory tree finding all files matching a sequence of glob patterns (e.g. **/*.py,*.cfg,**/config/*.yml), and replaces any comments on the beginning of the file by lines from a header file, preceded by a comment marker (a prefix).

The substitution does not apply to "hashbangs" (anything started by #!). These will be kept where they were originally.

See LICENSE for important licensing information.

Installation

You can use any pip compliant tool:

pip install jfaleiro.setup_headers

Or something like poetry:

poetry add jfaleiro.setup_headers

If you use pre-commit a pip or poetry installation is not required. See below.

Configuration

As of release 0.0.5, with the migration to poetry, distutils.commands is no longer supported.

Since the use of poetry plugins requires a dependency on poetry, a massive toolset, we moved away from a build tool extension altogether. We will reconsider when and if Python's strugle with its dependency hell improves.

The configuration of where license headers will be added is given in a file named headers.yaml by default:

header: HEADER
prefixes:
  - prefix: "#"
    globs: [
    "setup_headers/**/*.py",
    "test/**/*.py",
    ".devcontainer/Dockerfile",
    "Makefile"]
  - prefix: "##"
    globs:
    - "*.yml"
    - "*.yaml"
  - prefix: "//"
    globs:
    - ".devcontainer/devcontainer.json"
  - prefix: ";"
    globs: [
        setup.cfg,
        tox.ini
      ]

Each prefix is a recognized comment character(s) on the beginning of each line in the header. Globs are a pathlib.glob() pattern. Only relative patterns are allowed.

The **/* comes from Python's Pathlib and indicates all matches under that directory. The pattern ** will match only sub-directories, what is probably not what you want.

Create a file matching the name on the header with what you want to be inserted on the beginning of all files that match the globs pattern, something like:

     my_awesome_project - Does something awesome

     Copyright (C) 2019 Joe Doe.

     This program is not free. You should pay lots of money to use it.
     Contact me for my paypal account.

     You should have received a copy of My Proprietary License
     along with this program.  If not, see <http://joe.doe/licenses/>.

Use

Setuptools Command

As of release 0.0.5, with the migration to poetry, distutils.commands is no longer supported. See above.

Command Line

You can also use the CLI for any projects that do not care or rely on setuptools:

$ adjust-license-header --help
usage: adjust-license-header [-h] [--config CONFIG] [--dry-run] [--prefix-mandatory] [files [files ...]]

positional arguments:
  files               process only files in the list (default: None)

optional arguments:
  -h, --help          show this help message and exit
  --config CONFIG     name of the YAML config file (default: headers.yaml)
  --dry-run           don't apply any changes (default: False)
  --prefix-mandatory  failure if file is not associated to a prefix (default: False

Pre-Commit

Finally, the preferred way, you can keep license notices up to date at git commit time. Just add a .pre-commit-config.yaml to your project root:

# See https://pre-commit.com for more information on pre-commit
# See https://pre-commit.com/hooks.html for more hooks

repos:
-   repo: https://gitlab.com/jfaleiro.open/setup_headers
    rev: 0.0.4-dev10
    hooks:
    - id: adjust-license-header

If you use pre-commit a pip or poetry installation is not required.

Metadata

Release files for jfaleiro.setup-headers 0.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for jfaleiro.setup-headers 0.0.4
File Interpreter ABI Platform Actions
jfaleiro.setup_headers-0.0.4-py3-none-any.whl Python 3 none any Details for jfaleiro.setup_headers-0.0.4-py3-none-any.whl

Release files / jfaleiro.setup_headers-0.0.4-py3-none-any.whl

Download URL jfaleiro.setup_headers-0.0.4-py3-none-any.whl
Size 21.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1473f02e23f5ff7db91b3f2be18c6289e390d5080e8a2826b5db01a08e042075
BLAKE2b-256 checksum
How to use checksums
fa3f5701cc9b5eb960bd153d5ff086a9b3ff9d4dcea751e51a2f5e8f26b34d6a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.8 CPython/3.8.11 Linux/5.10.47-linuxkit

Security for jfaleiro.setup-headers 0.0.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page