How do I use 3rd party dependencies in a plugin? ...
# plugins
r
How do I use 3rd party dependencies in a plugin? I have a
BUILD
file setup for my plugin, with it’s own
resolve
and
pants_requirement
(following the documentation here), but whenever I try to run my plugin (or anything), I get a
ModuleNotFound
error. This does not seem to be a problem when running unit tests for that same plugin, which imports the 3rd party dependency.
c
when you install your plugin with adding it to
pants.toml
in the
[GLOBAL].plugins
those 3rd party deps will be pulled in as usual, but when you run your plugin as a in-repo plugin you need to provide those deps manually as the plugin is not packaged and installed, so list those requirements in the
[GLOBAL].plugins
option should make them available to your plugin.
r
Right, I found this, but this makes me very confused about the purpose of the plugins resolve. Is that only used for tests?
c
that, and in case you have a
python_distribution
target to publish it that would be used to instruct pants what 3rdparty deps you have for it
and possibly others I’m overlooking/not aware of
r
Even if I have my 3rd-party dependencies in
[GLOBAL].plugins
do I need to include them as
python_requirements
dependencies for unit tests?
c
yes, that installed by
[GLOBAL].plugins
will not be available in tests
consider that you see two sides of your plugin at once. Both developing the plugin and consuming/using the plugin. And those two have different requirements/setups.
r
If one of the 3rd-party dependencies installed via
[GLOBAL].plugins
includes an
entry_point
, is it possible to then invoke that
entry_point
via pants?
c
no those are not exposed. it’s easy enough to add a
pex_binary
for that purpose.
more context on that here https://github.com/pantsbuild/pants/pull/13257 (as I had the very same idea once)
r
No, you’re definitely right that a
pex_binary
accomplishes what we need, thanks!
consider that you see two sides of your plugin at once. Both developing the plugin and consuming/using the plugin. And those two have different requirements/setups.
I understand the reason… but it is still annoying 😒
1
One follow-up question on this, there is a lockfile for 3rd-party dependencies used to develop the plugin, how does the
pants
know which version of the 3rd-party dependency to use for the one specified in
[GLOBAL].plugins
? I’m asking because I’ve been seeing a problem where pants gets stuck resolving plugins (the dependencies in
[GLOBAL].plugins
). If
pants
bootstraps from a virtual environment, are those dependencies installed into the virtual environment?