Skip to main content
Version: 2.23 (prerelease)

preamble


Formats files with a preamble, with the preamble looked up based on path.

This is useful for things such as copyright headers or shebang lines.

Pants substitutes the following identifiers (following Python's string.Template substitutions): - $year: The current year (only used when actually writing the year to the file).

Backend: pants.backend.tools.preamble

Config section: [preamble]

Basic options

skip

--[no-]preamble-skip
PANTS_PREAMBLE_SKIP
pants.toml
[preamble]
skip = <bool>
default: False

If true, don't use preamble when running pants fmt.

template_by_globs

--preamble-template-by-globs="{'key1': val1, 'key2': val2, ...}"
PANTS_PREAMBLE_TEMPLATE_BY_GLOBS
pants.toml
[preamble.template_by_globs]
key1 = val1
key2 = val2
...
default: {}

Which preamble template to use based on the path globs (relative to the build root).

Example:

{
'*.rs': '// Copyright (c) $year\n// Line 2\n'
'*.py:!__init__.py': '# Copyright (c) $year\n# Line 2\n',
}

It might be helpful to load this config from a JSON or YAML file. To do that, set [preamble].config = '@path/to/config.yaml', for example.

Advanced options

None

Deprecated options

None

None