Skip to content

Commit

Permalink
Re-enable passing auto_mkdir in url_to_fs to the fs class (#1358)
Browse files Browse the repository at this point in the history
* Re-enable passing auto_mkdir in url_to_fs to the fs class

* add test
  • Loading branch information
martindurant authored Sep 11, 2023
1 parent 4eeba2b commit 765809a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
8 changes: 0 additions & 8 deletions fsspec/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ def open_files(
num=1,
protocol=None,
newline=None,
auto_mkdir=True,
expand=True,
**kwargs,
):
Expand Down Expand Up @@ -249,9 +248,6 @@ def open_files(
newline: bytes or None
Used for line terminator in text mode. If None, uses system default;
if blank, uses no translation.
auto_mkdir: bool (True)
If in write mode, this will ensure the target directory exists before
writing, by calling ``fs.mkdirs(exist_ok=True)``.
expand: bool
**kwargs: dict
Extra options that make sense to a particular storage connection, e.g.
Expand Down Expand Up @@ -288,9 +284,6 @@ def open_files(
protocol=protocol,
expand=expand,
)
if "r" not in mode and auto_mkdir:
parents = {fs._parent(path) for path in paths}
[fs.makedirs(parent, exist_ok=True) for parent in parents]
return OpenFiles(
[
OpenFile(
Expand Down Expand Up @@ -363,7 +356,6 @@ def url_to_fs(url, **kwargs):
# non-FS arguments that appear in fsspec.open()
# inspect could keep this in sync with open()'s signature
known_kwargs = {
"auto_mkdir",
"compression",
"encoding",
"errors",
Expand Down
13 changes: 9 additions & 4 deletions fsspec/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,10 @@ def test_pathobject(tmpdir):

def test_automkdir(tmpdir):
dir = os.path.join(str(tmpdir), "a")
of = fsspec.open(os.path.join(dir, "afile"), "w")
with of:
pass
assert "afile" in os.listdir(dir)
of = fsspec.open(os.path.join(dir, "afile"), "w", auto_mkdir=False)
with pytest.raises(IOError):
with of:
pass

dir = os.path.join(str(tmpdir), "b")
of = fsspec.open(os.path.join(dir, "bfile"), "w", auto_mkdir=True)
Expand Down Expand Up @@ -306,3 +306,8 @@ def test_chained_url(ftp_writable):
url += f"::ftp://{username}:{password}@{host}:{port}/archive.zip"
with fsspec.open(url, "rb") as f:
assert f.read() == data["afile"]


def test_automkdir_local():
fs, _ = fsspec.core.url_to_fs("file://", auto_mkdir=True)
assert fs.auto_mkdir is True

0 comments on commit 765809a

Please sign in to comment.