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 "source" as python-version for sdist uploads #1191

Merged
merged 1 commit into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions changelog/1191.misc.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- Use ``"source"`` instead of ``None`` as ``pyversion`` for ``sdist``
uploads. This is what PyPI (and most likely other package indexes)
expects.
6 changes: 6 additions & 0 deletions tests/test_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,3 +466,9 @@ def test_malformed_from_file(monkeypatch):
def test_package_from_egg():
filename = "tests/fixtures/twine-3.3.0-py3.9.egg"
package_file.PackageFile.from_filename(filename, comment=None)


def test_package_from_sdist():
filename = "tests/fixtures/twine-1.5.0.tar.gz"
p = package_file.PackageFile.from_filename(filename, comment=None)
assert p.python_version == "source"
6 changes: 4 additions & 2 deletions twine/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,16 +157,18 @@ def from_filename(cls, filename: str, comment: Optional[str]) -> "PackageFile":
)
raise exceptions.InvalidDistribution(msg)

py_version: Optional[str]
if dtype == "bdist_egg":
(dist,) = importlib_metadata.Distribution.discover(path=[filename])
py_version = dist.metadata["Version"]
elif dtype == "bdist_wheel":
py_version = cast(wheel.Wheel, meta).py_version
elif dtype == "bdist_wininst":
py_version = cast(wininst.WinInst, meta).py_version
elif dtype == "sdist":
py_version = "source"
else:
py_version = None
# This should not be reached.
raise ValueError

return cls(
filename, comment, cast(CheckedDistribution, meta), py_version, dtype
Expand Down
Loading