rapid-apartment-37923
12/06/2021, 10:44 AMsrc/
plugins/foo/schema.py
plugins/bar/schema.py
plugin_registry.py
webserver.py
test/
plugins/foo/test_foo.py
plugins/bar/test_bar.py
The challenge is that plugin_registry.py
is loading those plugins dynamically using importlib
. Any usage of a plugin goes through the registry as a facade. In practice this means that there is no import of foo/schema.py
in test_foo.py
but we only import the registry and have it load the right plugin for us.
In some integration tests it gets even more complicated. The registry and plugins are loaded in another process and the tests only call a REST API, without any import of registry or plugins in the test code.
This usage does not play well with the pants auto-discovery of Python import dependencies. We can think of two ways out of this, but both have their downside (see thread).
Is there any option we have missed? I am curious if you have further ideas for usrapid-apartment-37923
12/06/2021, 10:45 AMpython_sources(
sources=["!plugin_registry.py", "*.py"]
)
target(
name="resource-plugins",
description="List of all resources dynamically loaded by the registry",
dependencies=[
"src/plugins/foo",
"src/plugins/bar",
],
)
python_sources(
name="registry",
sources=["plugin_registry.py"],
dependencies=[":resource-plugins"]
)
• Advantage: This works from a Pants perspective as dependencies are correctly detected and is rather easy to maintain.
• Disadvantage: Dependencies are very coarse grained leading to many unnecessary invalidations. For example, if I change bar
also all tests for foo
will be executed even though this is unnecessaryrapid-apartment-37923
12/06/2021, 10:45 AMtest_foo.py
we would need to add dependencies=["src/plugins/foo"]
in the associated BUILD file.
The same dependency would also need to be added for the multiple binaries we ship. So far these places have just pulled in the registry.
• Advantage: Dependencies are more fine grained which should help fine grained invalidation and thus test performance
• Disadvantage: I expect push backs from the other developers here. Instead of just dropping a new plugin into a folder, we suddenly have to adjust multiple places to correctly declare a dependency on any new plugin it. Any mistake we make here might mean we forget to run tests even though relevant plugins have changed.rapid-apartment-37923
12/06/2021, 10:46 AMhappy-kitchen-89482
12/06/2021, 4:41 PMtest_foo.py
tell the registry "I need foo
but not `bar`" ?happy-kitchen-89482
12/06/2021, 4:42 PMrapid-apartment-37923
12/08/2021, 1:28 PMhappy-kitchen-89482
12/08/2021, 9:03 PMhappy-kitchen-89482
12/08/2021, 9:03 PM