Skip to content

Commit

Permalink
Merge pull request #94 from NeurodataWithoutBorders/additional-url-re…
Browse files Browse the repository at this point in the history
…solver

Additional url resolver needed by dendro
  • Loading branch information
magland authored Sep 17, 2024
2 parents 2bc4007 + 3c326c5 commit 66c36d5
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lindi/LindiRemfile/LindiRemfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import time
import os
import requests
from .additional_url_resolvers import get_additional_url_resolvers
from ..LocalCache.LocalCache import LocalCache

default_min_chunk_size = 128 * 1024 # This is different from Remfile - this is an important decision because it determines the chunk size in the LocalCache
Expand Down Expand Up @@ -41,6 +42,7 @@ def __init__(
Does not support using multiple threads
Does not use memory cache if LocalCache is specified
Handles DANDI authentication
Handles additional_url_resolver
A note:
In the context of LINDI, this LindiRemfile is going to be used for loading
Expand Down Expand Up @@ -367,6 +369,8 @@ def _resolve_dandi_url(url: str):


def _resolve_url(url: str):
for aur in get_additional_url_resolvers():
url = aur(url)
if url in _global_resolved_urls:
elapsed = time.time() - _global_resolved_urls[url]["timestamp"]
if elapsed < 60 * 10:
Expand Down
14 changes: 14 additions & 0 deletions lindi/LindiRemfile/additional_url_resolvers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from typing import Callable, List


_global = {
'additional_url_resolvers': []
}


def get_additional_url_resolvers() -> List[Callable[[str], str]]:
return _global['additional_url_resolvers']


def add_additional_url_resolver(resolver: Callable[[str], str]):
_global['additional_url_resolvers'].append(resolver)
1 change: 1 addition & 0 deletions lindi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
from .LindiStagingStore import LindiStagingStore, StagingArea # noqa: F401
from .LocalCache.LocalCache import LocalCache, ChunkTooLargeError # noqa: F401
from .File.File import File # noqa: F401
from .LindiRemfile.additional_url_resolvers import add_additional_url_resolver # noqa: F401
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "lindi"
version = "0.4.0a1"
version = "0.4.0a2"
description = ""
authors = [
"Jeremy Magland <[email protected]>",
Expand Down

0 comments on commit 66c36d5

Please sign in to comment.