Skip to content

Commit 50e1ea0

Browse files
author
Martin Durant
committed
Feedback after release
- registry loose versions dropped - current directory cannot be deleted
1 parent 61ec18f commit 50e1ea0

File tree

3 files changed

+41
-28
lines changed

3 files changed

+41
-28
lines changed

fsspec/implementations/local.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,7 @@ def glob(self, path, **kwargs):
5656
return super().glob(path, **kwargs)
5757

5858
def info(self, path, **kwargs):
59-
if isinstance(path, str):
60-
path = self._strip_protocol(path)
61-
out = os.stat(path, follow_symlinks=False)
62-
link = os.path.islink(path)
63-
if os.path.isdir(path):
64-
t = "directory"
65-
elif os.path.isfile(path):
66-
t = "file"
67-
else:
68-
t = "other"
69-
else:
59+
if hasattr(path, "stat"):
7060
# scandir DirEntry
7161
out = path.stat(follow_symlinks=False)
7262
link = path.is_symlink()
@@ -77,6 +67,17 @@ def info(self, path, **kwargs):
7767
else:
7868
t = "other"
7969
path = self._strip_protocol(path.path)
70+
else:
71+
# str or path-like
72+
path = self._strip_protocol(path)
73+
out = os.stat(path, follow_symlinks=False)
74+
link = os.path.islink(path)
75+
if os.path.isdir(path):
76+
t = "directory"
77+
elif os.path.isfile(path):
78+
t = "file"
79+
else:
80+
t = "other"
8081
result = {
8182
"name": path,
8283
"size": out.st_size,
@@ -121,6 +122,9 @@ def mv_file(self, path1, path2, **kwargs):
121122
def rm(self, path, recursive=False, maxdepth=None):
122123
path = self._strip_protocol(path).rstrip("/")
123124
if recursive and self.isdir(path):
125+
126+
if os.path.abspath(path) == os.getcwd():
127+
raise ValueError("Cannot delete current working directory")
124128
shutil.rmtree(path)
125129
else:
126130
os.remove(path)
@@ -161,7 +165,7 @@ def _strip_protocol(cls, path):
161165
path = stringify_path(path)
162166
if path.startswith("file://"):
163167
path = path[7:]
164-
return make_path_posix(path)
168+
return make_path_posix(path).rstrip("/")
165169

166170
def _isfilestore(self):
167171
# Inheriting from DaskFileSystem makes this False (S3, etc. were)

fsspec/implementations/tests/test_local.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,3 +662,14 @@ def test_transaction(tmpdir):
662662
read_content = fp.read()
663663

664664
assert content == read_content
665+
666+
667+
def test_delete_cwd(tmpdir):
668+
cwd = os.getcwd()
669+
fs = LocalFileSystem()
670+
try:
671+
os.chdir(tmpdir)
672+
with pytest.raises(ValueError):
673+
fs.rm(".", recursive=True)
674+
finally:
675+
os.chdir(cwd)

fsspec/registry.py

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import importlib
2-
from distutils.version import LooseVersion
32

43
__all__ = ["registry", "get_filesystem_class", "default"]
54

@@ -187,8 +186,6 @@ def register_implementation(name, cls, clobber=True, errtxt=None):
187186
"reference": {"class": "fsspec.implementations.reference.ReferenceFileSystem"},
188187
}
189188

190-
minversions = {"s3fs": LooseVersion("0.3.0"), "gcsfs": LooseVersion("0.3.0")}
191-
192189

193190
def get_filesystem_class(protocol):
194191
"""Fetch named protocol implementation from the registry
@@ -221,19 +218,20 @@ def get_filesystem_class(protocol):
221218

222219

223220
def _import_class(cls, minv=None):
224-
mod, name = cls.rsplit(".", 1)
225-
minv = minv or minversions
226-
minversion = minv.get(mod, None)
227-
228-
mod = importlib.import_module(mod)
229-
if minversion:
230-
version = getattr(mod, "__version__", None)
231-
if version and LooseVersion(version) < minversion:
232-
raise RuntimeError(
233-
"'{}={}' is installed, but version '{}' or "
234-
"higher is required".format(mod.__name__, version, minversion)
235-
)
236-
return getattr(mod, name)
221+
"""Take a string FQP and return the imported class or identifier
222+
223+
clas is of the form "package.module.klass" or "package.module:subobject.klass"
224+
"""
225+
if ":" in cls:
226+
mod, name = cls.rsplit(":", 1)
227+
mod = importlib.import_module(mod)
228+
for part in name.split("."):
229+
mod = getattr(mod, part)
230+
return mod
231+
else:
232+
mod, name = cls.rsplit(".", 1)
233+
mod = importlib.import_module(mod)
234+
return getattr(mod, name)
237235

238236

239237
def filesystem(protocol, **storage_options):

0 commit comments

Comments
 (0)