From 76b68ef73de6265df4d3f199e297f9ad983d9d70 Mon Sep 17 00:00:00 2001 From: Martin Durant Date: Mon, 18 Sep 2023 16:21:06 -0400 Subject: [PATCH] Revert auto_mkdir default in open() and special case local --- fsspec/core.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/fsspec/core.py b/fsspec/core.py index 6f3652c9a..50c446705 100644 --- a/fsspec/core.py +++ b/fsspec/core.py @@ -210,6 +210,7 @@ def open_files( num=1, protocol=None, newline=None, + auto_mkdir=True, expand=True, **kwargs, ): @@ -248,6 +249,9 @@ 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. @@ -284,6 +288,11 @@ def open_files( protocol=protocol, expand=expand, ) + if fs.protocol == "file": + fs.auto_mkdir = auto_mkdir + elif "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(