python-poetry/poetry · error · ValueError

Unknown distribution format {exts}

Error message

Unknown distribution format {exts}

What it means

Raised by Uploader._get_type() (a staticmethod) when the file's suffixes are neither a trailing .whl nor a trailing .tar.gz. _get_type classifies an archive as bdist_wheel or sdist; anything else is rejected before metadata extraction. Used to filter/gate which files can be uploaded.

Source

Thrown at src/poetry/publishing/uploader.py:337

        data_to_send = []
        for key, value in data.items():
            if not isinstance(value, (list, tuple)):
                data_to_send.append((key, value))
            else:
                for item in value:
                    data_to_send.append((key, item))

        return data_to_send

    @staticmethod
    def _get_type(file: Path) -> Literal["bdist_wheel", "sdist"]:
        exts = file.suffixes
        if exts and exts[-1] == ".whl":
            return "bdist_wheel"
        elif len(exts) >= 2 and "".join(exts[-2:]) == ".tar.gz":
            return "sdist"

        raise ValueError("Unknown distribution format " + "".join(exts))

    @staticmethod
    def _get_metadata(file: Path) -> RawMetadata:
        if file.suffix == ".whl":
            with zipfile.ZipFile(file) as z:
                for name in z.namelist():
                    parts = Path(name).parts
                    if (
                        len(parts) == 2
                        and parts[1] == "METADATA"
                        and parts[0].endswith(".dist-info")
                    ):
                        with z.open(name) as mf:
                            return parse_email(mf.read().decode("utf-8"))[0]
            raise FileNotFoundError("METADATA not found in wheel")

        elif file.suffixes[-2:] == [".tar", ".gz"]:
            with tarfile.open(file, "r:gz") as tar:

View on GitHub (pinned to 92b74dcfe3)

Solutions

  1. Build standard formats only: `poetry build` produces .whl and .tar.gz.
  2. Remove or exclude non-standard files from the upload set (e.g. delete stray .zip/.egg in dist/).
  3. If you genuinely need .tar.bz2 or .zip, rebuild as wheel/sdist instead.
  4. Inspect dist/ before publishing to confirm only .whl and .tar.gz are present.

Example fix

// before: stray .zip in dist/
$ ls dist/
mypkg-1.0.0-py3-none-any.whl  mypkg-1.0.0.zip
ValueError: Unknown distribution format .zip

// after
$ rm dist/mypkg-1.0.0.zip
$ poetry publish
Defensive patterns

Strategy: validation

Validate before calling

from pathlib import Path

def is_supported_archive(path: Path) -> bool:
    suffixes = path.suffixes
    return (suffixes and suffixes[-1] == ".whl") or (
        len(suffixes) >= 2 and "".join(suffixes[-2:]) == ".tar.gz"
    )

Prevention

When it happens

Trigger: Uploader is handed a file whose extension is not .whl or .tar.gz — e.g. .zip, .tar.bz2, .egg, .exe, or a file with no recognised archive suffix. _get_type runs during upload preparation.

Common situations: An old .egg or .zip left in dist/; a build backend that emits non-standard formats; a glob that picked up a README or metadata file; a typo'd filename.

Related errors


AI-assisted analysis of python-poetry/poetry@92b74dcfe3 (2026-08-04). Data as JSON: /data/errors/5477749bbe58c8af.json. Report an issue: GitHub.