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

Use {{ name }} in filename too #460

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Changes from 2 commits
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
7 changes: 6 additions & 1 deletion grayskull/strategy/pypi.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,13 @@ def get_url_filename(metadata: dict, default: Optional[str] = None) -> str:

for pkg_url in metadata["urls"]:
if pkg_url["packagetype"] == "sdist":
name = metadata["info"]["name"]
Copy link
Member Author

Choose a reason for hiding this comment

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

AFAICT metadata is gotten by requesting JSON for a package on PyPI like so...

import json
import requests


name = "dask-cuda"

req = requests.get(f"https://pypi.org/pypi/{name}/json")
metadata = json.loads(req.content)

assert metadata["info"]["name"] == name

This appears valid when looking at dask-cuda on PyPI

Am I missing something?

Choose a reason for hiding this comment

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

It looks like the fixture might be incomplete? (log)

metadata = {'info': {'version': '1.2.3'}, 'urls': [{'filename': 'foo_file-1.2.3.zip', 'packagetype': 'sdist'}]}

Choose a reason for hiding this comment

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

I have often wished the upstream Warehouse data model was captured somewhere other than in the code for warehouse (e.g. an OpenAPI spec, some TypedDicts, really anything...)

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah good catch! Thanks Nick 🙏

Wasn't thinking about fixtures for some reason 🤦‍♂️

Yeah was really hoping I could find some docs describing this somewhere, but was unable 😞

Copy link

@bollwyvl bollwyvl Apr 11, 2023

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

as far as I remember, pypi converts the _ to -, but it does not work for all
packages that were initially specified as having the _ will just work with it. pypi api is a bit confusing

version = metadata["info"]["version"]
return pkg_url["filename"].replace(version, "{{ version }}")
return (
pkg_url["filename"]
.replace(name, "{{ name }}")
.replace(version, "{{ version }}")
)
return default


Expand Down