Skip to content

Commit

Permalink
Allow file mode="x" with get_fs_token_paths (#1333)
Browse files Browse the repository at this point in the history
* Also expand paths in exclusive file creation mode=x

* Add test for filepath expandsion with file mode=x
  • Loading branch information
GenevieveBuckley authored Aug 16, 2023
1 parent 45a6aec commit a988ce5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions fsspec/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,8 @@ def get_fs_token_paths(
else:
if "w" in mode and expand:
paths = _expand_paths(paths, name_function, num)
elif "x" in mode and expand:
paths = _expand_paths(paths, name_function, num)
elif "*" in paths:
paths = [f for f in sorted(fs.glob(paths)) if not fs.isdir(f)]
else:
Expand Down
6 changes: 6 additions & 0 deletions fsspec/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
_expand_paths,
expand_paths_if_needed,
get_compression,
get_fs_token_paths,
open_files,
open_local,
)
Expand Down Expand Up @@ -75,6 +76,11 @@ def test_expand_error():
_expand_paths("*.*", None, 1)


@pytest.mark.parametrize("mode", ["w", "w+", "x", "x+"])
def test_expand_fs_token_paths(mode):
assert len(get_fs_token_paths("path", mode, num=2, expand=True)[-1]) == 2


def test_openfile_api(m):
m.open("somepath", "wb").write(b"data")
of = OpenFile(m, "somepath")
Expand Down

0 comments on commit a988ce5

Please sign in to comment.