From 472be826717c73701ffdd0f61432869efbed20b0 Mon Sep 17 00:00:00 2001 From: Luis Antonio Obis Aparicio <35803280+lobis@users.noreply.github.com> Date: Tue, 14 Nov 2023 16:23:39 -0600 Subject: [PATCH] feat: add fsspec as required dependency (#1021) * fsspec requirements * simplify fsspec import * use loop property * correctly create schemes list --- pyproject.toml | 2 +- src/uproot/_util.py | 11 ++--------- src/uproot/source/fsspec.py | 7 +++---- 3 files changed, 6 insertions(+), 14 deletions(-) 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", diff --git a/src/uproot/_util.py b/src/uproot/_util.py index 2e4d1331f..dbbacf941 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 @@ -275,15 +276,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 = list({*_remote_schemes, *fsspec.available_protocols()}) _uri_scheme = re.compile("^(" + "|".join([re.escape(x) for x in _schemes]) + ")://") _uri_scheme_chain = re.compile( diff --git a/src/uproot/source/fsspec.py b/src/uproot/source/fsspec.py index 2b9ba1d49..0cbf295e3 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()) @@ -189,8 +190,6 @@ 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: