How can I query 3rd party deps of a target? I tri...
# general
r
How can I query 3rd party deps of a target? I tried
pants dependencies --transitive
but it contains non 1st party deps as well.
1
e
pants dependencies --transitive --filter-target-type="python_requirement"
I think that should do it for you. filtering to only find 3rd party deps
h
Note that you can only get the direct 3rdparty deps this way (the ones any part of your code directly imports). The indirect deps are in the lockfile, but not explicitly modeled in the Pants dependency graph.
r
Thanks 🙏
Actually, the command always returns an empty result. I tried with
python_requirement
and
poetry_requirements
. Full command:
Copy code
pants dependencies --transitive --filter-target-type="poetry_requirements" agents:
Running on the full repo
::
returns the deps but not when I target specific targets.
e
Not sure if this is the issue, but
poetry_requirements
is not actually a target type. Its just a macro that creates
python_requirement
targets behind the scenes. Try targetting
python_requirement
r
Unfortunately it doesn't work 🥲
h
What happens if you remove the
--filter-target-type
but run on a specific target?
r
I get the following:
Copy code
//:poetry0#langchain-core
//:poetry0#langchain-openai
//:poetry0#langgraph
//:poetry0#protobuf
//pyproject.toml:poetry0
agents/__init__.py:lib
agents/agent.py:lib
agents/main.py:lib
agents/pb_test.py:tests
agents/router.py:lib
agents/simple.py:lib
lockfiles/python-default.lock:_python-default_lockfile
protobuf/v1/person.proto
utils/tools.py
h
OK, so the basic mechanism works, just the filtering doesn’t
So you’re filtering on the wrong kind of target (I assume
//:poetry0#langchain-core
and so on are what you want to see)
r
Yes exactly
Do you know what I should be filtering on?
h
Well, what are the types of those targets?
Try
pants peek
to find out
r
Thanks, I didn't know about the command.
pants peek //:poetry0#langchain-openai
returns:
Copy code
{
    "address": "//:poetry0#langchain-openai",
    "target_type": "python_requirement",
    "_find_links": [],
    "dependencies": [
      "//pyproject.toml:poetry0",
      "lockfiles/python-default.lock:_python-default_lockfile"
    ],
    "dependencies_raw": [
      "//pyproject.toml:poetry0",
      "lockfiles/python-default.lock:_python-default_lockfile"
    ],
    "description": null,
    "entry_point": null,
    "goals": [
      "run"
    ],
    "modules": null,
    "requirements": [
      "langchain-openai<0.3.0,>=0.2.6"
    ],
    "resolve": null,
    "tags": null,
    "type_stub_modules": null
  }
]
It seems like it's a
python_requirement
However,
pants dependencies --transitive --filter-target-type="python_requirement" agents:
returns nothing
h
Oh! Right, I keep slipping up on this
--filter-*
flags filter the input targets
this is confusing in the specific case of
dependencies
It does not affect the output targets
Sorry for the confusion - even I got confused!
To filter outputs you can do something like:
Copy code
$ pants dependencies --transitive agents: | xargs pants --no-pantsd list  --filter-target-type="python_requirement"
The
--no-pantsd
is important because you can’t have two concurrent daemonized pants runs
Alternatively you can redirect the output of the first run to a file and then cat that file into the second run (then you won’t need
--no-pantsd
)
r
Works thanks a lot 🙏