I've got a pretty... niche issue. We use plugins q...
# general
g
I've got a pretty... niche issue. We use plugins quite a bit for a project I'm involved in, with
entry_points
. Textbook setup where we use
importlib.metadata
to find our group and then load them dynamically. I'm porting the plugin host + some tooling to Pants, but it seems like the entry_points are never available. Which makes sense, I assume that Pants doesn't build and install the wheels for tests. Is there some magic incantation I can use to make entry_points work for tests, or do I need to mock it?
1
h
To clarify, these are system Foo’s plugins we’re talking about, not Pants’s plugins? And I guess you are using custom entry points?
Do these plugins have an
entry_points.txt
in their code already?
g
Yepp and yepp! I'll look at that discussion, it does sound relevant.
h
So possibly all you need is a
resources()
target!
g
Yeah. I guess I then also need something like
python_tests(dependencies=["//src/py:mock-dist-info"])
in every place that this needs to work.
That works awesome. Also had to actually depend on the plugin file, since it's not referenced anywhere.
h
Yeah, you could maybe write custom dep inference for that, or just wrap it in a macro
g
Yeah; no worries. Now do to the same for
importlib.resources
... I assume a similar mechanic should exist there.
In case anyone else finds this: yep, minus the .dist-info/entry_points.txt file: just define a
resources
target and depend on it.