pypa / twine

Utilities for interacting with PyPI
https://twine.readthedocs.io/
Apache License 2.0
1.59k stars 305 forks source link

Rely on .get for possibly undefined metadata. #1124

Closed jaraco closed 2 months ago

jaraco commented 2 months ago

Closes #977

JohnVillalovos commented 2 months ago

Would it make sense to put the data that is being requested into the pyproject.toml file?

henryiii commented 2 months ago

This is a deprecated field, so no. Project URLs has replaced home-page; home-page should not be required! (And you can't put it into a pyproject.toml file, it's not part of PEP 621)

JohnVillalovos commented 2 months ago

This is a deprecated field, so no. Project URLs has replaced home-page; home-page should not be required! (And you can't put it into a pyproject.toml file, it's not part of PEP 621)

So looks like can do: metadata["Project-URL"]

jaraco commented 2 months ago

Tests are failing for other reasons. I'm merging this to get the fix out ASAP.

JohnVillalovos commented 2 months ago

Tests are failing for other reasons. I'm merging this to get the fix out ASAP.

Should use get with a default value of an empty string. The type checking CI is failing due to that.

jaraco commented 2 months ago

This repo is secure, so nothing I can do but wait for other maintainers to come by. @sigmavirus24 or @bhrutledge Can you merge and cut a release?

henryiii commented 2 months ago

This is the wrong solution. This is on twine itself, so the metadata shouldn't ever be undefined. Instead, it should pull the correct metadata (from URLs) for this entry.

henryiii commented 2 months ago

I think it's metadata["Project-URL"]["Homepage"]

jaraco commented 2 months ago

This is the wrong solution. This is on twine itself, so the metadata shouldn't ever be undefined. Instead, it should pull the correct metadata (from URLs) for this entry.

I also believe it's the wrong solution and my recommendation would be to remove this boilerplate and let users call importlib metadata themselves. However, this PR aims to address narrowly the deprecation warning and emergent failure without making other changes to the logic.

jaraco commented 2 months ago

I think it's metadata["Project-URL"]["Homepage"]

importlib metadata doesn't provide a high-level interface for the metadata, so it's going to require something like this to get the URL.

JohnVillalovos commented 2 months ago

I think it's metadata["Project-URL"]["Homepage"]

Sadly no ☹️

But can do: metadata.get_all("Project-URL") which gets a list, containing sort of comma-separated values.

[
"Homepage, https://twine.readthedocs.io/", 
"Source, https://github.com/pypa/twine/",
...
]
JohnVillalovos commented 2 months ago

The easiest fix would be to just hard-code the value until a more elegant fix can happen. IMHO.

JohnVillalovos commented 2 months ago

The easiest fix would be to just hard-code the value until a more elegant fix can happen. IMHO.

I did that in: https://github.com/pypa/twine/pull/1127

jaraco commented 2 months ago

We're preferring the first submission in #1115 to this approach.