python_requirement
A Python requirement installable by pip.
This target is useful when you want to declare Python requirements inline in a BUILD file. If you have a requirements.txt
file already, you can instead use the macro python_requirements()
to convert each requirement into a python_requirement()
target automatically. For Poetry, use poetry_requirements()
.
See https://www.pantsbuild.org/v2.8/docs/python-third-party-dependencies.
Backend: ``
requirements
Iterable[str]
A pip-style requirement string, e.g. ["Django==3.2.8"]
.
You can specify multiple requirements for the same project in order to use environment markers, such as ["foo>=1.2,<1.3 ; python_version>'3.6'", "foo==0.9 ; python_version<'3'"]
.
If the requirement depends on some other requirement to work, such as needing setuptools
to be built, use the dependencies
field instead.
dependencies
Iterable[str] | None
None
Addresses to other targets that this target depends on, e.g. ['helloworld/subdir:lib'].
Alternatively, you may include file names. Pants will find which target owns that file, and create a new target from that which only includes the file in its sources
field. For files relative to the current BUILD file, prefix with ./
; otherwise, put the full path, e.g. ['./sibling.txt', 'resources/demo.json'].
You may exclude dependencies by prefixing with !
, e.g. ['!helloworld/subdir:lib', '!./sibling.txt']
. Ignores are intended for false positives with dependency inference; otherwise, simply leave off the dependency from the BUILD file.
description
str | None
None
A human-readable description of the target.
Use ./pants list --documented ::
to see all targets with descriptions.
modules
Iterable[str] | None
None
The modules this requirement provides (used for dependency inference).
For example, the requirement setuptools
provides ["setuptools", "pkg_resources", "easy_install"]
.
Usually you can leave this field off. If unspecified, Pants will first look at the default module mapping (https://github.com/pantsbuild/pants/blob/release_2.8.1/src/python/pants/backend/python/dependency_inference/default_module_mapping.py), and then will default to the normalized project name. For example, the requirement Django
would default to the module django
.
Mutually exclusive with the type_stub_modules
field.
tags
Iterable[str] | None
None
Arbitrary strings to describe a target.
For example, you may tag some test targets with 'integration_test' so that you could run ./pants --tag='integration_test' test ::
to only run on targets with that tag.
type_stub_modules
Iterable[str] | None
None
The modules this requirement provides if the requirement is a type stub (used for dependency inference).
For example, the requirement types-requests
provides ["requests"]
.
Usually you can leave this field off. If unspecified, Pants will first look at the default module mapping (https://github.com/pantsbuild/pants/blob/release_2.8.1/src/python/pants/backend/python/dependency_inference/default_module_mapping.py). If not found and the requirement name starts with types-
or stubs-
, or ends with -types
or -stubs
, will default to that requirement name without the prefix/suffix. For example, types-requests
would default to requests
. Otherwise, will be treated like a normal requirement (see the modules
field).
Mutually exclusive with the modules
field.