From e599139a7d5524758e54031097f8347869be9393 Mon Sep 17 00:00:00 2001 From: Luis Antonio Obis Aparicio Date: Tue, 14 Nov 2023 10:27:07 -0600 Subject: [PATCH 1/4] fsspec requirements --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 23c34eb93..ecb0389a4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -36,6 +36,7 @@ dependencies = [ "awkward>=2.4.6", "importlib-metadata;python_version<\"3.8\"", "numpy", + "fsspec", "packaging", "typing_extensions>=4.1.0; python_version < \"3.11\"" ] @@ -61,7 +62,6 @@ test = [ "lz4", "minio", "aiohttp; python_version<\"3.12\"", # asyncio not available - "fsspec", "fsspec-xrootd", "s3fs; python_version<\"3.12\"", # asyncio not available "paramiko", From 8f47a31dc573c0983e1b5adaaf42aaa6f9e89454 Mon Sep 17 00:00:00 2001 From: Luis Antonio Obis Aparicio Date: Tue, 14 Nov 2023 10:37:28 -0600 Subject: [PATCH 2/4] simplify fsspec import --- src/uproot/_util.py | 11 ++--------- src/uproot/source/fsspec.py | 9 ++++----- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/src/uproot/_util.py b/src/uproot/_util.py index e3f5b0f51..0149ea981 100644 --- a/src/uproot/_util.py +++ b/src/uproot/_util.py @@ -19,6 +19,7 @@ from collections.abc import Iterable from urllib.parse import unquote, urlparse +import fsspec import numpy import packaging.version @@ -282,15 +283,7 @@ def regularize_path(path): _windows_absolute_path_pattern_slash = re.compile(r"^[\\/][A-Za-z]:[\\/]") _remote_schemes = ["root", "s3", "http", "https"] -_schemes = ["file", *_remote_schemes] - -try: - # TODO: remove this try/except when fsspec becomes a required dependency - import fsspec - - _schemes = list({*_schemes, *fsspec.available_protocols()}) -except ImportError: - pass +_schemes = fsspec.available_protocols() _uri_scheme = re.compile("^(" + "|".join([re.escape(x) for x in _schemes]) + ")://") diff --git a/src/uproot/source/fsspec.py b/src/uproot/source/fsspec.py index 1419fea8e..afd0088ba 100644 --- a/src/uproot/source/fsspec.py +++ b/src/uproot/source/fsspec.py @@ -6,6 +6,9 @@ import concurrent.futures import queue +import fsspec +import fsspec.asyn + import uproot import uproot.source.chunk import uproot.source.futures @@ -24,8 +27,6 @@ class FSSpecSource(uproot.source.chunk.Source): """ def __init__(self, file_path: str, **options): - import fsspec.core - default_options = uproot.reading.open.defaults exclude_keys = set(default_options.keys()) @@ -188,11 +189,9 @@ def closed(self) -> bool: class FSSpecLoopExecutor(uproot.source.futures.Executor): @property def loop(self) -> asyncio.AbstractEventLoop: - import fsspec.asyn - return fsspec.asyn.get_loop() def submit(self, coroutine) -> concurrent.futures.Future: if not asyncio.iscoroutine(coroutine): raise TypeError("loop executor can only submit coroutines") - return asyncio.run_coroutine_threadsafe(coroutine, self.loop) + return asyncio.run_coroutine_threadsafe(coroutine, fsspec.asyn.get_loop()) From 9f76defb306026f7f34879907e1c3137e136ddcb Mon Sep 17 00:00:00 2001 From: Luis Antonio Obis Aparicio Date: Tue, 14 Nov 2023 10:38:28 -0600 Subject: [PATCH 3/4] use loop property --- src/uproot/source/fsspec.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/uproot/source/fsspec.py b/src/uproot/source/fsspec.py index afd0088ba..65640a329 100644 --- a/src/uproot/source/fsspec.py +++ b/src/uproot/source/fsspec.py @@ -194,4 +194,4 @@ def loop(self) -> asyncio.AbstractEventLoop: def submit(self, coroutine) -> concurrent.futures.Future: if not asyncio.iscoroutine(coroutine): raise TypeError("loop executor can only submit coroutines") - return asyncio.run_coroutine_threadsafe(coroutine, fsspec.asyn.get_loop()) + return asyncio.run_coroutine_threadsafe(coroutine, self.loop) From fe1301d5858e3b0320ebc0c66e05094112766106 Mon Sep 17 00:00:00 2001 From: Luis Antonio Obis Aparicio Date: Tue, 14 Nov 2023 10:41:14 -0600 Subject: [PATCH 4/4] correctly create schemes list --- src/uproot/_util.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/uproot/_util.py b/src/uproot/_util.py index 0149ea981..c28a23fdb 100644 --- a/src/uproot/_util.py +++ b/src/uproot/_util.py @@ -283,7 +283,7 @@ def regularize_path(path): _windows_absolute_path_pattern_slash = re.compile(r"^[\\/][A-Za-z]:[\\/]") _remote_schemes = ["root", "s3", "http", "https"] -_schemes = fsspec.available_protocols() +_schemes = list({*_remote_schemes, *fsspec.available_protocols()}) _uri_scheme = re.compile("^(" + "|".join([re.escape(x) for x in _schemes]) + ")://")