diff --git a/pygmt/src/which.py b/pygmt/src/which.py index d20059f0492..3fdcafa91f5 100644 --- a/pygmt/src/which.py +++ b/pygmt/src/which.py @@ -6,14 +6,13 @@ GMTTempFile, build_arg_string, fmt_docstring, - kwargs_to_strings, + is_nonstr_iter, use_alias, ) @fmt_docstring @use_alias(G="download", V="verbose") -@kwargs_to_strings(fname="sequence_space") def which(fname, **kwargs): r""" Find the full path to specified files. @@ -63,6 +62,9 @@ def which(fname, **kwargs): FileNotFoundError If the file is not found. """ + if is_nonstr_iter(fname): # Got a list of files + fname = " ".join(fname) + with GMTTempFile() as tmpfile: with Session() as lib: lib.call_module( diff --git a/pygmt/tests/test_which.py b/pygmt/tests/test_which.py index 15cb48963c3..b482b247b4d 100644 --- a/pygmt/tests/test_which.py +++ b/pygmt/tests/test_which.py @@ -1,7 +1,7 @@ """ Test pygmt.which. """ -import os +from pathlib import Path import pytest from pygmt import which @@ -13,9 +13,9 @@ def test_which(): Make sure `which` returns file paths for @files correctly without errors. """ for fname in ["tut_quakes.ngdc", "tut_bathy.nc"]: - cached_file = which(f"@{fname}", download="c") - assert os.path.exists(cached_file) - assert os.path.basename(cached_file) == fname + cached_file = which(fname=f"@{fname}", download="c") + assert Path(cached_file).exists() + assert Path(cached_file).name == fname def test_which_multiple(): @@ -23,10 +23,10 @@ def test_which_multiple(): Make sure `which` returns file paths for multiple @files correctly. """ filenames = ["ridge.txt", "tut_ship.xyz"] - cached_files = which(fname=[f"@{fname}" for fname in filenames], download="c") + cached_files = which([f"@{fname}" for fname in filenames], download="c") for cached_file in cached_files: - assert os.path.exists(cached_file) - assert os.path.basename(cached_file) in filenames + assert Path(cached_file).exists() + assert Path(cached_file).name in filenames def test_which_fails():