"Local" plugins
See original GitHub issueI would like to be able to “locally” register a plugin, within a bounded context. An example would be a library where I know, locally that I would be dealing with “.dat” / “.raw” files which actually have a certain binary format, so I want to register a plugin for these, but I don’t want this plugin to affect the entire Python process (because “.dat”/“.raw” could be anything, and I don’t want to make promises for other modules in the same process that could also be using imageio). IOW, I’d like something like (API names up to bikeshedding)
def my_libs_public_api(path: Path, ...):
# path can be a .dat/.raw, or perhaps any other format supported by imageio
imopen_with_extra_plugins = imopen.with_plugins(extra_plugins) # perhaps instantiated at module level
with imopen_with_extra_plugins(path, "r") as file: return file.read()
I think this is “mostly” just a matter of having an extra class attribute _instance_plugins
, which is checked before _known_plugins
, have with_plugins
return a new imopen instance with extra entries in _instance_plugins
, and check _instance_plugins
before _known_plugins
in imopen.__call__
.
Thoughts?
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (6 by maintainers)
Top GitHub Comments
Awesome.
@almarklein Any objections to extending support of
plugin
inimopen(..., plugin=...)
to allow plugin classes as input?@anntzer Would you be interested in contributing this feature?
Not now, but I’ll keep this somewhere in the back of my mind.