rich-london-74860
11/17/2022, 9:44 PM./pants dependencies --filter-target-type=<target_type> <some_target>
applies the filter to some_target
, not the list of dependencies, which I find very unintuitive.
For example, in directory db/sample_project_1
I have a BUILD
that looks like this:
python_sources(
name="lib",
sources=["*.py"],
dependencies=["3rdparty:dbr-9.1-reqs", "db/shared:lib"],
resolve="databricks",
tags=["model"]
)
When I call ./pants dependencies db/sample_project_1/__init__.py:lib
I get the following:
3rdparty/requirements-dbr-9.1.txt:dbr-9.1-reqs
3rdparty:dbr-9.1-reqs#boto3
3rdparty:dbr-9.1-reqs#pandas
3rdparty:dbr-9.1-reqs#scikit-learn
3rdparty:dbr-9.1-reqs#scipy
db/shared/__init__.py:lib
db/shared/config.py:lib
db/shared/runner.py:lib
db/shared:reqs#request
db/notebook_utils/__init__.py:lib
which is what I expect.
If I do ./pants dependencies db/sample_project_1/__init__.py:lib --filter-target-type="python_source"
, then I get the exact same output.
If I do ./pants dependencies db/sample_project_1/__init__.py:lib --filter-target-type="python_requirement"
, then I get nothing.
It appears that this is because db/sample_project_1/__init__.py:lib
itself is a python_source
I can see how this behavior might be expected if the goal is to filter targets from a glob (e.g. only get dependencies for python_source
in ::
), but it seems rather unintuitive to me.
The question I want to answer here is: “which of this files dependencies are 3rd party requirements vs other sources” and it looks like the best way to do that is something like:
./pants list --filter-target-type=python_requirement $(./pants dependencies db/sample_project_1/__init__.py:lib | tr '\n' ' ')
On a related note, it would be really nice if it was possible to use --output-file
in append-mode.happy-kitchen-89482
11/17/2022, 10:33 PM--output-file
?happy-kitchen-89482
11/17/2022, 10:42 PM--filter
is a general-purpose option for filtering the inputs of a goal, not the outputs (after all, not all goals have outputs that are themselves targets, that is specific to certain introspection goals)happy-kitchen-89482
11/17/2022, 10:44 PMhappy-kitchen-89482
11/17/2022, 10:46 PMhappy-kitchen-89482
11/17/2022, 10:51 PM./pants dependencies db/sample_project_1/__init__.py:lib | xargs ./pants --filter-target-type=python_requirement list
rich-london-74860
11/17/2022, 10:54 PM./pants list --filter-target-type=python_requirement $(./pants dependencies db/sample_project_1/__init__.py:lib | tr '\n' ' ')
Is there a reason xargs is preferred?happy-kitchen-89482
11/17/2022, 11:22 PMhappy-kitchen-89482
11/17/2022, 11:22 PMhappy-kitchen-89482
11/17/2022, 11:22 PMxargs = xargs -n 1
or something like that?happy-kitchen-89482
11/17/2022, 11:23 PMxargs -n 5000
rich-london-74860
11/18/2022, 3:22 AMxargs -I {} ./pants -lerror list --filter-target-type=python_requirement {}
which would definitely do it