-
Notifications
You must be signed in to change notification settings - Fork 111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
formalize extending common_cfg.definitions (and other things) in extensions? #6314
Comments
Duplicate of #5769 |
Importanting the content from #5769, which is partly overlapping with the OP: Two modes of operations come to my mind: Do nothing and don't fight extensionsOnce imported, extensions could "monkey-patch" this dictionary and announce additional config. This would have minimal impact on performance, as it is only happening when it become relevant. There are two major downsides: 1) the model would be to invite 3rd-party code mess with the internal of datalad-core (fragile), and 2) generic tools like x_configuration will have a hard time to pick these up (not impossible, though). Introduce update functionality that queries extensions (via entrypoint)This will be slower, but could be implemented in a lazy-loading fashion (likely the simple dict needs to become a class). The big advantage is to have a formal interface for extensions to work with. |
Well, in the original description of this PR I proposed a third (then I guess) way: Define DataLad core API for extensions to use to update internal DataLad "registries"which is different from both modes listed in the prior comment. Unlike the 2nd (entry points) it would provide an interface in the core (not in extensions) which would allow for easier deprecation cycles if we would need to change anything (if it would be via entry point -- "core" would need to support multiple "flavors" during deprecation and figure out which flavor of the interface extension uses). I do not think there would be any speed penalty in comparison to "monkey-patch"ing. |
I think a straightforward way to resolve this issue would be to turn I screened the code and this class would need to support to following API subset of
We would be able to add additional methods in the spirit of the proposed |
An aspect that still needs a resolution is how and when to trigger extensions to actually deposit their config definitions. In #6584 I tried to explore how fast this could be made, but it remains to be decided how such a mechanism needs to be used. My conclusion is that unless we trigger the respective extension code centrally, the ability of extensions to configure anything will remain severely limited -- to influence core package behavior only within running extension code. However, this is already possible right now, and requires no changes. So depending on the outcome of this decision, we can either close this or add a central entrypoint loop somewhere. |
Indeed a dedicated class/interface for
Given that we have not had yet a use case where we needed a "less limited" influence from extensions, I think that
ATM we use
What I was thinking is to have a singular entry point for each extension which would then do all desired registrations of extra features of the extension, smth like def myextension_entry_point(extensions):
extensions.add_config(name, ui, *, destination='global', default=None, type=None) # come up with your example ;)
with extensions.add_interfaces_group("Containerized environments") as g:
# optional kwargs can all be deduced from the name of the module or explicitly
# provided
g.add_interface('datalad_container.containers_list'[, cls=None, pyinterface=None, cliinterface=None])
g.add_interface('datalad_container.containers_remove')
...
extensions.add_downloader(...)
extensions.add_procedures([path='resources/procedures']) # use the same magic on traversal but now explicitly requested and "datalad core" would in a single helper iterate over all such registered pros:
cons I see in such approach
|
The use cases are plenty. My mental model for thinking about this is |
Great use case -- |
This also replaces the previously very flexible data structure for such items with a more rigid set of classes that implement lazy evaluation of defaults (avoiding their possibly expensive computation, even when they are not actually needed). They otherwise implement all elements of the previously used API, such that they work as a drop-in replacement. Only register_config() is intended to be used publicly. Fixed datalad#6314
This also replaces the previously very flexible data structure for such items with a more rigid set of classes that implement lazy evaluation of defaults (avoiding their possibly expensive computation, even when they are not actually needed). They otherwise implement all elements of the previously used API, such that they work as a drop-in replacement. Only register_config() is intended to be used publicly. Fixed datalad#6314
Looking at http://docs.datalad.org/en/latest/customization.html (filed separate #6313), and then skimming through extension template and extensions, it seems we have not formalized how extensions could (or should at all) expand the common_cfg.definitions (https://github.com/datalad/datalad/blob/master/datalad/interface/common_cfg.py#L46). ATM it seems just be a matter of "documenting" those added/used config variables somewhere in docstrings, but IMHO they should be added to aforementioned
definitions
. It would be particularly useful in the scope of theconfiguration
command (#6306).I guess we could just tell people to add entries to that (
common_cfg.definitions
) dictionary. But I start feeling that we need something likedatalad.support.extensions
module which would provide formalized and centralized interfaces for extensions to extend datalad. E.g. in the case of extending configuration, could beif we decide to just mimic internal structure present ATM (may be name it
add_common_cfg
to bring closer to current setup). If we later decide to formalize/change internal config structure or interface to add config variables, we would be able to provide deprecation cycle, while adjusting initial (above) version to map into a new internal data structure, etc. So, benefits are multiple.In the scope of #5963 we could also
add_downloader
.The text was updated successfully, but these errors were encountered: