-
Notifications
You must be signed in to change notification settings - Fork 121
pip: Add changelog links from pypi to checker data #440
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,6 +78,24 @@ def get_pypi_url(name: str, filename: str) -> str: | |
return source['url'] | ||
raise Exception('Failed to extract url from {}'.format(url)) | ||
|
||
def get_pypi_changelog(name: str) -> str: | ||
url = 'https://pypi.org/pypi/{}/json'.format(name) | ||
with urllib.request.urlopen(url) as response: | ||
body = json.loads(response.read().decode('utf-8')) | ||
urls = {k.casefold(): v for k, v in body['info']['project_urls'].items()} | ||
# Keys as recognized by pypi: | ||
# https://github.com/pypi/warehouse/blob/main/warehouse/templates/packaging/detail.html#L24 | ||
bbhtt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
search_keys = {"changelog", "change log", "changes", "release notes", "news", "what's new", "history"} | ||
keys = search_keys.intersection(urls.keys()) | ||
if len(keys) == 1: | ||
return urls[keys.pop()] | ||
elif len(keys) > 1: | ||
print(f"Warning: Got multiple potential keys for the changelog, picking one at random from {keys}.") | ||
return urls[keys.pop()] | ||
Comment on lines
+90
to
+94
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd just combine these two cases and pick the first one always. If it's wrong it needs to be manually edited anyways and the warning doesn't particularly mean that it was wrong either. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't have any data on how many projects might have values for more than one of those keys or if the keys may actually have different semantic meanings. (In some projects on Github I definitely saw differences in changlog and release notes.) But if you think it is really unnecessary and want the code as short as possible I'm happy to remove it. |
||
else: | ||
print(f"No changelog url found for '{name}'.") | ||
|
||
|
||
|
||
def get_tar_package_url_pypi(name: str, version: str) -> str: | ||
url = 'https://pypi.org/pypi/{}/{}/json'.format(name, version) | ||
|
@@ -354,14 +372,18 @@ with tempfile.TemporaryDirectory(prefix=tempdir_prefix) as tempdir: | |
name = name.casefold() | ||
is_pypi = True | ||
url = get_pypi_url(name, filename) | ||
changelog = get_pypi_changelog(name) | ||
source = OrderedDict([ | ||
('type', 'file'), | ||
('url', url), | ||
('sha256', sha256)]) | ||
if opts.checker_data: | ||
source['x-checker-data'] = { | ||
'type': 'pypi', | ||
'name': name} | ||
'name': name, | ||
} | ||
if changelog: | ||
source['x-checker-data']['changelog-url-template'] = changelog | ||
if url.endswith(".whl"): | ||
source['x-checker-data']['packagetype'] = 'bdist_wheel' | ||
is_vcs = False | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return type is wrong.