is there an easy way to search for targets whose a...
# plugins
f
is there an easy way to search for targets whose addresses match a certain patter in the rule api?
h
To handle —exclude-target-rexegp, we use AddressSpecsFilter. Bottom of https://github.com/pantsbuild/pants/blob/master/src/python/pants/engine/internals/mapper.py I don’t think you’ll want to use that actual type in a rule signature, but for possible inspiration. Likewise, see lines 100-102 of https://github.com/pantsbuild/pants/blob/master/src/python/pants/backend/project_info/filter_targets.py for how we handle the address regex option for filter — I imagine you may want to find consider all targets, rather than what was specified by the user? See lines 81-84 for how to do the equivalent of
./pants list ::
https://github.com/pantsbuild/pants/blob/master/src/python/pants/backend/python/mixed_interpreter_constraints/py_constraints.py It’s confusing that there are two types of targets at play, and you decide which you care about. The naming in that code is stale.. ”explicit targets”, aka BUILD targets, are what you specify exactly in your BUILD file, eg the entire
sources
field is used. This is all there was in Pants 1.x “Expanded targets”, aka “file targets”, aka “generated subtargets”, are based on the original BUILD target. They have all the same metadata, except only one file in the
sources
field. This is what we mean by “files are the atomic unit”; you can use a more precise subset of the original BUILD file target
🙏🏻 1
f
i'm actually try to find a way to manage 3rdparty python dependencies more gracefully since i'm moving them to separate BUILD files, and i might even try integrating this with the underlying virtualenv i use for getting my IDE to understand what's going on
h
Cool, so then you can use either the BUILD targets or file targets snippet. If a target type doesn’t have
sources
, then we always use the original BUILD target, as it’s impossible to make it more precise It might also be helpful to filter by target type. The simplest way is to do
isinstance(tgt, PythonRequirementLibrary)
. I don’t think the more portable way of using
if tgt.has_field(PythonRequirementsField)
is relevant, unless you plan to to subclass the target type