Repository navigation
FEAT: choose plugin based on extension and lazy-import plugins - #680
Conversation
Automatically generated by python-semantic-release
Also: removed ability to register plugins. Instead, directly register them in imageio.config.
This reverts commit a6b5720.
|
I noticed a "regression" introduced in this PR: If the user selected a specific format using the old As a result, @almarklein This would need to be fixed by having ffmpeg check the header of the file (or what ever the equivalent thing is for that backend). Any thoughts on how to best go about this? |
Nope. I bet that there would be an awful lot of headers that ffmpeg could parse, but I don't think we can give ffmpeg a few bytes and ask it to let us know if it looks familiar :) I guess this is the way it is? |
Theoretically, there is ffprobe that might give us that information in a relatively efficient way. I don't know how easy/hard it would be to feed in a file object though (I also don't really know how we do that in ffmpeg itself :D). |
|
Status update: Currently the tests are breaking (again), because we give DICOM special treatment and allow it to read folders. I ran into this situation multiple times while writing this PR, and I remember dealing with this in previous PRs. @almarklein Can we formalize folder support for Currently, At the same time, we have supported folder access for DICOM for several years now, and simply dropping it seems like a bad idea. |
|
Interesting. This is indeed an edge case. In the old version, we seemed to have worked around it. Do you know why we do run into it now? Maybe that gives a hint on how to best solve this.
That may seem the most clean solution, but I don't oversee how this will affect the rest of the code. If we can make this work without needing changes in all other plugins then maybe this is a way forward. Alternatively, we may need to force reading a dicomdir by providing the path to an arbitrary file in that directory. This is also not pretty though... Do you think we can keep DICOM working as-is if the plugin is explicitly selected? That might help. |
We ran into this before but simply patched it in the function that encountered it instead of dealing with it formerly. For example: imageio/imageio/core/request.py Lines 572 to 579 in b4cbde8 In this particular case, we are encountering it because I made tifffile's
I'm not sure if this is possible to change incrementally; my hunch is that it isn't. However, at the moment, we even struggle to detect if the request points to a file vs. a folder, so even if we would be willing to add changes to all plugins in one go, we would first have to establish how this info is shared with plugins.
Yes, that's what I implemented in 4923c7d. If the request is called with an explicit This is, however, me adding a quick-fix to solve breaking CI, so we might still want to formalize this behavior to avoid doing more quick-fix patches (and remove the ones we have already). |
Given the circumstances I think that fix is actually not that hacky. Formalizing support for folders just because of this one plugin, without any further advantages, is also not great. What I mean to say: I don't there is a "pure" way to deal with this, and the current solution is clear for the user and confines the odd feature of being able to read a directory to a specific plugin. |
Yep. Given my perspective (maintainer level background knowledge of what ImageIO does and does not do), I agree here. Explicit support for folders adds much more problems than it solves. It can be like this for now, but I will dare to make a prophecy and say that we will bump into this issue again further down the road x). When I said On the other hand the question "how to read a folder of images with ImageIO?" is one of the more popular questions that I encounter when I am digging for problems with the library to find features we might wish to add. Our example on reading folders does address this, however, so I don't see it as a high-priority issue for now :) Unless you have any unresolved points @almarklein I think the above should resolve/conclude all open points. There is still the |
I won't be surprised either :)
Could you please remind me how this will affect users? |
Sure. On current master, In this PR I currently see no trivial way around this, and the correct way to resolve it is to make |
|
Ok, seems like very much an edge case to me, and we can probably live with that regression temporarily. |
|
@almarklein Okay looks like we agree on all the open points. Anything else to add or should we merge once the tests pass? (They currently beak because of a merge conflict with master. We introduced |
|
I failed to use Nuitka to pack imageio with 'pyav' plugin, |
|
@huangxin168 I have never used Nuitka myself. That said, based on my brief google search it will discover files to include by scanning the source for Since Nuitka also acts as a compiler, another point to investigate is how it interacts with C extensions. This is because |
|
@FirefoxMetzger I tried --include-plugin-directory, unfortunately the same. Thank you for your help. |
Closes #641
Closes #677 (fix is implemented here)
Closes #665
Closes #334
Issues that may be closed or will become easy to close
#580
This PR is essentially a large refactor of the plugin manager that aligns
imopen, the oldFormatManagerand the docs and forces them to remain in sync. It does so by adding (and changing) a few things:imageio.corenow relies onimageio.configfor global configuration (formerly used for docs only).known_pluginsandknown_extensionsinimageio.configto track extensions and plugins.imopennow looks up the request's extension inknown_extensionsand (upon success) tries relevant plugins first. (Smart searching of plugins by accounting for the file's extension. #641)imopennow checksknown_pluginswhen checking all plugins (if extension-based handling doesn't work).imopen's state is no longer needed, so it is now a function (formerly it was a class).FormatManagernow internally delegates all format lookups toimopen. (formerly,imopencalled the format manager as a fallback when it couldn't find a plugin).FormatManager'sadd_formatnow adds a format toknown_formatsand it'ssortmethod sortsknown_formats.imopenwill now lazy-import a plugin during the first time it selects that plugin to handle a request. (fixes 'import imageio' on M1 MacBook with Python 3.9 causes "MemoryError" - installed with conda/pip #665 because FreeImage will only be imported when actually used by the code)imopenwill now display a friendly error message in cases a request could not be handled, but a user might be able to install a plugin to handle it. (Improve error message when reading an EXR file without plugin installed #334)FormatManagerwill now lazy-import a plugin during the first time it is asked to return a format of that plugin._can_readto handle a bug in FreeImage related to PPM and PBM files (FreeImage identifies images written via PPM-FI as PBM-FI. #677)Lazy-importing should also be a good first step towards factoring out some of the backends (including FreeImage), which would eventually address #580.
What is left for this PR: