Skip to content

Commit 8ca9eeb

Browse files
authored
warn on incompatible fsspec installation (#206)
* warn on incompatible fsspec installation * make it more robust * use once_per_args
1 parent 04b12d0 commit 8ca9eeb

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

setup.cfg

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ install_requires=
2929
funcy>=1.14
3030
fsspec>=2022.10.0
3131
typing-extensions>=3.7.4
32+
packaging>=19
3233

3334
[options.extras_require]
3435
tests =

src/dvc_objects/fs/base.py

+29-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
)
2323

2424
from fsspec.asyn import get_loop
25-
from funcy import cached_property
25+
from funcy import cached_property, once_per_args
2626

2727
from ..executors import ThreadPoolExecutor, batch_coros
2828
from .callbacks import DEFAULT_CALLBACK, Callback
@@ -58,6 +58,33 @@ def __init__(self, link: str, fs: "FileSystem", path: str) -> None:
5858
)
5959

6060

61+
@once_per_args
62+
def check_required_version(
63+
pkg: str, dist: str = "dvc_objects", log_level=logging.WARNING
64+
):
65+
from importlib import metadata
66+
67+
from packaging.requirements import InvalidRequirement, Requirement
68+
69+
try:
70+
reqs = {
71+
r.name: r.specifier for r in map(Requirement, metadata.requires(dist) or [])
72+
}
73+
version = metadata.version(pkg)
74+
except (metadata.PackageNotFoundError, InvalidRequirement):
75+
return
76+
77+
specifier = reqs.get(pkg)
78+
if specifier and version and version not in specifier:
79+
logger.log(
80+
log_level,
81+
"'%s%s' is required, but you have %r installed which is incompatible.",
82+
pkg,
83+
specifier,
84+
version,
85+
)
86+
87+
6188
class FileSystem:
6289
sep = "/"
6390

@@ -142,6 +169,7 @@ def get_missing_deps(cls) -> List[str]:
142169
def _check_requires(self, **kwargs):
143170
from .scheme import Schemes
144171

172+
check_required_version(pkg="fsspec")
145173
missing = self.get_missing_deps()
146174
if not missing:
147175
return

0 commit comments

Comments
 (0)