Skip to content
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

Allow specifying which sources are checked with canReadList #1562

Merged
merged 1 commit into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Improvements
- Show a loading spinner on the image display in geojs in girder ([#1559](../../pull/1559))
- Better handle images that are composed of a folder and an item ([#1561](../../pull/1561))
- Allow specifying which sources are checked with canReadList ([#1562](../../pull/1562))

### Bug Fixes
- Fix a compositing error in transformed multi source images ([#1560](../../pull/1560))
Expand Down
9 changes: 6 additions & 3 deletions large_image/tilesource/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ def canRead(*args, **kwargs) -> bool:

def canReadList(
pathOrUri: Union[str, PosixPath], mimeType: Optional[str] = None,
availableSources: Optional[Dict[str, Type[FileTileSource]]] = None,
*args, **kwargs) -> List[Tuple[str, bool]]:
"""
Check if large_image can read a path or uri via each source.
Expand All @@ -218,16 +219,18 @@ def canReadList(
:param pathOrUri: either a file path or a fixed source via
large_image://<source>.
:param mimeType: the mimetype of the file, if known.
:param availableSources: an ordered dictionary of sources to try. If None,
use the primary list of sources.
:returns: A list of tuples of (source name, canRead).
"""
if not len(AvailableTileSources):
if availableSources is None and not len(AvailableTileSources):
loadTileSources()
sourceList = getSortedSourceList(
AvailableTileSources, pathOrUri, mimeType, *args, **kwargs)
availableSources or AvailableTileSources, pathOrUri, mimeType, *args, **kwargs)
result = []
for entry in sorted(sourceList):
sourceName = entry[-1]
result.append((sourceName, AvailableTileSources[sourceName].canRead(
result.append((sourceName, (availableSources or AvailableTileSources)[sourceName].canRead(
pathOrUri, *args, **kwargs)))
return result

Expand Down
6 changes: 5 additions & 1 deletion test/lisource_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,11 @@ def source_compare(sourcePath, opts): # noqa
else:
sys.stdout.write('%s\n' % sourcePath)
sys.stdout.flush()
canread = large_image.canReadList(sourcePath)
sublist = {
k: v for k, v in large_image.tilesource.AvailableTileSources.items()
if (getattr(opts, 'skipsource', None) is None or k not in opts.skipsource) and
(getattr(opts, 'usesource', None) is None or k in opts.usesource)}
canread = large_image.canReadList(sourcePath, availableSources=sublist)
large_image.cache_util.cachesClear()
slen = max([len(source) for source, _ in canread] + [10])
sys.stdout.write('Source' + ' ' * (slen - 6))
Expand Down