diff --git a/changelog/1195.removal.txt b/changelog/1195.removal.txt new file mode 100644 index 00000000..88dbe6bc --- /dev/null +++ b/changelog/1195.removal.txt @@ -0,0 +1,2 @@ +- Remove support for ``egg`` and ``wininst` distribution types. These are not + accepted by PyPI and not produced by any modern build-backeds. diff --git a/docs/internal/twine.rst b/docs/internal/twine.rst index 43265de8..a2ba3950 100644 --- a/docs/internal/twine.rst +++ b/docs/internal/twine.rst @@ -15,4 +15,3 @@ twine package twine.settings twine.utils twine.wheel - twine.wininst diff --git a/docs/internal/twine.wininst.rst b/docs/internal/twine.wininst.rst deleted file mode 100644 index 68da6723..00000000 --- a/docs/internal/twine.wininst.rst +++ /dev/null @@ -1,4 +0,0 @@ -twine.wininst module -==================== - -.. automodule:: twine.wininst diff --git a/tests/fixtures/twine-3.3.0-py3.9.egg b/tests/fixtures/twine-3.3.0-py3.9.egg deleted file mode 100644 index d0088a5e..00000000 Binary files a/tests/fixtures/twine-3.3.0-py3.9.egg and /dev/null differ diff --git a/tests/test_package.py b/tests/test_package.py index 37125741..61f4b1d2 100644 --- a/tests/test_package.py +++ b/tests/test_package.py @@ -463,12 +463,14 @@ def test_malformed_from_file(monkeypatch): assert "Invalid distribution file" in err.value.args[0] -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" + + +def test_package_from_unrecognized_file_error(): + filename = "twine/package.py" + with pytest.raises(exceptions.InvalidDistribution) as err: + package_file.PackageFile.from_filename(filename, comment=None) + assert "Unknown distribution format" in err.value.args[0] diff --git a/twine/package.py b/twine/package.py index 2c3a8f7d..3705e2d8 100644 --- a/twine/package.py +++ b/twine/package.py @@ -44,19 +44,14 @@ from twine import exceptions from twine import wheel -from twine import wininst DIST_TYPES = { - "bdist_wheel": wheel.Wheel, - "bdist_wininst": wininst.WinInst, - "bdist_egg": pkginfo.BDist, + "wheel": wheel.Wheel, "sdist": pkginfo.SDist, } DIST_EXTENSIONS = { - ".whl": "bdist_wheel", - ".exe": "bdist_wininst", - ".egg": "bdist_egg", + ".whl": "wheel", ".tar.bz2": "sdist", ".tar.gz": "sdist", ".zip": "sdist", @@ -157,13 +152,8 @@ def from_filename(cls, filename: str, comment: Optional[str]) -> "PackageFile": ) raise exceptions.InvalidDistribution(msg) - if dtype == "bdist_egg": - (dist,) = importlib_metadata.Distribution.discover(path=[filename]) - py_version = dist.metadata["Version"] - elif dtype == "bdist_wheel": + if dtype == "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: diff --git a/twine/wininst.py b/twine/wininst.py deleted file mode 100644 index 42f0d9be..00000000 --- a/twine/wininst.py +++ /dev/null @@ -1,59 +0,0 @@ -import os -import re -import zipfile -from typing import Optional - -from pkginfo import distribution - -from twine import exceptions - -wininst_file_re = re.compile(r".*py(?P\d+\.\d+)\.exe$") - - -class WinInst(distribution.Distribution): - def __init__(self, filename: str, metadata_version: Optional[str] = None) -> None: - self.filename = filename - self.metadata_version = metadata_version - self.extractMetadata() - - @property - def py_version(self) -> str: - m = wininst_file_re.match(self.filename) - if m is None: - return "any" - else: - return m.group("pyver") - - def read(self) -> bytes: - fqn = os.path.abspath(os.path.normpath(self.filename)) - if not os.path.exists(fqn): - raise exceptions.InvalidDistribution("No such file: %s" % fqn) - - if fqn.endswith(".exe"): - archive = zipfile.ZipFile(fqn) - names = archive.namelist() - - def read_file(name: str) -> bytes: - return archive.read(name) - - else: - raise exceptions.InvalidDistribution( - "Not a known archive format for file: %s" % fqn - ) - - try: - tuples = [ - x.split("/") for x in names if x.endswith((".egg-info", "PKG-INFO")) - ] - schwarz = sorted((len(x), x) for x in tuples) - for path in [x[1] for x in schwarz]: - candidate = "/".join(path) - data = read_file(candidate) - if b"Metadata-Version" in data: - return data - finally: - archive.close() - - raise exceptions.InvalidDistribution( - "No PKG-INFO/.egg-info in archive: %s" % fqn - )