Skip to main content

Conhead

Consistent header management.

CLI tool for applying and maintaining consistent headers across source files.

  • Add headers to files that don’t have them.

  • Update fields in files that already have them.

  • Maintain different header configurations for different file types

Installation

Conhead is available as the Python conhead package.

For example, to install using pipx:

$ pipx install conhead
$ conhead --help
Usage: conhead [OPTIONS] SRC

Configuration

Configure conhead via pyproject.toml. Each header template is configured via a separate [tools.conhead.header.<name>] section. Each section is a header definition and can be applied to one or more file extensions.

Example:

[tools.conhead.header.hashhead]
extensions = ['py', 'toml', 'yaml']
template = """
    # Copyright {{YEARS}} Organized Organization
    # SPDX-License-Identifier: Apache-2.0

"""

[tools.conhead.header.slashhead]
extensions = ['c', 'cpp', 'java']
template = """
    // Copyright {{YEARS}} Organized Organization
    // SPDX-License-Identifier: Apache-2.0

"""

Template Definition

A few things to note about the template definition.

Each TOML tools.conhead.header section has a few options:

  • extensions: A list of extensions that the header definition applies to.

  • template: The header template for this header definition. This is the text that is applied to files that have the indicated extensions.

Header Templates

Notice a few things about the header template.

  • The text of the template is indented for better readability withing the pyproject.toml configuration file, however conhead de-indents this text for you.

  • The template contains a field that is kept up to date in the target source file. In this case the {{YEARS}} field writes the current year into every new template. If a file already contains a header with the year in it, and the year is different from the current year, it is updated to show a range of years. For example, a new template would have the {{YEARS}} field replaced with 2020 if it was first written in 2020. When the header is then updated in 2022, this field is rewritten as 2020-2022.

  • If you need to write some text that contains certain characters used to describe fields, you must escape them. Examples are \{, \} and \\. These characters will appear in the rendered header without the preceding slash.

Usage

Let’s say there is a python file without a header at hello.py:

def hello():
    print("Greetings!")

You can apply the hashhead header template defined in pyproject.toml and view the results by:

$ conhead hello.py
WARNING: missing header: hello.py

$ cat hello.py
# Copyright 2022 Organized Organization
# SPDX-License-Identifier: Apache-2.0


def hello():
    print("Greetings!")

conhead will recognize the header if you apply it to hello.py again and will not write a second header.

$ conhead hello.py

$ cat hello.py
# Copyright 2022 Organized Organization
# SPDX-License-Identifier: Apache-2.0


def hello():
    print("Greetings!")

Pre-commit

conhead is pre-commit ready. To use with pre-commit, add the repo to your .pre-commit-config.yaml.

For example:

- repo: https://github.com/slobberchops/conhead
  rev: v0.4.0
  hooks:

    - id: conhead

Metadata

Release files for conhead 1.0.0

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

Source distribution (sdist)

Source distribution for conhead 1.0.0
File Size Uploaded Provenance Actions
conhead-1.0.0.tar.gz 17.3 kB Without provenance Details for conhead-1.0.0.tar.gz

Release files / conhead-1.0.0.tar.gz

Download URL conhead-1.0.0.tar.gz
Size 17.3 kB
Tags Source
SHA-256 checksum
How to use checksums
4f3e3b6feda4a13b92584f16c7b3816ad6d3bfef98aea290c62369e041d82c82
BLAKE2b-256 checksum
How to use checksums
1404ffdbdf4f4e41724b3d206d1068e45fe21e7ce082c6073adc6d03015eb43f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.8.10

Security for conhead 1.0.0

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