From 2ef861a7d932565b2c38dfbc4be01fea7cab9096 Mon Sep 17 00:00:00 2001 From: Hagen Wierstorf Date: Tue, 5 Dec 2023 10:33:50 +0100 Subject: [PATCH 1/3] Support *paths in touch() --- audeer/core/io.py | 8 ++++++-- tests/test_io.py | 7 +++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/audeer/core/io.py b/audeer/core/io.py index 6b957bc..c0a7178 100644 --- a/audeer/core/io.py +++ b/audeer/core/io.py @@ -969,7 +969,8 @@ def rmdir( def touch( - path: typing.Union[str, bytes] + path: typing.Union[str, bytes], + *paths: typing.Sequence[typing.Union[str, bytes]], ) -> str: """Create an empty file. @@ -979,6 +980,9 @@ def touch( Args: path: path to file + *paths: additional arguments + to be joined with ``path`` + by :func:`os.path.join` Returns: expanded path to file @@ -989,7 +993,7 @@ def touch( 'file.txt' """ - path = safe_path(path) + path = safe_path(path, *paths) if os.path.exists(path): os.utime(path, None) else: diff --git a/tests/test_io.py b/tests/test_io.py index b252b55..6d2b5a7 100644 --- a/tests/test_io.py +++ b/tests/test_io.py @@ -505,7 +505,7 @@ def test_list_dir_names(tmpdir, dir_list, expected, recursive, hidden): def test_list_dir_names_errors(tmpdir): with pytest.raises(NotADirectoryError): - file = audeer.touch(audeer.path(tmpdir, 'file.txt')) + file = audeer.touch(tmpdir, 'file.txt') audeer.list_dir_names(file) with pytest.raises(FileNotFoundError): audeer.list_dir_names('not-existent') @@ -1153,7 +1153,7 @@ def test_move_file(tmpdir, src_file, dst_file): tmp_path = str(tmpdir.mkdir('folder')) tmp_path = audeer.mkdir(tmp_path) - src_path = audeer.touch(os.path.join(tmp_path, src_file)) + src_path = audeer.touch(tmp_path, src_file) dst_path = os.path.join(tmp_path, dst_file) audeer.move_file(src_path, dst_path) @@ -1220,8 +1220,7 @@ def test_rmdir(tmpdir): def test_touch(tmpdir): - path = str(tmpdir.mkdir('folder1')) - path = audeer.mkdir(path) + path = audeer.mkdir(tmpdir, 'folder1') path = os.path.join(path, 'file') assert not os.path.exists(path) audeer.touch(path) From 83ee79d8d31cdf30ed1403bf8aee550b14750eab Mon Sep 17 00:00:00 2001 From: Hagen Wierstorf Date: Tue, 5 Dec 2023 11:09:34 +0100 Subject: [PATCH 2/3] Update examples of list_file_names() --- audeer/core/io.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/audeer/core/io.py b/audeer/core/io.py index c0a7178..93b0f20 100644 --- a/audeer/core/io.py +++ b/audeer/core/io.py @@ -576,12 +576,12 @@ def list_file_names( Examples: >>> dir_path = mkdir('path') - >>> _ = touch(os.path.join(dir_path, 'file.wav')) - >>> _ = touch(os.path.join(dir_path, 'File.wav')) - >>> _ = touch(os.path.join(dir_path, '.lock')) + >>> _ = touch(dir_path, 'file.wav') + >>> _ = touch(dir_path, 'File.wav') + >>> _ = touch(dir_path, '.lock') >>> sub_dir_path = mkdir('path', 'sub') - >>> _ = touch(os.path.join(sub_dir_path, 'file.ogg')) - >>> _ = touch(os.path.join(sub_dir_path, '.lock')) + >>> _ = touch(sub_dir_path, 'file.ogg') + >>> _ = touch(sub_dir_path, '.lock') >>> list_file_names( ... dir_path, ... basenames=True, From 605a2b00e293e24f1e74281e58684662d8e1ae77 Mon Sep 17 00:00:00 2001 From: Hagen Wierstorf Date: Tue, 5 Dec 2023 11:10:01 +0100 Subject: [PATCH 3/3] Update example of move_file() --- audeer/core/io.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/audeer/core/io.py b/audeer/core/io.py index 93b0f20..23ed766 100644 --- a/audeer/core/io.py +++ b/audeer/core/io.py @@ -860,7 +860,7 @@ def move_file( Examples: >>> path = mkdir('folder') - >>> src_path = touch(os.path.join(path, 'file1')) + >>> src_path = touch(path, 'file1') >>> dst_path = os.path.join(path, 'file2') >>> move_file(src_path, dst_path) >>> list_file_names(path, basenames=True)