Accept pathlib.Path in reading and writing utilities#473
Open
omkar-334 wants to merge 2 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The reading and writing utilities accepted only
strpaths. This widens them to also acceptpathlib.Path, in addition tostr, so callers (napari included) no longer have to stringify paths before calling npe2.The approach is to accept
PathLike(str | pathlib.Path) at the public API and normalisePathtostrwithos.fspathbefore any path matching or plugin dispatch. Reader and writer plugins keep receivingstr, so existing plugins are unaffected. Remote URLs are passed asstrand pass through unchanged.Changes:
types.PathLikeis nowstr | pathlib.Path(wasstr).io_utils:read,read_get_reader,write,write_get_writer(and the internal_read/_write/_get_compatible_readers_by_choice) accept and normalisePath.PluginManager:iter_compatible_readersandget_writeraccept and normalisePath.Resolves the npe2 side of napari/napari#8586.
Testing strategy
Pathbased tests intests/test__io_utils.pycoveringread,read_get_reader(single and stacked),write, andwrite_get_writer.strwhen aPathis passed, to lock in backwards compatibility.Pathtest forPluginManager.iter_compatible_readersintests/test_plugin_manager.py.strbased tests are unchanged and still pass, confirming no behaviour change for current callers.Run: