diff --git a/changelog/1191.misc.txt b/changelog/1191.misc.txt new file mode 100644 index 00000000..a9edc539 --- /dev/null +++ b/changelog/1191.misc.txt @@ -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. diff --git a/tests/test_package.py b/tests/test_package.py index be3d9540..37125741 100644 --- a/tests/test_package.py +++ b/tests/test_package.py @@ -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" diff --git a/twine/package.py b/twine/package.py index 8bcec211..2c3a8f7d 100644 --- a/twine/package.py +++ b/twine/package.py @@ -157,7 +157,6 @@ 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"] @@ -165,8 +164,11 @@ def from_filename(cls, filename: str, comment: Optional[str]) -> "PackageFile": 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