From cf531eab7f72732e4ad9246da849b1f780487c2f Mon Sep 17 00:00:00 2001 From: lgan-czi Date: Tue, 12 Jul 2022 09:45:01 -0700 Subject: [PATCH 1/3] removed version from get_plugin_pypi_metadata --- backend/api/model.py | 2 +- backend/preview/preview.py | 2 +- backend/utils/pypi.py | 7 ++----- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/backend/api/model.py b/backend/api/model.py index f6545b6dd..c53cc59e4 100644 --- a/backend/api/model.py +++ b/backend/api/model.py @@ -148,7 +148,7 @@ def build_plugin_metadata(plugin: str, version: str) -> Tuple[str, dict]: cached_plugin = get_cache(f'cache/{plugin}/{version}.json') if cached_plugin: return plugin, cached_plugin - metadata = get_plugin_pypi_metadata(plugin, version) + metadata = get_plugin_pypi_metadata(plugin) github_repo_url = metadata.get('code_repository') if github_repo_url: metadata = {**metadata, **get_github_metadata(github_repo_url)} diff --git a/backend/preview/preview.py b/backend/preview/preview.py index 94887271b..8ca28c58b 100644 --- a/backend/preview/preview.py +++ b/backend/preview/preview.py @@ -243,7 +243,7 @@ def get_pypi_date_meta(meta): first_released = None if name: # don't pass in version in case package version is later than released version - pypi_info = get_plugin_pypi_metadata(name, version=None) + pypi_info = get_plugin_pypi_metadata(name) # plugin has already been released to PyPI if pypi_info: pypi_version = pypi_info['version'] diff --git a/backend/utils/pypi.py b/backend/utils/pypi.py index f4ddd6962..9282c131b 100644 --- a/backend/utils/pypi.py +++ b/backend/utils/pypi.py @@ -40,7 +40,7 @@ def query_pypi() -> Dict[str, str]: return packages -def get_plugin_pypi_metadata(plugin: str, version: str) -> dict: +def get_plugin_pypi_metadata(plugin: str) -> dict: """ Get plugin metadata through pypi API. @@ -48,10 +48,7 @@ def get_plugin_pypi_metadata(plugin: str, version: str) -> dict: :param version: version of the plugin :return: metadata dict for the plugin, empty if not found """ - if version: - url = f"https://pypi.org/pypi/{plugin}/{version}/json" - else: - url = f"https://pypi.org/pypi/{plugin}/json" + url = f"https://pypi.org/pypi/{plugin}/json" try: response = requests.get(url) From 0d1abde778e25a6d6aea2a4e494d7ae4ecb94746 Mon Sep 17 00:00:00 2001 From: lgan-czi Date: Tue, 12 Jul 2022 11:25:05 -0700 Subject: [PATCH 2/3] fixed errors with unit tests --- backend/api/_tests/test_pypi.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/api/_tests/test_pypi.py b/backend/api/_tests/test_pypi.py index a9c43fd24..25edb7f85 100644 --- a/backend/api/_tests/test_pypi.py +++ b/backend/api/_tests/test_pypi.py @@ -22,7 +22,7 @@ def test_query_pypi(self, mock_get): 'requests.get', return_value=FakeResponse(data=plugin) ) def test_get_plugin_pypi_metadata(self, mock_request_get): - result = get_plugin_pypi_metadata("test", "0.0.1") + result = get_plugin_pypi_metadata("test") assert (result["name"] == "test") assert (result["summary"] == "A test plugin") assert (result["description"] == "# description [example](http://example.com)") @@ -46,4 +46,4 @@ def test_get_plugin_pypi_metadata(self, mock_request_get): 'requests.get', side_effect=HTTPError() ) def test_get_plugin_error(self, mock_get): - assert ({} == get_plugin_pypi_metadata("test", "0.0.1")) + assert ({} == get_plugin_pypi_metadata("test")) From 6319f332686db0f2607bcca1b9f2ec6d12701fa9 Mon Sep 17 00:00:00 2001 From: lgan-czi Date: Tue, 12 Jul 2022 11:29:26 -0700 Subject: [PATCH 3/3] switched to setting version to none --- backend/api/_tests/test_pypi.py | 4 ++-- backend/api/model.py | 2 +- backend/preview/preview.py | 2 +- backend/utils/pypi.py | 7 +++++-- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/backend/api/_tests/test_pypi.py b/backend/api/_tests/test_pypi.py index 25edb7f85..a9c43fd24 100644 --- a/backend/api/_tests/test_pypi.py +++ b/backend/api/_tests/test_pypi.py @@ -22,7 +22,7 @@ def test_query_pypi(self, mock_get): 'requests.get', return_value=FakeResponse(data=plugin) ) def test_get_plugin_pypi_metadata(self, mock_request_get): - result = get_plugin_pypi_metadata("test") + result = get_plugin_pypi_metadata("test", "0.0.1") assert (result["name"] == "test") assert (result["summary"] == "A test plugin") assert (result["description"] == "# description [example](http://example.com)") @@ -46,4 +46,4 @@ def test_get_plugin_pypi_metadata(self, mock_request_get): 'requests.get', side_effect=HTTPError() ) def test_get_plugin_error(self, mock_get): - assert ({} == get_plugin_pypi_metadata("test")) + assert ({} == get_plugin_pypi_metadata("test", "0.0.1")) diff --git a/backend/api/model.py b/backend/api/model.py index c53cc59e4..f8b2ed5db 100644 --- a/backend/api/model.py +++ b/backend/api/model.py @@ -148,7 +148,7 @@ def build_plugin_metadata(plugin: str, version: str) -> Tuple[str, dict]: cached_plugin = get_cache(f'cache/{plugin}/{version}.json') if cached_plugin: return plugin, cached_plugin - metadata = get_plugin_pypi_metadata(plugin) + metadata = get_plugin_pypi_metadata(plugin, version=None) github_repo_url = metadata.get('code_repository') if github_repo_url: metadata = {**metadata, **get_github_metadata(github_repo_url)} diff --git a/backend/preview/preview.py b/backend/preview/preview.py index 8ca28c58b..94887271b 100644 --- a/backend/preview/preview.py +++ b/backend/preview/preview.py @@ -243,7 +243,7 @@ def get_pypi_date_meta(meta): first_released = None if name: # don't pass in version in case package version is later than released version - pypi_info = get_plugin_pypi_metadata(name) + pypi_info = get_plugin_pypi_metadata(name, version=None) # plugin has already been released to PyPI if pypi_info: pypi_version = pypi_info['version'] diff --git a/backend/utils/pypi.py b/backend/utils/pypi.py index 9282c131b..f4ddd6962 100644 --- a/backend/utils/pypi.py +++ b/backend/utils/pypi.py @@ -40,7 +40,7 @@ def query_pypi() -> Dict[str, str]: return packages -def get_plugin_pypi_metadata(plugin: str) -> dict: +def get_plugin_pypi_metadata(plugin: str, version: str) -> dict: """ Get plugin metadata through pypi API. @@ -48,7 +48,10 @@ def get_plugin_pypi_metadata(plugin: str) -> dict: :param version: version of the plugin :return: metadata dict for the plugin, empty if not found """ - url = f"https://pypi.org/pypi/{plugin}/json" + if version: + url = f"https://pypi.org/pypi/{plugin}/{version}/json" + else: + url = f"https://pypi.org/pypi/{plugin}/json" try: response = requests.get(url)