Skip to content

Commit

Permalink
Only make dst dir when src req is satisfied
Browse files Browse the repository at this point in the history
  • Loading branch information
maddenp-noaa committed Dec 7, 2024
1 parent 89941b5 commit 7f05b41
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/uwtools/tests/utils/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,12 @@ def test_tasks_filecopy_source_local(src, ok):
with patch.object(tasks, "file", exists):
with patch.object(tasks, "copy") as copy:
tasks.filecopy(src=src, dst=dst)
mkdir.assert_called_once_with(parents=True, exist_ok=True)
copy.assert_called_once_with(Path(src), Path(dst))
else:
with raises(UWConfigError) as e:
tasks.filecopy(src=src, dst=dst)
assert str(e.value) == "Support for scheme 'foo' not implemented"
mkdir.assert_called_once_with(parents=True, exist_ok=True)


def test_tasks_symlink_simple(tmp_path):
Expand Down
3 changes: 2 additions & 1 deletion src/uwtools/utils/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,16 @@ def filecopy(src: Union[Path, str], dst: Union[Path, str]):
yield "Copy %s -> %s" % (src, dst)
yield asset(Path(dst), Path(dst).is_file)
dst = Path(dst) # currently no support for remote destinations
dst.parent.mkdir(parents=True, exist_ok=True)
scheme = urlparse(str(src)).scheme
if scheme in SCHEMES.local:
src = Path(src)
yield file(src)
dst.parent.mkdir(parents=True, exist_ok=True)
copy(src, dst)
elif scheme in SCHEMES.http:
src = str(src)
yield existing(src)
dst.parent.mkdir(parents=True, exist_ok=True)
response = requests.get(src, allow_redirects=True, timeout=3)
if (code := response.status_code) == 200:
with open(dst, "wb") as f:
Expand Down

0 comments on commit 7f05b41

Please sign in to comment.