<@UQ1678BE1> how to get third party dependencies w...
# plugins
h
@jolly-midnight-72759 how to get third party dependencies working:
Use
await Get(Pex, PexFromTargetsRequest.for_requirements)
. See https://github.com/pantsbuild/pants/blob/c98ee3696818bc9945968ba94a14180d9466a6e7/src/python/pants/backend/python/goals/pytest_runner.py#L122-L126 as an example, although you’ll want to put all of the
specified_addresses
in
for_requirements()
method call, not just one like this example does. This will grab all relevant 3rd party reqs for that code and create a Pex with it for you. If you have a constraints file set up, this same
requirements.pex
will be reused across
test
,
run
,
repl
, etc. Then, you need to add the arguments
["--pex-path", requirements_pex.output_filename]
to the
PexRequest
to create your Jupyter Pex. https://github.com/pantsbuild/pants/blob/c98ee3696818bc9945968ba94a14180d9466a6e7/src/python/pants/backend/python/goals/pytest_runner.py#L148-L149. This tells Pex to ~merge the two PEX files at runtime. (In the example, we’re saying the more verbose
requirements_pex_request.input.output_filename
- this is because we haven’t yet called
await
with the
Get(Pex, PexFromTargetsRequest)
. The
requirements_pex_request
has the type
Get
, rather than the type
Pex
. So we need to unwrap that
Get
.)
j
I think I followed all of this.
I am getting
Copy code
Engine traceback:
  in select
  in jupyter.goal.jupyter
  in pants.backend.python.util_rules.pex.create_pex
  in pants.backend.python.util_rules.pex_from_targets.pex_from_targets
  in pants.engine.internals.graph.transitive_targets
  in pants.engine.internals.graph.resolve_targets
  in pants.engine.internals.graph.resolve_unexpanded_targets
Traceback (no traceback):
  <pants native internals>
Exception: WithDeps(Inner(InnerEntry { params: {Addresses}, rule: Task(Task { product: UnexpandedTargets, can_modify_workunit: false, clause: [Addresses], gets: [Get { output: WrappedTarget, input: Address }], func: pants.engine.internals.graph:177:resolve_unexpanded_targets(), cacheable: true, display_info: DisplayInfo { name: "pants.engine.internals.graph.resolve_unexpanded_targets", desc: None, level: Trace } }) })) did not declare a dependency on JustGet(Get { output: WrappedTarget, input: Addresses })
h
That’s a bad error message that the values for a
Get
are off. Are you using
Get(WrappedTarget, Address)
somewhere?
(If you’re able to post a Gist, that would help)
👍🏽 1
j
I don't see
WrappedTarget
anywhere in my code
Copy code
transitive_targets = await Get(
        TransitiveTargets, TransitiveTargetsRequest(all_specified_addresses)
    )
h
(btw, you can use f-strings. All Pants plugin code is Python 3.6+)
😅 1
j
is the only
await Get
before the `await MultiGet that builds the digests that will become the pex
h
Ah, I see it.
Copy code
PexFromTargetsRequest.for_requirements(
            [all_specified_addresses], internal_only=True
        )
Remove the
[]
.
all_specified_addresses
is already an iterable, and you’re accidentally wrapping it in a list again so it’s a nested list, which breaks things
🦅 1
j
But in the example,
request.field_set.address
is not a list. Got it
👍 1
Good eye!
h
Good eye!
The error message is horrible. We have an issue to fix it, which I think I may be able to knock out soon. But FYI I found this by looking at this part of the stacktrace:
Copy code
in pants.backend.python.util_rules.pex.create_pex
  in pants.backend.python.util_rules.pex_from_targets.pex_from_targets
  in pants.engine.internals.graph.transitive_targets
So I suspected something was off with the
PexFromTargets
part of the code, and voila
🎉 1
j
that did it!
🚀 1
now to make py2 or py3 magically happen
h
Which you’re already very close to doing 🙂 see the other thread
j
jump to other thread
😂 1