Skip to content

Create parent directories in get_file #1282

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 1 addition & 17 deletions fsspec/implementations/tests/memory/memory_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import pytest

import fsspec.tests.abstract as abstract
from fsspec.implementations.tests.memory.memory_fixtures import MemoryFixtures

Expand All @@ -9,21 +7,7 @@ class TestMemoryCopy(abstract.AbstractCopyTests, MemoryFixtures):


class TestMemoryGet(abstract.AbstractGetTests, MemoryFixtures):
@pytest.mark.skip(reason="Bug: does not auto-create new directory")
def test_get_file_to_new_directory(self):
pass

@pytest.mark.skip(reason="Bug: does not auto-create new directory")
def test_get_file_to_file_in_new_directory(self):
pass

@pytest.mark.skip(reason="Bug: does not auto-create new directory")
def test_get_glob_to_new_directory(self):
pass

@pytest.mark.skip(reason="Bug: does not auto-create new directory")
def test_get_list_of_files_to_new_directory(self):
pass
pass


class TestMemoryPut(abstract.AbstractPutTests, MemoryFixtures):
Expand Down
4 changes: 4 additions & 0 deletions fsspec/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -861,12 +861,16 @@ def get_file(
self, rpath, lpath, callback=_DEFAULT_CALLBACK, outfile=None, **kwargs
):
"""Copy single remote file to local"""
from .implementations.local import LocalFileSystem

if isfilelike(lpath):
outfile = lpath
elif self.isdir(rpath):
os.makedirs(lpath, exist_ok=True)
return None

LocalFileSystem(auto_mkdir=True).makedirs(self._parent(lpath), exist_ok=True)

with self.open(rpath, "rb", **kwargs) as f1:
if outfile is None:
outfile = open(lpath, "wb")
Expand Down