Skip to main content

A Python CLI to inspect, validate, and manage license and copyright headers.

Project description

TopMark

PyPI version Documentation Status Downloads GitHub release

TopMark is a command-line tool to inspect, insert, validate, and manage file headers in diverse codebases.
It maintains consistent metadata across files by supporting multiple comment styles, configuration formats, and dry-run safety.


📚 Documentation

Full documentation is hosted on Read the Docs:
👉 https://topmark.readthedocs.io

This README provides an overview. See the docs for deeper topics (install, usage, API, CI/CD, etc.).


🧩 Features

  • Detect, insert, and replace file headers across multiple file types
  • Comment-aware (line and block styles)
  • Configurable header fields and alignment
  • Dry-run by default for safety
  • Policy-based control over when headers may be inserted, updated, or added to empty files
  • Layered configuration via:
    • pyproject.toml ([tool.topmark])
    • topmark.toml
    • CLI overrides and --config
  • Fine-grained include/exclude rules
  • Selective application via file patterns or stdin
  • Strict static typing (PEP 604 unions, Pyright)
  • Works well with pre-commit, CI, and Git hooks
  • Preserves newline style (LF/CRLF/CR) and BOM
  • Idempotent: re-running on already-compliant files makes no changes
  • Configurable comment alignment and raw/pretty formatting

🧱 Example headers

TopMark adapts headers to the comment syntax of each file type.

Bash / Shell

#!/bin/bash

# topmark:header:start
#
#   project   : TopMark
#   file      : script.sh
#   license   : MIT
#   copyright : (c) 2025 Olivier Biot
#
# topmark:header:end

echo "Hello, World!"

XML

<?xml version="1.0" encoding="UTF-8"?>
<!--
topmark:header:start

  project   : TopMark
  file      : config.xml
  license   : MIT
  copyright : (c) 2025 Olivier Biot

topmark:header:end
-->

<configuration>
    <!-- XML content here -->
</configuration>

JavaScript

// topmark:header:start
//
//   project   : TopMark
//   file      : app.js
//   license   : MIT
//   copyright : (c) 2025 Olivier Biot
//
// topmark:header:end

console.log("Hello, World!");

CSS

/*
 * topmark:header:start
 *
 *   project   : TopMark
 *   file      : styles.css
 *   license   : MIT
 *   copyright : (c) 2025 Olivier Biot
 *
 * topmark:header:end
 */

body { margin: 0; }

⚙️ Installation

From PyPI

pip install topmark

From source (development setup)

git clone https://github.com/shutterfreak/topmark.git
cd topmark
make venv
make venv-sync-dev

Run checks to confirm setup:

make verify
make test

Verify CLI

topmark version
topmark --help

🚀 Usage

topmark [COMMAND] [OPTIONS] [PATHS]...

Subcommands

Command Description
check Add or update TopMark headers
strip Remove TopMark headers
dump-config Show resolved configuration (merged TOML)
filetypes List supported file types
processors List header processors and mappings
show-defaults Show built-in defaults without merging
init-config Output a starter configuration
version Print version (PEP 440 or SemVer)

Examples

# Preview (dry-run)
topmark check src/

# Apply in place
topmark check --apply src/

# Remove headers (dry-run)
topmark strip src/

# Remove headers and apply changes
topmark strip --apply src/

# Show supported file types in Markdown format
topmark filetypes --output-format markdown --long

# List processors and associated file types
topmark processors --output-format markdown --long

TopMark preserves line endings, shebangs, BOMs, and indentation rules for each file type.


🧠 Configuration & Policy

TopMark supports layered configuration discovery and a flexible policy system controlling insert/update behavior.

Discovery order

  1. Built-in defaults (topmark-default.toml)
  2. User config (~/.config/topmark/topmark.toml or ~/.topmark.toml)
  3. Project config (nearest upward pyproject.toml or topmark.toml)
  4. Explicit --config files (merged in order)
  5. CLI flags and options (highest precedence)

Example topmark.toml

[fields]
project = "TopMark"
license = "MIT"
copyright = "(c) 2025 Olivier Biot"

[header]
fields = ["file", "file_relpath", "project", "license", "copyright"]

[tool.topmark.policy]
add_only = false
update_only = false
allow_header_in_empty_files = false

[tool.topmark.policy_by_type."python"]
allow_header_in_empty_files = true

[formatting]
align_fields = true
raw_header = false

[files]
file_types = ["python", "markdown", "env"]
exclude_from = [".gitignore"]
relative_to = "."

Policy semantics

Setting Meaning
add_only = true Only insert headers into files without one; skip updating existing ones
update_only = true Only update existing headers; skip inserting new ones
allow_header_in_empty_files Allow adding headers to empty files (useful for e.g. __init__.py)

Per-type overrides under [tool.topmark.policy_by_type."filetype"] can adjust specific behavior.

These policy options apply equally to the CLI and the public API.

See docs/configuration/discovery.md for more detail on config precedence and path semantics.


🪝 Pre-commit Integration

TopMark includes pre-commit hooks for automated header management.

Hook ID Purpose
topmark-check Validate headers (non-destructive)
topmark-apply Apply header updates (manual)

Install hooks:

pre-commit install
pre-commit run --all-files

Manual header fix (safe interactive mode):

pre-commit run topmark-apply --hook-stage manual --all-files

🔒 Public API

The public API now an optional policy argument (global or per-type) that integrates with the same resolution mechanism used by the CLI.

Example

from pathlib import Path
from topmark import api
from topmark.api.public_types import Policy

# Dry-run header checks
result = api.check(
    [Path("src")],
    apply=True,
    policy=Policy(add_only=True)
)

print(result.summary)
print(result.had_errors)

# Apply changes
applied = api.check([Path("src")], apply=True)

# Remove headers
api.strip([Path("src")], apply=True)

For programmatic discovery:

from topmark.registry import Registry

for ft, proc in Registry.bindings():
    print(ft.name, bool(proc))

📦 Packaging & Versioning

TopMark follows Semantic Versioning (SemVer).

Change Type Version Impact
fix: Patch
feat: Minor
feat!: / BREAKING CHANGE: Major

Build and check distributions:

python -m build
python -m twine check dist/*

Upload:

python -m twine upload dist/*

Tags are released via CI/CD.


🧪 Development

To test across all supported Python versions:

make test              # tox default envs
tox -m api-check       # API stability across all Python versions

For faster iteration:

make pytest            # run tests in current interpreter
make lint              # static linting
make verify            # formatting, linting, docs, links

📄 License

MIT License © 2025 Olivier Biot

See LICENSE


TopMark — consistent headers for consistent projects.

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

topmark-0.10.1.tar.gz (225.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

topmark-0.10.1-py3-none-any.whl (293.6 kB view details)

Uploaded Python 3

File details

Details for the file topmark-0.10.1.tar.gz.

File metadata

  • Download URL: topmark-0.10.1.tar.gz
  • Upload date:
  • Size: 225.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for topmark-0.10.1.tar.gz
Algorithm Hash digest
SHA256 68b5f075fea6e0387128e572c0116056fea115209970b101733080533dfb35ef
MD5 51aa502328c0064a4050422278fd8a5b
BLAKE2b-256 cf9a1a956a65d01832847f0b07794f29235685cb1ce55336d88f8f1b92575b8f

See more details on using hashes here.

Provenance

The following attestation bundles were made for topmark-0.10.1.tar.gz:

Publisher: release.yml on shutterfreak/topmark

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file topmark-0.10.1-py3-none-any.whl.

File metadata

  • Download URL: topmark-0.10.1-py3-none-any.whl
  • Upload date:
  • Size: 293.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for topmark-0.10.1-py3-none-any.whl
Algorithm Hash digest
SHA256 558f24e0322fb5521ce9e0d26e84b85fec28119ded15c0118103edb88573e40a
MD5 1e5d36804e69fe297b843b4ca1eda481
BLAKE2b-256 5e1c74e0ca86801129584b4d13a3300eee594356b3aa91fac281f8a966ab2eed

See more details on using hashes here.

Provenance

The following attestation bundles were made for topmark-0.10.1-py3-none-any.whl:

Publisher: release.yml on shutterfreak/topmark

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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