Skip to content
Draft
Changes from all 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
24 changes: 23 additions & 1 deletion pip/flatpak-pip-generator
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Copy link
Collaborator

Choose a reason for hiding this comment

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

return type is wrong.

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
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
Copy link
Collaborator

@bbhtt bbhtt May 9, 2025

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.)
Therefore my intention was to give the users a hint that they might not get the best result or then one they are expecting. It could be rewritten to be more informational than a warning, maybe also the code cleaned up a bit. (Maybe printing all keys and values to be more useful and allow for easy manual fixing afterwards.)

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)
Expand Down Expand Up @@ -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
Expand Down