From 589449e911208619ce9591d9925f17effee48bdb Mon Sep 17 00:00:00 2001 From: KumoLiu Date: Thu, 7 Sep 2023 16:09:07 +0800 Subject: [PATCH 1/4] add `download_large_files` Signed-off-by: KumoLiu --- monai/bundle/__init__.py | 1 + monai/bundle/__main__.py | 1 + monai/bundle/scripts.py | 40 +++++++++ tests/test_bundle_download.py | 148 +++++++++++++++++++++------------- 4 files changed, 133 insertions(+), 57 deletions(-) diff --git a/monai/bundle/__init__.py b/monai/bundle/__init__.py index dd556e9eb3..97ce354d88 100644 --- a/monai/bundle/__init__.py +++ b/monai/bundle/__init__.py @@ -30,6 +30,7 @@ trt_export, verify_metadata, verify_net_in_out, + download_large_files, ) from .utils import ( DEFAULT_EXP_MGMT_SETTINGS, diff --git a/monai/bundle/__main__.py b/monai/bundle/__main__.py index e2a78bac5e..d82c58e37e 100644 --- a/monai/bundle/__main__.py +++ b/monai/bundle/__main__.py @@ -21,6 +21,7 @@ trt_export, verify_metadata, verify_net_in_out, + download_large_files, ) if __name__ == "__main__": diff --git a/monai/bundle/scripts.py b/monai/bundle/scripts.py index cdea2b4218..7e0f09dfca 100644 --- a/monai/bundle/scripts.py +++ b/monai/bundle/scripts.py @@ -1586,3 +1586,43 @@ def create_workflow( workflow_.initialize() return workflow_ + + +def download_large_files(bundle_path: str, large_file_name: str | None = None) -> None: + """ + This utility allows you to download large files from a bundle. It supports file suffixes like ".yml", ".yaml", and ".json". + If you don't specify a `large_file_name`, it will automatically search for large files among the supported suffixes. + + Typical usage examples: + .. code-block:: bash + + # Execute this module as a CLI entry to download large files from a bundle path: + python -m monai.bundle download_large_files --bundle_path + + # Execute this module as a CLI entry to download large files from the bundle path with a specified `large_file_name`: + python -m monai.bundle download_large_files --bundle_path --large_file_name large_files.yaml + + Args: + bundle_path: The path to the bundle where the files are located. + large_file_name: (Optional) The name of the large file to be downloaded. + + """ + if large_file_name is None: + for large_file_type in [".yml", ".yaml", ".json"]: + large_file_name = "large_files" + large_file_type + large_file_path = os.path.join(bundle_path, large_file_name) + if os.path.exists(large_file_path): + break + + parser = ConfigParser() + parser.read_config(os.path.join(bundle_path, large_file_name)) + large_files_list = parser.get()["large_files"] + for lf_data in large_files_list: + lf_data["fuzzy"] = True + if "hash_val" in lf_data and lf_data.get("hash_val", "") == "": + lf_data.pop("hash_val") + if "hash_type" in lf_data and lf_data.get("hash_type", "") == "": + lf_data.pop("hash_type") + lf_data["filepath"] = os.path.join(bundle_path, lf_data["path"]) + lf_data.pop("path") + download_url(**lf_data) diff --git a/tests/test_bundle_download.py b/tests/test_bundle_download.py index 2457af3229..48c57642dd 100644 --- a/tests/test_bundle_download.py +++ b/tests/test_bundle_download.py @@ -71,63 +71,70 @@ {"spatial_dims": 3, "out_channels": 5}, ] +TEST_CASE_8 = [ + ["network.json", "test_output.pt", "test_input.pt", "large_files.yaml"], + "test_bundle_v0.1.2", + "https://github.com/Project-MONAI/MONAI-extra-test-data/releases/download/0.8.1/test_bundle_v0.1.2.zip", + {"model.pt": "27952767e2e154e3b0ee65defc5aed38", "model.ts": "97746870fe591f69ac09827175b00675"}, +] -class TestDownload(unittest.TestCase): - @parameterized.expand([TEST_CASE_1, TEST_CASE_2]) - @skip_if_quick - def test_github_download_bundle(self, bundle_name, version): - bundle_files = ["model.pt", "model.ts", "network.json", "test_output.pt", "test_input.pt"] - repo = "Project-MONAI/MONAI-extra-test-data/0.8.1" - hash_val = "a131d39a0af717af32d19e565b434928" - with skip_if_downloading_fails(): - # download a whole bundle from github releases - with tempfile.TemporaryDirectory() as tempdir: - cmd = ["coverage", "run", "-m", "monai.bundle", "download", "--name", bundle_name, "--source", "github"] - cmd += ["--bundle_dir", tempdir, "--repo", repo] - if version is not None: - cmd += ["--version", version] - command_line_tests(cmd) - for file in bundle_files: - file_path = os.path.join(tempdir, "test_bundle", file) - self.assertTrue(os.path.exists(file_path)) - if file == "network.json": - self.assertTrue(check_hash(filepath=file_path, val=hash_val)) - - @parameterized.expand([TEST_CASE_3]) - @skip_if_quick - def test_url_download_bundle(self, bundle_files, bundle_name, url, hash_val): - with skip_if_downloading_fails(): - # download a single file from url, also use `args_file` - with tempfile.TemporaryDirectory() as tempdir: - def_args = {"name": bundle_name, "bundle_dir": tempdir, "url": ""} - def_args_file = os.path.join(tempdir, "def_args.json") - parser = ConfigParser() - parser.export_config_file(config=def_args, filepath=def_args_file) - cmd = ["coverage", "run", "-m", "monai.bundle", "download", "--args_file", def_args_file] - cmd += ["--url", url, "--source", "github"] - command_line_tests(cmd) - for file in bundle_files: - file_path = os.path.join(tempdir, bundle_name, file) - self.assertTrue(os.path.exists(file_path)) - if file == "network.json": - self.assertTrue(check_hash(filepath=file_path, val=hash_val)) - - @parameterized.expand([TEST_CASE_6]) - @skip_if_quick - def test_monaihosting_download_bundle(self, bundle_files, bundle_name, url): - with skip_if_downloading_fails(): - # download a single file from url, also use `args_file` - with tempfile.TemporaryDirectory() as tempdir: - def_args = {"name": bundle_name, "bundle_dir": tempdir, "url": ""} - def_args_file = os.path.join(tempdir, "def_args.json") - parser = ConfigParser() - parser.export_config_file(config=def_args, filepath=def_args_file) - cmd = ["coverage", "run", "-m", "monai.bundle", "download", "--args_file", def_args_file] - cmd += ["--url", url, "--progress", "False", "--source", "monaihosting"] - command_line_tests(cmd) - for file in bundle_files: - file_path = os.path.join(tempdir, bundle_name, file) - self.assertTrue(os.path.exists(file_path)) + +# class TestDownload(unittest.TestCase): +# @parameterized.expand([TEST_CASE_1, TEST_CASE_2]) +# @skip_if_quick +# def test_github_download_bundle(self, bundle_name, version): +# bundle_files = ["model.pt", "model.ts", "network.json", "test_output.pt", "test_input.pt"] +# repo = "Project-MONAI/MONAI-extra-test-data/0.8.1" +# hash_val = "a131d39a0af717af32d19e565b434928" +# with skip_if_downloading_fails(): +# # download a whole bundle from github releases +# with tempfile.TemporaryDirectory() as tempdir: +# cmd = ["coverage", "run", "-m", "monai.bundle", "download", "--name", bundle_name, "--source", "github"] +# cmd += ["--bundle_dir", tempdir, "--repo", repo] +# if version is not None: +# cmd += ["--version", version] +# command_line_tests(cmd) +# for file in bundle_files: +# file_path = os.path.join(tempdir, "test_bundle", file) +# self.assertTrue(os.path.exists(file_path)) +# if file == "network.json": +# self.assertTrue(check_hash(filepath=file_path, val=hash_val)) + +# @parameterized.expand([TEST_CASE_3]) +# @skip_if_quick +# def test_url_download_bundle(self, bundle_files, bundle_name, url, hash_val): +# with skip_if_downloading_fails(): +# # download a single file from url, also use `args_file` +# with tempfile.TemporaryDirectory() as tempdir: +# def_args = {"name": bundle_name, "bundle_dir": tempdir, "url": ""} +# def_args_file = os.path.join(tempdir, "def_args.json") +# parser = ConfigParser() +# parser.export_config_file(config=def_args, filepath=def_args_file) +# cmd = ["coverage", "run", "-m", "monai.bundle", "download", "--args_file", def_args_file] +# cmd += ["--url", url, "--source", "github"] +# command_line_tests(cmd) +# for file in bundle_files: +# file_path = os.path.join(tempdir, bundle_name, file) +# self.assertTrue(os.path.exists(file_path)) +# if file == "network.json": +# self.assertTrue(check_hash(filepath=file_path, val=hash_val)) + +# @parameterized.expand([TEST_CASE_6]) +# @skip_if_quick +# def test_monaihosting_download_bundle(self, bundle_files, bundle_name, url): +# with skip_if_downloading_fails(): +# # download a single file from url, also use `args_file` +# with tempfile.TemporaryDirectory() as tempdir: +# def_args = {"name": bundle_name, "bundle_dir": tempdir, "url": ""} +# def_args_file = os.path.join(tempdir, "def_args.json") +# parser = ConfigParser() +# parser.export_config_file(config=def_args, filepath=def_args_file) +# cmd = ["coverage", "run", "-m", "monai.bundle", "download", "--args_file", def_args_file] +# cmd += ["--url", url, "--progress", "False", "--source", "monaihosting"] +# command_line_tests(cmd) +# for file in bundle_files: +# file_path = os.path.join(tempdir, bundle_name, file) +# self.assertTrue(os.path.exists(file_path)) class TestLoad(unittest.TestCase): @@ -147,7 +154,6 @@ def test_load_weights(self, bundle_files, bundle_name, repo, device, model_file) progress=False, device=device, ) - # prepare network with open(os.path.join(tempdir, bundle_name, bundle_files[2])) as f: net_args = json.load(f)["network_def"] @@ -250,5 +256,33 @@ def test_load_ts_module(self, bundle_files, bundle_name, version, repo, device, self.assertTrue("network.json" in extra_file_dict.keys()) +# class TestDownloadLargefiles(unittest.TestCase): +# @parameterized.expand([TEST_CASE_8]) +# @skip_if_quick +# def test_url_download_large_files(self, bundle_files, bundle_name, url, hash_val): +# with skip_if_downloading_fails(): +# # download a single file from url, also use `args_file` +# with tempfile.TemporaryDirectory() as tempdir: +# def_args = {"name": bundle_name, "bundle_dir": tempdir, "url": ""} +# def_args_file = os.path.join(tempdir, "def_args.json") +# parser = ConfigParser() +# parser.export_config_file(config=def_args, filepath=def_args_file) +# cmd = ["coverage", "run", "-m", "monai.bundle", "download", "--args_file", def_args_file] +# cmd += ["--url", url, "--source", "github"] +# command_line_tests(cmd) +# for file in bundle_files: +# file_path = os.path.join(tempdir, bundle_name, file) +# print(file_path) +# self.assertTrue(os.path.exists(file_path)) + +# # download large files +# bundle_path = os.path.join(tempdir, bundle_name) +# cmd = ["coverage", "run", "-m", "monai.bundle", "download_large_files", "--bundle_path", bundle_path] +# command_line_tests(cmd) +# for file in ["model.pt", "model.ts"]: +# file_path = os.path.join(tempdir, bundle_name, f"models/{file}") +# self.assertTrue(check_hash(filepath=file_path, val=hash_val[file])) + + if __name__ == "__main__": unittest.main() From ad9ac07d4c0f7bd94936b365638928d98d02166c Mon Sep 17 00:00:00 2001 From: KumoLiu Date: Thu, 7 Sep 2023 16:14:02 +0800 Subject: [PATCH 2/4] add unittest Signed-off-by: KumoLiu --- monai/bundle/__init__.py | 2 +- monai/bundle/__main__.py | 2 +- tests/test_bundle_download.py | 164 +++++++++++++++++----------------- 3 files changed, 84 insertions(+), 84 deletions(-) diff --git a/monai/bundle/__init__.py b/monai/bundle/__init__.py index 97ce354d88..711f1d2875 100644 --- a/monai/bundle/__init__.py +++ b/monai/bundle/__init__.py @@ -19,6 +19,7 @@ ckpt_export, create_workflow, download, + download_large_files, get_all_bundles_list, get_bundle_info, get_bundle_versions, @@ -30,7 +31,6 @@ trt_export, verify_metadata, verify_net_in_out, - download_large_files, ) from .utils import ( DEFAULT_EXP_MGMT_SETTINGS, diff --git a/monai/bundle/__main__.py b/monai/bundle/__main__.py index d82c58e37e..778c9ef2f0 100644 --- a/monai/bundle/__main__.py +++ b/monai/bundle/__main__.py @@ -14,6 +14,7 @@ from monai.bundle.scripts import ( ckpt_export, download, + download_large_files, init_bundle, onnx_export, run, @@ -21,7 +22,6 @@ trt_export, verify_metadata, verify_net_in_out, - download_large_files, ) if __name__ == "__main__": diff --git a/tests/test_bundle_download.py b/tests/test_bundle_download.py index 6adb457f14..0ced1585a5 100644 --- a/tests/test_bundle_download.py +++ b/tests/test_bundle_download.py @@ -79,62 +79,62 @@ ] -# class TestDownload(unittest.TestCase): -# @parameterized.expand([TEST_CASE_1, TEST_CASE_2]) -# @skip_if_quick -# def test_github_download_bundle(self, bundle_name, version): -# bundle_files = ["model.pt", "model.ts", "network.json", "test_output.pt", "test_input.pt"] -# repo = "Project-MONAI/MONAI-extra-test-data/0.8.1" -# hash_val = "a131d39a0af717af32d19e565b434928" -# with skip_if_downloading_fails(): -# # download a whole bundle from github releases -# with tempfile.TemporaryDirectory() as tempdir: -# cmd = ["coverage", "run", "-m", "monai.bundle", "download", "--name", bundle_name, "--source", "github"] -# cmd += ["--bundle_dir", tempdir, "--repo", repo] -# if version is not None: -# cmd += ["--version", version] -# command_line_tests(cmd) -# for file in bundle_files: -# file_path = os.path.join(tempdir, "test_bundle", file) -# self.assertTrue(os.path.exists(file_path)) -# if file == "network.json": -# self.assertTrue(check_hash(filepath=file_path, val=hash_val)) - -# @parameterized.expand([TEST_CASE_3]) -# @skip_if_quick -# def test_url_download_bundle(self, bundle_files, bundle_name, url, hash_val): -# with skip_if_downloading_fails(): -# # download a single file from url, also use `args_file` -# with tempfile.TemporaryDirectory() as tempdir: -# def_args = {"name": bundle_name, "bundle_dir": tempdir, "url": ""} -# def_args_file = os.path.join(tempdir, "def_args.json") -# parser = ConfigParser() -# parser.export_config_file(config=def_args, filepath=def_args_file) -# cmd = ["coverage", "run", "-m", "monai.bundle", "download", "--args_file", def_args_file] -# cmd += ["--url", url, "--source", "github"] -# command_line_tests(cmd) -# for file in bundle_files: -# file_path = os.path.join(tempdir, bundle_name, file) -# self.assertTrue(os.path.exists(file_path)) -# if file == "network.json": -# self.assertTrue(check_hash(filepath=file_path, val=hash_val)) - -# @parameterized.expand([TEST_CASE_6]) -# @skip_if_quick -# def test_monaihosting_download_bundle(self, bundle_files, bundle_name, url): -# with skip_if_downloading_fails(): -# # download a single file from url, also use `args_file` -# with tempfile.TemporaryDirectory() as tempdir: -# def_args = {"name": bundle_name, "bundle_dir": tempdir, "url": ""} -# def_args_file = os.path.join(tempdir, "def_args.json") -# parser = ConfigParser() -# parser.export_config_file(config=def_args, filepath=def_args_file) -# cmd = ["coverage", "run", "-m", "monai.bundle", "download", "--args_file", def_args_file] -# cmd += ["--url", url, "--progress", "False", "--source", "monaihosting"] -# command_line_tests(cmd) -# for file in bundle_files: -# file_path = os.path.join(tempdir, bundle_name, file) -# self.assertTrue(os.path.exists(file_path)) +class TestDownload(unittest.TestCase): + @parameterized.expand([TEST_CASE_1, TEST_CASE_2]) + @skip_if_quick + def test_github_download_bundle(self, bundle_name, version): + bundle_files = ["model.pt", "model.ts", "network.json", "test_output.pt", "test_input.pt"] + repo = "Project-MONAI/MONAI-extra-test-data/0.8.1" + hash_val = "a131d39a0af717af32d19e565b434928" + with skip_if_downloading_fails(): + # download a whole bundle from github releases + with tempfile.TemporaryDirectory() as tempdir: + cmd = ["coverage", "run", "-m", "monai.bundle", "download", "--name", bundle_name, "--source", "github"] + cmd += ["--bundle_dir", tempdir, "--repo", repo] + if version is not None: + cmd += ["--version", version] + command_line_tests(cmd) + for file in bundle_files: + file_path = os.path.join(tempdir, "test_bundle", file) + self.assertTrue(os.path.exists(file_path)) + if file == "network.json": + self.assertTrue(check_hash(filepath=file_path, val=hash_val)) + + @parameterized.expand([TEST_CASE_3]) + @skip_if_quick + def test_url_download_bundle(self, bundle_files, bundle_name, url, hash_val): + with skip_if_downloading_fails(): + # download a single file from url, also use `args_file` + with tempfile.TemporaryDirectory() as tempdir: + def_args = {"name": bundle_name, "bundle_dir": tempdir, "url": ""} + def_args_file = os.path.join(tempdir, "def_args.json") + parser = ConfigParser() + parser.export_config_file(config=def_args, filepath=def_args_file) + cmd = ["coverage", "run", "-m", "monai.bundle", "download", "--args_file", def_args_file] + cmd += ["--url", url, "--source", "github"] + command_line_tests(cmd) + for file in bundle_files: + file_path = os.path.join(tempdir, bundle_name, file) + self.assertTrue(os.path.exists(file_path)) + if file == "network.json": + self.assertTrue(check_hash(filepath=file_path, val=hash_val)) + + @parameterized.expand([TEST_CASE_6]) + @skip_if_quick + def test_monaihosting_download_bundle(self, bundle_files, bundle_name, url): + with skip_if_downloading_fails(): + # download a single file from url, also use `args_file` + with tempfile.TemporaryDirectory() as tempdir: + def_args = {"name": bundle_name, "bundle_dir": tempdir, "url": ""} + def_args_file = os.path.join(tempdir, "def_args.json") + parser = ConfigParser() + parser.export_config_file(config=def_args, filepath=def_args_file) + cmd = ["coverage", "run", "-m", "monai.bundle", "download", "--args_file", def_args_file] + cmd += ["--url", url, "--progress", "False", "--source", "monaihosting"] + command_line_tests(cmd) + for file in bundle_files: + file_path = os.path.join(tempdir, bundle_name, file) + self.assertTrue(os.path.exists(file_path)) class TestLoad(unittest.TestCase): @@ -281,32 +281,32 @@ def test_load_ts_module(self, bundle_files, bundle_name, version, repo, device, self.assertTrue("network.json" in extra_file_dict.keys()) -# class TestDownloadLargefiles(unittest.TestCase): -# @parameterized.expand([TEST_CASE_8]) -# @skip_if_quick -# def test_url_download_large_files(self, bundle_files, bundle_name, url, hash_val): -# with skip_if_downloading_fails(): -# # download a single file from url, also use `args_file` -# with tempfile.TemporaryDirectory() as tempdir: -# def_args = {"name": bundle_name, "bundle_dir": tempdir, "url": ""} -# def_args_file = os.path.join(tempdir, "def_args.json") -# parser = ConfigParser() -# parser.export_config_file(config=def_args, filepath=def_args_file) -# cmd = ["coverage", "run", "-m", "monai.bundle", "download", "--args_file", def_args_file] -# cmd += ["--url", url, "--source", "github"] -# command_line_tests(cmd) -# for file in bundle_files: -# file_path = os.path.join(tempdir, bundle_name, file) -# print(file_path) -# self.assertTrue(os.path.exists(file_path)) - -# # download large files -# bundle_path = os.path.join(tempdir, bundle_name) -# cmd = ["coverage", "run", "-m", "monai.bundle", "download_large_files", "--bundle_path", bundle_path] -# command_line_tests(cmd) -# for file in ["model.pt", "model.ts"]: -# file_path = os.path.join(tempdir, bundle_name, f"models/{file}") -# self.assertTrue(check_hash(filepath=file_path, val=hash_val[file])) +class TestDownloadLargefiles(unittest.TestCase): + @parameterized.expand([TEST_CASE_8]) + @skip_if_quick + def test_url_download_large_files(self, bundle_files, bundle_name, url, hash_val): + with skip_if_downloading_fails(): + # download a single file from url, also use `args_file` + with tempfile.TemporaryDirectory() as tempdir: + def_args = {"name": bundle_name, "bundle_dir": tempdir, "url": ""} + def_args_file = os.path.join(tempdir, "def_args.json") + parser = ConfigParser() + parser.export_config_file(config=def_args, filepath=def_args_file) + cmd = ["coverage", "run", "-m", "monai.bundle", "download", "--args_file", def_args_file] + cmd += ["--url", url, "--source", "github"] + command_line_tests(cmd) + for file in bundle_files: + file_path = os.path.join(tempdir, bundle_name, file) + print(file_path) + self.assertTrue(os.path.exists(file_path)) + + # download large files + bundle_path = os.path.join(tempdir, bundle_name) + cmd = ["coverage", "run", "-m", "monai.bundle", "download_large_files", "--bundle_path", bundle_path] + command_line_tests(cmd) + for file in ["model.pt", "model.ts"]: + file_path = os.path.join(tempdir, bundle_name, f"models/{file}") + self.assertTrue(check_hash(filepath=file_path, val=hash_val[file])) if __name__ == "__main__": From e9756767a9f8c6fa012d7a7f584110629d40c291 Mon Sep 17 00:00:00 2001 From: KumoLiu Date: Thu, 7 Sep 2023 16:31:25 +0800 Subject: [PATCH 3/4] fix mypy Signed-off-by: KumoLiu --- monai/bundle/scripts.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/monai/bundle/scripts.py b/monai/bundle/scripts.py index 8315da03b8..be732147f6 100644 --- a/monai/bundle/scripts.py +++ b/monai/bundle/scripts.py @@ -1641,14 +1641,13 @@ def download_large_files(bundle_path: str, large_file_name: str | None = None) - """ if large_file_name is None: - for large_file_type in [".yml", ".yaml", ".json"]: - large_file_name = "large_files" + large_file_type - large_file_path = os.path.join(bundle_path, large_file_name) - if os.path.exists(large_file_path): - break + large_file_path = list(Path(bundle_path).glob("large_files*")) + large_file_path = list(filter(lambda x: x.suffix in [".yml", ".yaml", ".json"], large_file_path)) + if len(large_file_path) == 0: + raise FileNotFoundError("Cannot find the large files.") parser = ConfigParser() - parser.read_config(os.path.join(bundle_path, large_file_name)) + parser.read_config(large_file_path) large_files_list = parser.get()["large_files"] for lf_data in large_files_list: lf_data["fuzzy"] = True From 9432f8adf49bc41890365c29c2a8f48790559f5b Mon Sep 17 00:00:00 2001 From: KumoLiu Date: Thu, 7 Sep 2023 19:44:20 +0800 Subject: [PATCH 4/4] address comments Signed-off-by: KumoLiu --- monai/bundle/scripts.py | 7 ++++--- tests/test_bundle_download.py | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/monai/bundle/scripts.py b/monai/bundle/scripts.py index be732147f6..056a4ddef3 100644 --- a/monai/bundle/scripts.py +++ b/monai/bundle/scripts.py @@ -1621,7 +1621,7 @@ def create_workflow( return workflow_ -def download_large_files(bundle_path: str, large_file_name: str | None = None) -> None: +def download_large_files(bundle_path: str | None = None, large_file_name: str | None = None) -> None: """ This utility allows you to download large files from a bundle. It supports file suffixes like ".yml", ".yaml", and ".json". If you don't specify a `large_file_name`, it will automatically search for large files among the supported suffixes. @@ -1636,15 +1636,16 @@ def download_large_files(bundle_path: str, large_file_name: str | None = None) - python -m monai.bundle download_large_files --bundle_path --large_file_name large_files.yaml Args: - bundle_path: The path to the bundle where the files are located. + bundle_path: (Optional) The path to the bundle where the files are located. Default is `os.getcwd()`. large_file_name: (Optional) The name of the large file to be downloaded. """ + bundle_path = os.getcwd() if bundle_path is None else bundle_path if large_file_name is None: large_file_path = list(Path(bundle_path).glob("large_files*")) large_file_path = list(filter(lambda x: x.suffix in [".yml", ".yaml", ".json"], large_file_path)) if len(large_file_path) == 0: - raise FileNotFoundError("Cannot find the large files.") + raise FileNotFoundError(f"Cannot find the large_files.yml/yaml/json under {bundle_path}.") parser = ConfigParser() parser.read_config(large_file_path) diff --git a/tests/test_bundle_download.py b/tests/test_bundle_download.py index 0ced1585a5..3c78112bfa 100644 --- a/tests/test_bundle_download.py +++ b/tests/test_bundle_download.py @@ -73,7 +73,7 @@ TEST_CASE_8 = [ ["network.json", "test_output.pt", "test_input.pt", "large_files.yaml"], - "test_bundle_v0.1.2", + "test_bundle", "https://github.com/Project-MONAI/MONAI-extra-test-data/releases/download/0.8.1/test_bundle_v0.1.2.zip", {"model.pt": "27952767e2e154e3b0ee65defc5aed38", "model.ts": "97746870fe591f69ac09827175b00675"}, ]