From 546d6c0e3c32d41c49f4951a4ede553b62d75ba5 Mon Sep 17 00:00:00 2001 From: KumoLiu Date: Mon, 18 Sep 2023 17:24:26 +0800 Subject: [PATCH 1/9] fix #6833 Signed-off-by: KumoLiu --- monai/bundle/scripts.py | 113 +++++++++++++++++++++++++--------- tests/test_bundle_get_data.py | 47 +++++++++++++- 2 files changed, 130 insertions(+), 30 deletions(-) diff --git a/monai/bundle/scripts.py b/monai/bundle/scripts.py index 6b34627a6a..65d58d0ad9 100644 --- a/monai/bundle/scripts.py +++ b/monai/bundle/scripts.py @@ -541,11 +541,24 @@ def load( return model +@deprecated_arg_default( + "model_info_url", + None, + "https://raw.githubusercontent.com/Project-MONAI/model-zoo/dev/models/model_info.json", + since="1.3", + replaced="1.5", +) def _get_all_bundles_info( - repo: str = "Project-MONAI/model-zoo", tag: str = "hosting_storage_v1", auth_token: str | None = None + repo: str = "Project-MONAI/model-zoo", + tag: str = "hosting_storage_v1", + auth_token: str | None = None, + model_info_url: str | None = None, ) -> dict[str, dict[str, dict[str, Any]]]: if has_requests: - request_url = f"https://api.github.com/repos/{repo}/releases" + if model_info_url is not None: + request_url = model_info_url + else: + request_url = f"https://api.github.com/repos/{repo}/releases" if auth_token is not None: headers = {"Authorization": f"Bearer {auth_token}"} resp = requests_get(request_url, headers=headers) @@ -558,33 +571,56 @@ def _get_all_bundles_info( bundle_name_pattern = re.compile(r"_v\d*.") bundles_info: dict[str, dict[str, dict[str, Any]]] = {} - for release in releases_list: - if release["tag_name"] == tag: - for asset in release["assets"]: - asset_name = bundle_name_pattern.split(asset["name"])[0] - if asset_name not in bundles_info: - bundles_info[asset_name] = {} - asset_version = asset["name"].split(f"{asset_name}_v")[-1].replace(".zip", "") - bundles_info[asset_name][asset_version] = { - "id": asset["id"], - "name": asset["name"], - "size": asset["size"], - "download_count": asset["download_count"], - "browser_download_url": asset["browser_download_url"], - "created_at": asset["created_at"], - "updated_at": asset["updated_at"], - } - return bundles_info + if model_info_url is not None: + for asset in releases_list.keys(): + asset_name = bundle_name_pattern.split(asset)[0] + if asset_name not in bundles_info: + bundles_info[asset_name] = {} + asset_version = asset.split(f"{asset_name}_v")[-1] + bundles_info[asset_name][asset_version] = { + "name": asset, + "browser_download_url": releases_list[asset]["source"], + } + return bundles_info + else: + for release in releases_list: + if release["tag_name"] == tag: + for asset in release["assets"]: + asset_name = bundle_name_pattern.split(asset["name"])[0] + if asset_name not in bundles_info: + bundles_info[asset_name] = {} + asset_version = asset["name"].split(f"{asset_name}_v")[-1].replace(".zip", "") + bundles_info[asset_name][asset_version] = { + "id": asset["id"], + "name": asset["name"], + "size": asset["size"], + "download_count": asset["download_count"], + "browser_download_url": asset["browser_download_url"], + "created_at": asset["created_at"], + "updated_at": asset["updated_at"], + } + return bundles_info return bundles_info +@deprecated_arg_default( + "model_info_url", + None, + "https://raw.githubusercontent.com/Project-MONAI/model-zoo/dev/models/model_info.json", + since="1.3", + replaced="1.5", +) def get_all_bundles_list( - repo: str = "Project-MONAI/model-zoo", tag: str = "hosting_storage_v1", auth_token: str | None = None + repo: str = "Project-MONAI/model-zoo", + tag: str = "hosting_storage_v1", + auth_token: str | None = None, + model_info_url: str | None = None, ) -> list[tuple[str, str]]: """ Get all bundles names (and the latest versions) that are stored in the release of specified repository - with the provided tag. The default values of arguments correspond to the release of MONAI model zoo. - In order to increase the rate limits of calling Github APIs, you can input your personal access token. + with the provided tag or listed in `model_info_url`. The default values of arguments correspond to the + release of MONAI model zoo. In order to increase the rate limits of calling Github APIs, you can input + your personal access token. Please check the following link for more details about rate limiting: https://docs.github.com/en/rest/overview/resources-in-the-rest-api#rate-limiting @@ -595,13 +631,14 @@ def get_all_bundles_list( repo: it should be in the form of "repo_owner/repo_name/". tag: the tag name of the release. auth_token: github personal access token. + model_info_url: a JSON file link containing all of the model information. Returns: a list of tuple in the form of (bundle name, latest version). """ - bundles_info = _get_all_bundles_info(repo=repo, tag=tag, auth_token=auth_token) + bundles_info = _get_all_bundles_info(repo=repo, tag=tag, auth_token=auth_token, model_info_url=model_info_url) bundles_list = [] for bundle_name in bundles_info: latest_version = sorted(bundles_info[bundle_name].keys())[-1] @@ -610,15 +647,23 @@ def get_all_bundles_list( return bundles_list +@deprecated_arg_default( + "model_info_url", + None, + "https://raw.githubusercontent.com/Project-MONAI/model-zoo/dev/models/model_info.json", + since="1.3", + replaced="1.5", +) def get_bundle_versions( bundle_name: str, repo: str = "Project-MONAI/model-zoo", tag: str = "hosting_storage_v1", auth_token: str | None = None, + model_info_url: str | None = None, ) -> dict[str, list[str] | str]: """ Get the latest version, as well as all existing versions of a bundle that is stored in the release of specified - repository with the provided tag. + repository with the provided tag or listed in `model_info_url`. In order to increase the rate limits of calling Github APIs, you can input your personal access token. Please check the following link for more details about rate limiting: https://docs.github.com/en/rest/overview/resources-in-the-rest-api#rate-limiting @@ -631,13 +676,14 @@ def get_bundle_versions( repo: it should be in the form of "repo_owner/repo_name/". tag: the tag name of the release. auth_token: github personal access token. + model_info_url: a JSON file link containing all of the model information. Returns: a dictionary that contains the latest version and all versions of a bundle. """ - bundles_info = _get_all_bundles_info(repo=repo, tag=tag, auth_token=auth_token) + bundles_info = _get_all_bundles_info(repo=repo, tag=tag, auth_token=auth_token, model_info_url=model_info_url) if bundle_name not in bundles_info: raise ValueError(f"bundle: {bundle_name} is not existing in repo: {repo}.") bundle_info = bundles_info[bundle_name] @@ -646,17 +692,27 @@ def get_bundle_versions( return {"latest_version": all_versions[-1], "all_versions": all_versions} +@deprecated_arg_default( + "model_info_url", + None, + "https://raw.githubusercontent.com/Project-MONAI/model-zoo/dev/models/model_info.json", + since="1.3", + replaced="1.5", +) def get_bundle_info( bundle_name: str, version: str | None = None, repo: str = "Project-MONAI/model-zoo", tag: str = "hosting_storage_v1", auth_token: str | None = None, + model_info_url: str | None = None, ) -> dict[str, Any]: """ Get all information (include "id", "name", "size", "download_count", "browser_download_url", "created_at", "updated_at") of a bundle - with the specified bundle name and version. + with the specified bundle name and version which is stored in the release of specified repository with the provided tag. + Since v1.5, it has been deprecated in favor of'model_info_url', which contains only "name" and "browser_download_url" + information about a bundle. In order to increase the rate limits of calling Github APIs, you can input your personal access token. Please check the following link for more details about rate limiting: https://docs.github.com/en/rest/overview/resources-in-the-rest-api#rate-limiting @@ -670,13 +726,14 @@ def get_bundle_info( repo: it should be in the form of "repo_owner/repo_name/". tag: the tag name of the release. auth_token: github personal access token. + model_info_url: a JSON file link containing all of the model information. Returns: a dictionary that contains the bundle's information. """ - bundles_info = _get_all_bundles_info(repo=repo, tag=tag, auth_token=auth_token) + bundles_info = _get_all_bundles_info(repo=repo, tag=tag, auth_token=auth_token, model_info_url=model_info_url) if bundle_name not in bundles_info: raise ValueError(f"bundle: {bundle_name} is not existing.") bundle_info = bundles_info[bundle_name] @@ -685,7 +742,7 @@ def get_bundle_info( if version not in bundle_info: raise ValueError(f"version: {version} of bundle: {bundle_name} is not existing.") - return bundle_info[version] + return bundle_info[version] # type: ignore[no-any-return] @deprecated_arg("runner_id", since="1.1", removed="1.3", new_name="run_id", msg_suffix="please use `run_id` instead.") diff --git a/tests/test_bundle_get_data.py b/tests/test_bundle_get_data.py index a560f3945f..f13963cdca 100644 --- a/tests/test_bundle_get_data.py +++ b/tests/test_bundle_get_data.py @@ -25,7 +25,16 @@ TEST_CASE_2 = [{"bundle_name": "spleen_ct_segmentation", "version": "0.1.0", "auth_token": None}] -TEST_CASE_FAKE_TOKEN = [{"bundle_name": "spleen_ct_segmentation", "version": "0.1.0", "auth_token": "ghp_errortoken"}] +TEST_CASE_FAKE_TOKEN_1 = [{"bundle_name": "spleen_ct_segmentation", "version": "0.1.0", "auth_token": "ghp_errortoken"}] + +TEST_CASE_FAKE_TOKEN_2 = [ + { + "bundle_name": "spleen_ct_segmentation", + "version": "0.1.0", + "auth_token": "ghp_errortoken", + "model_info_url": "https://raw.githubusercontent.com/Project-MONAI/model-zoo/dev/models/model_info.json", + } +] @skip_if_windows @@ -39,6 +48,16 @@ def test_get_all_bundles_list(self): self.assertTrue(isinstance(output[0], tuple)) self.assertTrue(len(output[0]) == 2) + @skip_if_quick + def test_get_all_bundles_list_model_info_url(self): + with skip_if_downloading_fails(): + output = get_all_bundles_list( + model_info_url="https://raw.githubusercontent.com/Project-MONAI/model-zoo/dev/models/model_info.json" + ) + self.assertTrue(isinstance(output, list)) + self.assertTrue(isinstance(output[0], tuple)) + self.assertTrue(len(output[0]) == 2) + @parameterized.expand([TEST_CASE_1]) @skip_if_quick def test_get_bundle_versions(self, params): @@ -48,6 +67,18 @@ def test_get_bundle_versions(self, params): self.assertTrue("latest_version" in output and "all_versions" in output) self.assertTrue("0.1.0" in output["all_versions"]) + @parameterized.expand([TEST_CASE_1]) + @skip_if_quick + def test_get_bundle_versions_model_info_url(self, params): + with skip_if_downloading_fails(): + output = get_bundle_versions( + model_info_url="https://raw.githubusercontent.com/Project-MONAI/model-zoo/dev/models/model_info.json", + **params, + ) + self.assertTrue(isinstance(output, dict)) + self.assertTrue("latest_version" in output and "all_versions" in output) + self.assertTrue("0.1.0" in output["all_versions"]) + @parameterized.expand([TEST_CASE_1, TEST_CASE_2]) @skip_if_quick def test_get_bundle_info(self, params): @@ -57,7 +88,19 @@ def test_get_bundle_info(self, params): for key in ["id", "name", "size", "download_count", "browser_download_url"]: self.assertTrue(key in output) - @parameterized.expand([TEST_CASE_FAKE_TOKEN]) + @parameterized.expand([TEST_CASE_1, TEST_CASE_2]) + @skip_if_quick + def test_get_bundle_info_model_info_url(self, params): + with skip_if_downloading_fails(): + output = get_bundle_info( + model_info_url="https://raw.githubusercontent.com/Project-MONAI/model-zoo/dev/models/model_info.json", + **params, + ) + self.assertTrue(isinstance(output, dict)) + for key in ["name", "browser_download_url"]: + self.assertTrue(key in output) + + @parameterized.expand([TEST_CASE_FAKE_TOKEN_1, TEST_CASE_FAKE_TOKEN_2]) @skip_if_quick def test_fake_token(self, params): with skip_if_downloading_fails(): From 1bd68e9f912655c50e3c24844013d58d618ecc7a Mon Sep 17 00:00:00 2001 From: KumoLiu Date: Mon, 18 Sep 2023 18:18:21 +0800 Subject: [PATCH 2/9] address comments Signed-off-by: KumoLiu --- monai/bundle/scripts.py | 73 ++++++++++------------------------- tests/test_bundle_get_data.py | 53 ++++++++----------------- 2 files changed, 36 insertions(+), 90 deletions(-) diff --git a/monai/bundle/scripts.py b/monai/bundle/scripts.py index 65d58d0ad9..0abb2e8b92 100644 --- a/monai/bundle/scripts.py +++ b/monai/bundle/scripts.py @@ -541,22 +541,13 @@ def load( return model -@deprecated_arg_default( - "model_info_url", - None, - "https://raw.githubusercontent.com/Project-MONAI/model-zoo/dev/models/model_info.json", - since="1.3", - replaced="1.5", -) +@deprecated_arg_default("tag", "hosting_storage_v1", "dev", since="1.3", replaced="1.5") def _get_all_bundles_info( - repo: str = "Project-MONAI/model-zoo", - tag: str = "hosting_storage_v1", - auth_token: str | None = None, - model_info_url: str | None = None, + repo: str = "Project-MONAI/model-zoo", tag: str = "hosting_storage_v1", auth_token: str | None = None ) -> dict[str, dict[str, dict[str, Any]]]: if has_requests: - if model_info_url is not None: - request_url = model_info_url + if tag == "dev": + request_url = f"https://raw.githubusercontent.com/{repo}/{tag}/models/model_info.json" else: request_url = f"https://api.github.com/repos/{repo}/releases" if auth_token is not None: @@ -571,7 +562,7 @@ def _get_all_bundles_info( bundle_name_pattern = re.compile(r"_v\d*.") bundles_info: dict[str, dict[str, dict[str, Any]]] = {} - if model_info_url is not None: + if tag == "dev": for asset in releases_list.keys(): asset_name = bundle_name_pattern.split(asset)[0] if asset_name not in bundles_info: @@ -603,24 +594,16 @@ def _get_all_bundles_info( return bundles_info -@deprecated_arg_default( - "model_info_url", - None, - "https://raw.githubusercontent.com/Project-MONAI/model-zoo/dev/models/model_info.json", - since="1.3", - replaced="1.5", -) +@deprecated_arg_default("tag", "hosting_storage_v1", "dev", since="1.3", replaced="1.5") def get_all_bundles_list( - repo: str = "Project-MONAI/model-zoo", - tag: str = "hosting_storage_v1", - auth_token: str | None = None, - model_info_url: str | None = None, + repo: str = "Project-MONAI/model-zoo", tag: str = "hosting_storage_v1", auth_token: str | None = None ) -> list[tuple[str, str]]: """ Get all bundles names (and the latest versions) that are stored in the release of specified repository - with the provided tag or listed in `model_info_url`. The default values of arguments correspond to the - release of MONAI model zoo. In order to increase the rate limits of calling Github APIs, you can input - your personal access token. + with the provided tag. If tag is "dev", will get model information from + https://raw.githubusercontent.com/repo_owner/repo_name/dev/models/model_info.json. + The default values of arguments correspond to the release of MONAI model zoo. In order to increase the + rate limits of calling Github APIs, you can input your personal access token. Please check the following link for more details about rate limiting: https://docs.github.com/en/rest/overview/resources-in-the-rest-api#rate-limiting @@ -631,14 +614,13 @@ def get_all_bundles_list( repo: it should be in the form of "repo_owner/repo_name/". tag: the tag name of the release. auth_token: github personal access token. - model_info_url: a JSON file link containing all of the model information. Returns: a list of tuple in the form of (bundle name, latest version). """ - bundles_info = _get_all_bundles_info(repo=repo, tag=tag, auth_token=auth_token, model_info_url=model_info_url) + bundles_info = _get_all_bundles_info(repo=repo, tag=tag, auth_token=auth_token) bundles_list = [] for bundle_name in bundles_info: latest_version = sorted(bundles_info[bundle_name].keys())[-1] @@ -647,23 +629,17 @@ def get_all_bundles_list( return bundles_list -@deprecated_arg_default( - "model_info_url", - None, - "https://raw.githubusercontent.com/Project-MONAI/model-zoo/dev/models/model_info.json", - since="1.3", - replaced="1.5", -) +@deprecated_arg_default("tag", "hosting_storage_v1", "dev", since="1.3", replaced="1.5") def get_bundle_versions( bundle_name: str, repo: str = "Project-MONAI/model-zoo", tag: str = "hosting_storage_v1", auth_token: str | None = None, - model_info_url: str | None = None, ) -> dict[str, list[str] | str]: """ Get the latest version, as well as all existing versions of a bundle that is stored in the release of specified - repository with the provided tag or listed in `model_info_url`. + repository with the provided tag. If tag is "dev", will get model information from + https://raw.githubusercontent.com/repo_owner/repo_name/dev/models/model_info.json. In order to increase the rate limits of calling Github APIs, you can input your personal access token. Please check the following link for more details about rate limiting: https://docs.github.com/en/rest/overview/resources-in-the-rest-api#rate-limiting @@ -676,14 +652,13 @@ def get_bundle_versions( repo: it should be in the form of "repo_owner/repo_name/". tag: the tag name of the release. auth_token: github personal access token. - model_info_url: a JSON file link containing all of the model information. Returns: a dictionary that contains the latest version and all versions of a bundle. """ - bundles_info = _get_all_bundles_info(repo=repo, tag=tag, auth_token=auth_token, model_info_url=model_info_url) + bundles_info = _get_all_bundles_info(repo=repo, tag=tag, auth_token=auth_token) if bundle_name not in bundles_info: raise ValueError(f"bundle: {bundle_name} is not existing in repo: {repo}.") bundle_info = bundles_info[bundle_name] @@ -692,26 +667,19 @@ def get_bundle_versions( return {"latest_version": all_versions[-1], "all_versions": all_versions} -@deprecated_arg_default( - "model_info_url", - None, - "https://raw.githubusercontent.com/Project-MONAI/model-zoo/dev/models/model_info.json", - since="1.3", - replaced="1.5", -) +@deprecated_arg_default("tag", "hosting_storage_v1", "dev", since="1.3", replaced="1.5") def get_bundle_info( bundle_name: str, version: str | None = None, repo: str = "Project-MONAI/model-zoo", - tag: str = "hosting_storage_v1", + tag: str | None = "hosting_storage_v1", auth_token: str | None = None, - model_info_url: str | None = None, ) -> dict[str, Any]: """ Get all information (include "id", "name", "size", "download_count", "browser_download_url", "created_at", "updated_at") of a bundle with the specified bundle name and version which is stored in the release of specified repository with the provided tag. - Since v1.5, it has been deprecated in favor of'model_info_url', which contains only "name" and "browser_download_url" + Since v1.5, "hosting_storage_v1" will be deprecated in favor of 'dev', which contains only "name" and "browser_download_url". information about a bundle. In order to increase the rate limits of calling Github APIs, you can input your personal access token. Please check the following link for more details about rate limiting: @@ -726,14 +694,13 @@ def get_bundle_info( repo: it should be in the form of "repo_owner/repo_name/". tag: the tag name of the release. auth_token: github personal access token. - model_info_url: a JSON file link containing all of the model information. Returns: a dictionary that contains the bundle's information. """ - bundles_info = _get_all_bundles_info(repo=repo, tag=tag, auth_token=auth_token, model_info_url=model_info_url) + bundles_info = _get_all_bundles_info(repo=repo, tag=tag, auth_token=auth_token) if bundle_name not in bundles_info: raise ValueError(f"bundle: {bundle_name} is not existing.") bundle_info = bundles_info[bundle_name] diff --git a/tests/test_bundle_get_data.py b/tests/test_bundle_get_data.py index f13963cdca..a2e6f642e5 100644 --- a/tests/test_bundle_get_data.py +++ b/tests/test_bundle_get_data.py @@ -25,40 +25,34 @@ TEST_CASE_2 = [{"bundle_name": "spleen_ct_segmentation", "version": "0.1.0", "auth_token": None}] +TEST_CASE_3 = [{"tag": "hosting_storage_v1"}] + +TEST_CASE_4 = [{"tag": "dev"}] + +TEST_CASE_5 = [{"bundle_name": "brats_mri_segmentation", "tag": "dev"}] + +TEST_CASE_6 = [{"bundle_name": "spleen_ct_segmentation", "version": "0.1.0", "auth_token": None, "tag": "dev"}] + TEST_CASE_FAKE_TOKEN_1 = [{"bundle_name": "spleen_ct_segmentation", "version": "0.1.0", "auth_token": "ghp_errortoken"}] TEST_CASE_FAKE_TOKEN_2 = [ - { - "bundle_name": "spleen_ct_segmentation", - "version": "0.1.0", - "auth_token": "ghp_errortoken", - "model_info_url": "https://raw.githubusercontent.com/Project-MONAI/model-zoo/dev/models/model_info.json", - } + {"bundle_name": "spleen_ct_segmentation", "version": "0.1.0", "auth_token": "ghp_errortoken", "tag": "dev"} ] @skip_if_windows @SkipIfNoModule("requests") class TestGetBundleData(unittest.TestCase): + @parameterized.expand([TEST_CASE_3, TEST_CASE_4]) @skip_if_quick - def test_get_all_bundles_list(self): - with skip_if_downloading_fails(): - output = get_all_bundles_list() - self.assertTrue(isinstance(output, list)) - self.assertTrue(isinstance(output[0], tuple)) - self.assertTrue(len(output[0]) == 2) - - @skip_if_quick - def test_get_all_bundles_list_model_info_url(self): + def test_get_all_bundles_list(self, params): with skip_if_downloading_fails(): - output = get_all_bundles_list( - model_info_url="https://raw.githubusercontent.com/Project-MONAI/model-zoo/dev/models/model_info.json" - ) + output = get_all_bundles_list(**params) self.assertTrue(isinstance(output, list)) self.assertTrue(isinstance(output[0], tuple)) self.assertTrue(len(output[0]) == 2) - @parameterized.expand([TEST_CASE_1]) + @parameterized.expand([TEST_CASE_1, TEST_CASE_5]) @skip_if_quick def test_get_bundle_versions(self, params): with skip_if_downloading_fails(): @@ -67,18 +61,6 @@ def test_get_bundle_versions(self, params): self.assertTrue("latest_version" in output and "all_versions" in output) self.assertTrue("0.1.0" in output["all_versions"]) - @parameterized.expand([TEST_CASE_1]) - @skip_if_quick - def test_get_bundle_versions_model_info_url(self, params): - with skip_if_downloading_fails(): - output = get_bundle_versions( - model_info_url="https://raw.githubusercontent.com/Project-MONAI/model-zoo/dev/models/model_info.json", - **params, - ) - self.assertTrue(isinstance(output, dict)) - self.assertTrue("latest_version" in output and "all_versions" in output) - self.assertTrue("0.1.0" in output["all_versions"]) - @parameterized.expand([TEST_CASE_1, TEST_CASE_2]) @skip_if_quick def test_get_bundle_info(self, params): @@ -88,14 +70,11 @@ def test_get_bundle_info(self, params): for key in ["id", "name", "size", "download_count", "browser_download_url"]: self.assertTrue(key in output) - @parameterized.expand([TEST_CASE_1, TEST_CASE_2]) + @parameterized.expand([TEST_CASE_5, TEST_CASE_6]) @skip_if_quick - def test_get_bundle_info_model_info_url(self, params): + def test_get_bundle_info_monaihosting(self, params): with skip_if_downloading_fails(): - output = get_bundle_info( - model_info_url="https://raw.githubusercontent.com/Project-MONAI/model-zoo/dev/models/model_info.json", - **params, - ) + output = get_bundle_info(**params) self.assertTrue(isinstance(output, dict)) for key in ["name", "browser_download_url"]: self.assertTrue(key in output) From e269b48eb2d074551db19322ca41c8d7caccc565 Mon Sep 17 00:00:00 2001 From: KumoLiu Date: Mon, 18 Sep 2023 18:20:09 +0800 Subject: [PATCH 3/9] minor fix Signed-off-by: KumoLiu --- monai/bundle/scripts.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/monai/bundle/scripts.py b/monai/bundle/scripts.py index 0abb2e8b92..e2fcce5cde 100644 --- a/monai/bundle/scripts.py +++ b/monai/bundle/scripts.py @@ -672,7 +672,7 @@ def get_bundle_info( bundle_name: str, version: str | None = None, repo: str = "Project-MONAI/model-zoo", - tag: str | None = "hosting_storage_v1", + tag: str = "hosting_storage_v1", auth_token: str | None = None, ) -> dict[str, Any]: """ From e0108a2f4fcf4f2c0194dd9d822299018dc9970c Mon Sep 17 00:00:00 2001 From: YunLiu <55491388+KumoLiu@users.noreply.github.com> Date: Mon, 18 Sep 2023 20:33:14 +0800 Subject: [PATCH 4/9] Update monai/bundle/scripts.py Co-authored-by: Wenqi Li <831580+wyli@users.noreply.github.com> Signed-off-by: YunLiu <55491388+KumoLiu@users.noreply.github.com> --- monai/bundle/scripts.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/monai/bundle/scripts.py b/monai/bundle/scripts.py index e2fcce5cde..cee7b20289 100644 --- a/monai/bundle/scripts.py +++ b/monai/bundle/scripts.py @@ -541,7 +541,7 @@ def load( return model -@deprecated_arg_default("tag", "hosting_storage_v1", "dev", since="1.3", replaced="1.5") +@deprecated_arg_default("tag", "hosting_storage_v1", "dev", since="1.2", replaced="1.5") def _get_all_bundles_info( repo: str = "Project-MONAI/model-zoo", tag: str = "hosting_storage_v1", auth_token: str | None = None ) -> dict[str, dict[str, dict[str, Any]]]: From 5541216059f429e59dea7eeacb286dc9611c2285 Mon Sep 17 00:00:00 2001 From: YunLiu <55491388+KumoLiu@users.noreply.github.com> Date: Mon, 18 Sep 2023 20:36:10 +0800 Subject: [PATCH 5/9] Update monai/bundle/scripts.py Co-authored-by: Eric Kerfoot <17726042+ericspod@users.noreply.github.com> Signed-off-by: YunLiu <55491388+KumoLiu@users.noreply.github.com> --- monai/bundle/scripts.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/monai/bundle/scripts.py b/monai/bundle/scripts.py index cee7b20289..b2aa24f017 100644 --- a/monai/bundle/scripts.py +++ b/monai/bundle/scripts.py @@ -546,10 +546,11 @@ def _get_all_bundles_info( repo: str = "Project-MONAI/model-zoo", tag: str = "hosting_storage_v1", auth_token: str | None = None ) -> dict[str, dict[str, dict[str, Any]]]: if has_requests: - if tag == "dev": - request_url = f"https://raw.githubusercontent.com/{repo}/{tag}/models/model_info.json" - else: + if tag == "hosting_storage_v1": request_url = f"https://api.github.com/repos/{repo}/releases" + else: + request_url = f"https://raw.githubusercontent.com/{repo}/{tag}/models/model_info.json" + if auth_token is not None: headers = {"Authorization": f"Bearer {auth_token}"} resp = requests_get(request_url, headers=headers) From 5ec1187d5da60abddcf573b12a9f398115b66cc3 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 18 Sep 2023 12:37:11 +0000 Subject: [PATCH 6/9] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- monai/bundle/scripts.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/monai/bundle/scripts.py b/monai/bundle/scripts.py index b2aa24f017..6aaf91e62a 100644 --- a/monai/bundle/scripts.py +++ b/monai/bundle/scripts.py @@ -550,7 +550,7 @@ def _get_all_bundles_info( request_url = f"https://api.github.com/repos/{repo}/releases" else: request_url = f"https://raw.githubusercontent.com/{repo}/{tag}/models/model_info.json" - + if auth_token is not None: headers = {"Authorization": f"Bearer {auth_token}"} resp = requests_get(request_url, headers=headers) From e3dcce8b463a80493a7aa3ea452f88b7e383ed9a Mon Sep 17 00:00:00 2001 From: KumoLiu Date: Mon, 18 Sep 2023 20:38:31 +0800 Subject: [PATCH 7/9] address comments Signed-off-by: KumoLiu --- monai/bundle/scripts.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/monai/bundle/scripts.py b/monai/bundle/scripts.py index b2aa24f017..0a603097c0 100644 --- a/monai/bundle/scripts.py +++ b/monai/bundle/scripts.py @@ -563,18 +563,7 @@ def _get_all_bundles_info( bundle_name_pattern = re.compile(r"_v\d*.") bundles_info: dict[str, dict[str, dict[str, Any]]] = {} - if tag == "dev": - for asset in releases_list.keys(): - asset_name = bundle_name_pattern.split(asset)[0] - if asset_name not in bundles_info: - bundles_info[asset_name] = {} - asset_version = asset.split(f"{asset_name}_v")[-1] - bundles_info[asset_name][asset_version] = { - "name": asset, - "browser_download_url": releases_list[asset]["source"], - } - return bundles_info - else: + if tag == "hosting_storage_v1": for release in releases_list: if release["tag_name"] == tag: for asset in release["assets"]: @@ -592,6 +581,17 @@ def _get_all_bundles_info( "updated_at": asset["updated_at"], } return bundles_info + else: + for asset in releases_list.keys(): + asset_name = bundle_name_pattern.split(asset)[0] + if asset_name not in bundles_info: + bundles_info[asset_name] = {} + asset_version = asset.split(f"{asset_name}_v")[-1] + bundles_info[asset_name][asset_version] = { + "name": asset, + "browser_download_url": releases_list[asset]["source"], + } + return bundles_info return bundles_info From b65f19927b634fdb73fa6920692a7d838e4f1f70 Mon Sep 17 00:00:00 2001 From: KumoLiu Date: Mon, 18 Sep 2023 20:44:48 +0800 Subject: [PATCH 8/9] address comments Signed-off-by: KumoLiu --- monai/bundle/scripts.py | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/monai/bundle/scripts.py b/monai/bundle/scripts.py index 9b016a1310..bfdd963126 100644 --- a/monai/bundle/scripts.py +++ b/monai/bundle/scripts.py @@ -571,15 +571,7 @@ def _get_all_bundles_info( if asset_name not in bundles_info: bundles_info[asset_name] = {} asset_version = asset["name"].split(f"{asset_name}_v")[-1].replace(".zip", "") - bundles_info[asset_name][asset_version] = { - "id": asset["id"], - "name": asset["name"], - "size": asset["size"], - "download_count": asset["download_count"], - "browser_download_url": asset["browser_download_url"], - "created_at": asset["created_at"], - "updated_at": asset["updated_at"], - } + bundles_info[asset_name][asset_version] = dict(asset) return bundles_info else: for asset in releases_list.keys(): From 250e4c015b60f0954a4ef4b5ce2710620de273ce Mon Sep 17 00:00:00 2001 From: KumoLiu Date: Mon, 18 Sep 2023 21:26:14 +0800 Subject: [PATCH 9/9] address comments Signed-off-by: KumoLiu --- monai/bundle/scripts.py | 1 - 1 file changed, 1 deletion(-) diff --git a/monai/bundle/scripts.py b/monai/bundle/scripts.py index bfdd963126..711f585159 100644 --- a/monai/bundle/scripts.py +++ b/monai/bundle/scripts.py @@ -583,7 +583,6 @@ def _get_all_bundles_info( "name": asset, "browser_download_url": releases_list[asset]["source"], } - return bundles_info return bundles_info