Configuration

Configuration via file

The [tox-toml-fmt] table is used when present in the tox.toml file:

[tox-toml-fmt]

# After how many columns split arrays/dicts into multiple lines and wrap long strings;
# use a trailing comma in arrays to force multiline format instead of lowering this value
column_width = 120

# Number of spaces for indentation
indent = 2

# Extra newlines between sub-tables in the same group (e.g. "\n" for one blank line between sub-tables)
sub_table_spacing = ""

# Extra newlines between root table groups (e.g. "\n" for one blank line, "\n\n" for two)
separate_root_table = "\n"

# Environments pinned to the start of env_list
pin_envs = ["fix", "type"]

If not set they will default to values from the CLI. The example above shows the defaults (except pin_envs which defaults to an empty list).

Shared configuration file

You can place formatting settings in a standalone tox-toml-fmt.toml file instead of (or in addition to) the [tox-toml-fmt] table. This is useful for monorepos or when you want to share the same configuration across multiple projects without duplicating it in each tox.toml.

The formatter searches for tox-toml-fmt.toml starting from the directory of the file being formatted and walking up to the filesystem root. The first match wins. You can also pass an explicit path via --config:

tox-toml-fmt --config /path/to/tox-toml-fmt.toml tox.toml

The shared config file uses the same keys as the [tox-toml-fmt] table, but without the table header:

column_width = 120
indent = 2
sub_table_spacing = ""
separate_root_table = "\n"
pin_envs = ["fix", "type"]

When both a shared config file and a [tox-toml-fmt] table exist, per-file settings from the [tox-toml-fmt] table take precedence over the shared config file.

Command line interface

tox-toml-fmt [-h] [-V] [-s | --check] [-n] [--config path] [--column-width count]
             [--indent count] [--table-format {short,long}]
             [--sub-table-spacing SUB_TABLE_SPACING]
             [--separate-root-table SEPARATE_ROOT_TABLE] [--expand-tables EXPAND_TABLES]
             [--collapse-tables COLLAPSE_TABLES] [--skip-wrap-for-keys SKIP_WRAP_FOR_KEYS]
             [--pin-env PIN_ENVS]
             inputs [inputs ...]

tox-toml-fmt positional arguments

  • inputs - pyproject.toml file(s) to format, use '-' to read from stdin

tox-toml-fmt options

  • -h, --help - show this help message and exit

  • -V, --version - print package version of pyproject_fmt

  • --config PATH - path to a shared tox-toml-fmt.toml config file

tox-toml-fmt run mode

  • -s, --stdout - print the formatted TOML to the stdout, implied if reading from stdin

  • --check - check and fail if any input would be formatted, printing any diffs

  • -n, --no-print-diff - Flag indicating to print diff for the check mode

tox-toml-fmt formatting behavior

  • --column-width COUNT - max column width in the TOML file (default: 120)

  • --indent COUNT - number of spaces to use for indentation (default: 2)

  • --table-format TABLE_FORMAT - table format: 'short' collapses sub-tables, 'long' expands to [table.subtable] (default: short)

  • --sub-table-spacing SUB_TABLE_SPACING - extra newlines between sub-tables in the same group (e.g. ' for compact, 'n’ for one blank line) (default: )

  • --separate-root-table SEPARATE_ROOT_TABLE - extra newlines between root table groups (e.g. '\n' for one blank line, '\n\n' for two) (default: )

  • --expand-tables EXPAND_TABLES - comma-separated list of tables to force expand (default: [])

  • --collapse-tables COLLAPSE_TABLES - comma-separated list of tables to force collapse (default: [])

  • --skip-wrap-for-keys SKIP_WRAP_FOR_KEYS - comma-separated list of key patterns to skip string wrapping (supports wildcards like '*.parse') (default: [])

  • --pin-env PIN_ENVS - environments pinned to the start of env_list (comma separated) (default: [])