python
Options for Pants's Python backend.
Backend: pants.core
Config section: [python]
Basic options
default_run_goal_use_sandbox
--[no-]python-default-run-goal-use-sandbox
PANTS_PYTHON_DEFAULT_RUN_GOAL_USE_SANDBOX
[python]
default_run_goal_use_sandbox = <bool>
True
The default value used for the run_goal_use_sandbox
field of Python targets. See the relevant field for more details.
Advanced options
default_resolve
--python-default-resolve=<str>
PANTS_PYTHON_DEFAULT_RESOLVE
[python]
default_resolve = <str>
python-default
The default value used for the resolve
field.
The name must be defined as a resolve in [python].resolves
.
enable_lockfile_targets
--[no-]python-enable-lockfile-targets
PANTS_PYTHON_ENABLE_LOCKFILE_TARGETS
[python]
enable_lockfile_targets = <bool>
True
Create targets for all Python lockfiles defined in [python].resolves
.
The lockfile targets will then be used as dependencies to the python_requirement
targets that use them, invalidating source targets per resolve when the lockfile changes.
If another targets address is in conflict with the created lockfile target, it will shadow the lockfile target and it will not be available as a dependency for any python_requirement
targets.
enable_resolves
--[no-]python-enable-resolves
PANTS_PYTHON_ENABLE_RESOLVES
[python]
enable_resolves = <bool>
False
Set to true to enable lockfiles for user code. See [python].resolves
for an explanation of this feature.
This option is mutually exclusive with [python].requirement_constraints
. We strongly recommend using this option because it:
- Uses
--hash
to validate that all downloaded files are expected, which reduces the risk of supply chain attacks. - Enforces that all transitive dependencies are in the lockfile, whereas constraints allow you to leave off dependencies. This ensures your build is more stable and reduces the risk of supply chain attacks.
- Allows you to have multiple lockfiles in your repository.
interpreter_constraints
--python-interpreter-constraints="[<requirement>, <requirement>, ...]"
PANTS_PYTHON_INTERPRETER_CONSTRAINTS
[python]
interpreter_constraints = [
<requirement>,
<requirement>,
...,
]
[ "CPython>=3.7,<4" ]
The Python interpreters your codebase is compatible with.
These constraints are used as the default value for the interpreter_constraints
field of Python targets.
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.
interpreter_versions_universe
--python-interpreter-versions-universe="['<str>', '<str>', ...]"
PANTS_PYTHON_INTERPRETER_VERSIONS_UNIVERSE
[python]
interpreter_versions_universe = [
'<str>',
'<str>',
...,
]
[ "2.7", "3.5", "3.6", "3.7", "3.8", "3.9", "3.10", "3.11" ]
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.15/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
[python]
invalid_lockfile_behavior = <InvalidLockfileBehavior>
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.
Note that warn
will still expect a Pants lockfile header, it only won't error if the lockfile is stale and should be regenerated.
Use ignore
to avoid needing a lockfile header at all, e.g. if you are manually managing lockfiles rather than using the generate-lockfiles
goal.
macos_big_sur_compatibility
--[no-]python-macos-big-sur-compatibility
PANTS_PYTHON_MACOS_BIG_SUR_COMPATIBILITY
[python]
macos_big_sur_compatibility = <bool>
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.