Skip to content

Commit

Permalink
Automatically create folders for local filesystem
Browse files Browse the repository at this point in the history
  • Loading branch information
sultaniman committed Apr 24, 2024
1 parent 536b616 commit fa81e25
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
8 changes: 8 additions & 0 deletions dlt/destinations/impl/filesystem/filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,15 @@ def __init__(
load_package_timestamp=dlt.current.load_package()["state"]["created_at"], # type: ignore
extra_placeholders=config.extra_placeholders,
)

# We would like to avoid failing for local filesystem where
# deeply nested directory will not exist before writing a file.
# It `auto_mkdir` is disabled by default in fsspec so we made some
# trade offs between different options and decided on this.
item = self.make_remote_path()
if self.config.protocol.startswith("file"):
fs_client.makedirs(posixpath.dirname(item), exist_ok=True)

fs_client.put_file(local_path, item)

def make_remote_path(self) -> str:
Expand Down
5 changes: 0 additions & 5 deletions tests/load/pipeline/test_filesystem_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,14 +305,9 @@ def count(*args, **kwargs) -> Any:
"hiphip": counter("Hurraaaa"),
}
now = pendulum.now()
kwargs = {}
if default_buckets_env.startswith("file://"):
kwargs = {"auto_mkdir": True}

fs_destination = filesystem(
layout=layout,
extra_placeholders=extra_placeholders,
kwargs=kwargs,
current_datetime=counter(now),
)
pipeline = dlt.pipeline(
Expand Down

0 comments on commit fa81e25

Please sign in to comment.