Skip to main content
Version: 2.10 (deprecated)

fmt


pants fmt [args]

Autoformat source code.

Backend: pants.core

Config section: [fmt]

Basic options

only

--fmt-only="['<str>', '<str>', ...]"
PANTS_FMT_ONLY
pants.toml
[fmt]
only = [
'<str>',
'<str>',
...,
]
default: []

Only run these formatters and skip all others.

The formatter names are outputted at the final summary of running this goal, e.g. isort and shfmt. You can also run fmt --only=fake to get a list of all activated formatters.

You can repeat this option, e.g. fmt --only=isort --only=shfmt or fmt --only=['isort', 'shfmt'].

Advanced options

batch_size

--fmt-batch-size=<int>
PANTS_FMT_BATCH_SIZE
pants.toml
[fmt]
batch_size = <int>
default: 128

The target number of files to be included in each formatter batch.

Formatter processes are batched for a few reasons:

  1. to avoid OS argument length limits (in processes which don't support argument files)
  2. to support more stable cache keys than would be possible if all files were operated on in a single batch.
  3. to allow for parallelism in formatter processes which don't have internal parallelism, or -- if they do support internal parallelism -- to improve scheduling behavior when multiple processes are competing for cores and so internal parallelism cannot be used perfectly.

In order to improve cache hit rates (see 2.), batches are created at stable boundaries, and so this value is only a "target" batch size (rather than an exact value).

Deprecated options

per_file_caching

--[no-]fmt-per-file-caching
PANTS_FMT_PER_FILE_CACHING
pants.toml
[fmt]
per_file_caching = <bool>
default: False
Deprecated, will be removed in version: 2.11.0.dev0.
Formatters are now broken into multiple batches by default using the `--batch-size` argument.<br /><br />To keep (roughly) this option's behavior, set [fmt].batch_size = 1. However, you'll likely get better performance by using a larger batch size because of reduced overhead launching processes.

Rather than formatting all files in a single batch, format each file as a separate process.

Why do this? You'll get many more cache hits. Why not do this? Formatters both have substantial startup overhead and are cheap to add one additional file to the run. On a cold cache, it is much faster to use --no-per-file-caching.

We only recommend using --per-file-caching if you are using a remote cache or if you have benchmarked that this option will be faster than --no-per-file-caching for your use case.

None