Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed pypi scraping issue causing issue #598 #605

Merged
merged 3 commits into from
Jul 12, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion backend/api/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is minor, but is there a reason not to pass version = None here and not make any of the following changes? (It could be nice to support versions depending on what we decide for follow-up work, but it'd be easy to put back so it's definitely a minor design decision for now).

Copy link
Contributor Author

@lgan-czi lgan-czi Jul 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah, that would work too, and it's probably a better way to do this to minimize side effects.

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)}
Expand Down
2 changes: 1 addition & 1 deletion backend/preview/preview.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
7 changes: 2 additions & 5 deletions backend/utils/pypi.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,15 @@ 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.

:param plugin: name of the plugin
: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)
Expand Down