Skip to content

Commit b11bf8e

Browse files
authored
List late registered protocols (fsspec#358)
* tests: check if late registered fsspec impls are listed * upath.registry.available_implementations: add protocols from fsspec registry
1 parent ffd90c9 commit b11bf8e

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

upath/registry.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444

4545
from fsspec.core import get_filesystem_class
4646
from fsspec.registry import known_implementations as _fsspec_known_implementations
47+
from fsspec.registry import registry as _fsspec_registry
4748

4849
import upath
4950

@@ -148,11 +149,10 @@ def available_implementations(*, fallback: bool = False) -> list[str]:
148149
If True, also return protocols for fsspec filesystems without
149150
an implementation in universal_pathlib.
150151
"""
151-
impl = list(_registry)
152152
if not fallback:
153-
return impl
153+
return list(_registry)
154154
else:
155-
return list({*impl, *list(_fsspec_known_implementations)})
155+
return list({*_registry, *_fsspec_registry, *_fsspec_known_implementations})
156156

157157

158158
def register_implementation(

upath/tests/test_registry.py

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
1+
import random
2+
import string
3+
14
import pytest
2-
from fsspec.registry import known_implementations
5+
from fsspec.implementations.local import LocalFileSystem
6+
from fsspec.registry import _registry as fsspec_registry_private
7+
from fsspec.registry import known_implementations as fsspec_known_implementations
8+
from fsspec.registry import register_implementation as fsspec_register_implementation
9+
from fsspec.registry import registry as fsspec_registry
310

411
from upath import UPath
512
from upath.registry import available_implementations
@@ -69,9 +76,29 @@ def test_available_implementations():
6976
assert set(impl) == IMPLEMENTATIONS
7077

7178

72-
def test_available_implementations_with_fallback():
79+
@pytest.fixture
80+
def fake_registered_proto():
81+
fake_proto = "".join(random.choices(string.ascii_lowercase, k=8))
82+
83+
class FakeRandomFS(LocalFileSystem):
84+
protocol = fake_proto
85+
86+
fsspec_register_implementation(fake_proto, FakeRandomFS)
87+
try:
88+
yield fake_proto
89+
finally:
90+
fsspec_registry_private.pop(fake_proto, None)
91+
92+
93+
def test_available_implementations_with_fallback(fake_registered_proto):
7394
impl = available_implementations(fallback=True)
74-
assert set(impl) == IMPLEMENTATIONS.union(list(known_implementations))
95+
assert fake_registered_proto in impl
96+
assert set(impl) == IMPLEMENTATIONS.union(
97+
{
98+
*fsspec_known_implementations,
99+
*fsspec_registry,
100+
}
101+
)
75102

76103

77104
def test_available_implementations_with_entrypoint(fake_entrypoint):

0 commit comments

Comments
 (0)