Skip to main content
Version: 2.8 (deprecated)

python


Options for Pants's Python support.

Backend: ``

Config section: [python]

Basic options

macos_big_sur_compatibility

--[no-]python-macos-big-sur-compatibility
PANTS_PYTHON_MACOS_BIG_SUR_COMPATIBILITY
pants.toml
[python]
macos_big_sur_compatibility = <bool>
default: False

If set, and if running on MacOS Big Sur, use macosx_10_16 as the platform when building wheels. Otherwise, the default of macosx_11_0 will be used. This may be required for pip to be able to install the resulting distribution on Big Sur.

Advanced options

experimental_lockfile

--python-experimental-lockfile=<file>
PANTS_PYTHON_EXPERIMENTAL_LOCKFILE
pants.toml
[python]
experimental_lockfile = <file>
default: None

The lockfile to use when resolving requirements for your own code (vs. tools you run).

This is highly experimental and will change, including adding support for multiple lockfiles. This option's behavior may change without the normal deprecation cycle.

To generate a lockfile, activate the backend pants.backend.experimental.pythonand run ./pants generate-user-lockfile ::.

Mutually exclusive with [python].requirement_constraints.

experimental_resolves_to_lockfiles

--python-experimental-resolves-to-lockfiles="{'key1': val1, 'key2': val2, ...}"
PANTS_PYTHON_EXPERIMENTAL_RESOLVES_TO_LOCKFILES
pants.toml
[python.experimental_resolves_to_lockfiles]
key1 = val1
key2 = val2
...
default: {}

A mapping of logical names to lockfile paths used in your project, e.g. { default = '3rdparty/default_lockfile.txt', py2 = '3rdparty/py2.txt' }.

To generate a lockfile, run ./pants generate-lockfiles --resolve=<name> or ./pants generate-lockfiles to generate for all resolves (including tool lockfiles).

This is highly experimental and will likely change.

interpreter_constraints

--python-interpreter-constraints="[<requirement>, <requirement>, ...]"
PANTS_PYTHON_INTERPRETER_CONSTRAINTS
pants.toml
[python]
interpreter_constraints = [
<requirement>,
<requirement>,
...,
]
default:
[
  "CPython>=3.6,<4"
]

The Python interpreters your codebase is compatible with.

Specify with requirement syntax, e.g. 'CPython>=2.7,<3' (A CPython interpreter with version >=2.7 AND version <3) or 'PyPy' (A pypy interpreter of any version). Multiple constraint strings will be ORed together.

These constraints are used as the default value for the interpreter_constraints field of Python targets.

interpreter_search_paths

--python-interpreter-search-paths="[<binary-paths>, <binary-paths>, ...]"
PANTS_PYTHON_INTERPRETER_SEARCH_PATHS
pants.toml
[python]
interpreter_search_paths = [
<binary-paths>,
<binary-paths>,
...,
]
default:
[
  "<PYENV>",
  "<PATH>"
]

A list of paths to search for Python interpreters that match your project's interpreter constraints.

You can specify absolute paths to interpreter binaries and/or to directories containing interpreter binaries. The order of entries does not matter.

The following special strings are supported:

  • <PATH>, the contents of the PATH env var
  • <ASDF>, all Python versions currently configured by ASDF (asdf shell, ${HOME}/.tool-versions), with a fallback to all installed versions
  • <ASDF_LOCAL>, the ASDF interpreter with the version in BUILD_ROOT/.tool-versions
  • <PYENV>, all Python versions under $(pyenv root)/versions
  • <PYENV_LOCAL>, the Pyenv interpreter with the version in BUILD_ROOT/.python-version
  • <PEXRC>, paths in the PEX_PYTHON_PATH variable in /etc/pexrc or ~/.pexrc

interpreter_versions_universe

--python-interpreter-versions-universe="['<str>', '<str>', ...]"
PANTS_PYTHON_INTERPRETER_VERSIONS_UNIVERSE
pants.toml
[python]
interpreter_versions_universe = [
'<str>',
'<str>',
...,
]
default:
[
  "2.7",
  "3.5",
  "3.6",
  "3.7",
  "3.8",
  "3.9",
  "3.10"
]

All known Python major/minor interpreter versions that may be used by either your code or tools used by your code.

This is used by Pants to robustly handle interpreter constraints, such as knowing when generating lockfiles which Python versions to check if your code is using.

This does not control which interpreter your code will use. Instead, to set your interpreter constraints, update [python].interpreter_constraints, the interpreter_constraints field, and relevant tool options like [isort].interpreter_constraints to tell Pants which interpreters your code actually uses. See https://www.pantsbuild.org/v2.8/docs/python-interpreter-compatibility.

All elements must be the minor and major Python version, e.g. '2.7' or '3.10'. Do not include the patch version.

invalid_lockfile_behavior

--python-invalid-lockfile-behavior=<InvalidLockfileBehavior>
PANTS_PYTHON_INVALID_LOCKFILE_BEHAVIOR
pants.toml
[python]
invalid_lockfile_behavior = <InvalidLockfileBehavior>
one of: error, ignore, warn
default: error

The behavior when a lockfile has requirements or interpreter constraints that are not compatible with what the current build is using.

We recommend keeping the default of error for CI builds.

requirement_constraints

--python-requirement-constraints=<file_option>
PANTS_PYTHON_REQUIREMENT_CONSTRAINTS
pants.toml
[python]
requirement_constraints = <file_option>
default: None

When resolving third-party requirements for your own code (vs. tools you run), use this constraints file to determine which versions to use.

This only applies when resolving user requirements, rather than tools you run like Black and Pytest. To constrain tools, set [tool].lockfile, e.g. [black].lockfile.

See https://pip.pypa.io/en/stable/user_guide/#constraints-files for more information on the format of constraint files and how constraints are applied in Pex and pip.

Mutually exclusive with [python].experimental_lockfile.

resolve_all_constraints

--[no-]python-resolve-all-constraints
PANTS_PYTHON_RESOLVE_ALL_CONSTRAINTS
pants.toml
[python]
resolve_all_constraints = <bool>
default: True

If enabled, when resolving requirements, Pants will first resolve your entire constraints file as a single global resolve. Then, if the code uses a subset of your constraints file, Pants will extract the relevant requirements from that global resolve so that only what's actually needed gets used. If disabled, Pants will not use a global resolve and will resolve each subset of your requirements independently.

Usually this option should be enabled because it can result in far fewer resolves.

Requires [python].requirement_constraints to be set.

resolver_jobs

--python-resolver-jobs=<int>
PANTS_PYTHON_RESOLVER_JOBS
pants.toml
[python]
resolver_jobs = <int>
default: #cores/2

The maximum number of concurrent jobs to build wheels with.

Because Pants can run multiple subprocesses in parallel, the maximum total parallelism will be --process-execution-{local,remote}-parallelism x --python-resolver-jobs.

Setting this option higher may result in better parallelism, but, if set too high, may result in starvation and Out of Memory errors.

resolver_manylinux

--python-resolver-manylinux=<str>
PANTS_PYTHON_RESOLVER_MANYLINUX
pants.toml
[python]
resolver_manylinux = <str>
default: manylinux2014

Whether to allow resolution of manylinux wheels when resolving requirements for foreign linux platforms. The value should be a manylinux platform upper bound, e.g.: 'manylinux2010', or else the string 'no' to disallow.

tailor_ignore_solitary_init_files

--[no-]python-tailor-ignore-solitary-init-files
PANTS_PYTHON_TAILOR_IGNORE_SOLITARY_INIT_FILES
pants.toml
[python]
tailor_ignore_solitary_init_files = <bool>
default: True

Don't tailor python_sources targets for solitary __init__.py files, as those usually exist as import scaffolding rather than true library code.

Set to False if you commonly have packages containing real code in __init__.py and there are no other .py files in the package.

tailor_pex_binary_targets

--[no-]python-tailor-pex-binary-targets
PANTS_PYTHON_TAILOR_PEX_BINARY_TARGETS
pants.toml
[python]
tailor_pex_binary_targets = <bool>
default: True

Tailor pex_binary() targets for Python entry point files.

tailor_requirements_targets

--[no-]python-tailor-requirements-targets
PANTS_PYTHON_TAILOR_REQUIREMENTS_TARGETS
pants.toml
[python]
tailor_requirements_targets = <bool>
default: True

Tailor python_requirements() targets for requirements files.

Deprecated options

None

None