Skip to content
Open
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
9 changes: 8 additions & 1 deletion src/poetry/installation/chef.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,14 @@ def _prepare_sdist(
if len(elements) == 1 and elements[0].is_dir():
sdist_dir = elements[0]
else:
sdist_dir = archive_dir / archive.name.rstrip(suffix)
# Remove known archive suffixes properly — rstrip treats
# its argument as a character set, not a suffix string.
stem = archive.name
for ext in (".tar.gz", ".tar.bz2", ".tar.xz", ".tar", ".zip"):
Comment on lines +113 to +114
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Consider handling additional common archive suffixes or deriving them more generically.

This implementation only accounts for a small, fixed set of suffixes and misses common variants like .tgz or .tbz2. You could either expand the list of handled extensions or use Path(archive.name).suffixes to strip multi-part suffixes more generically (e.g., remove all trailing suffixes when the last one is a known compression type) so the logic is more robust to other sdist archive names.

Suggested implementation:

            if len(elements) == 1 and elements[0].is_dir():
                sdist_dir = elements[0]
            else:
                # Derive the stem by stripping common (possibly multi-part) archive
                # and compression suffixes more generically. This handles variants
                # like .tar.gz, .tar.bz2, .tgz, .tbz2, etc.
                stem = archive.name
                suffixes = Path(stem).suffixes

                if suffixes:
                    compression_suffixes = {".gz", ".bz2", ".xz", ".zip"}
                    archive_suffixes = {".tar", ".zip", ".tgz", ".tbz2"}

                    # Strip trailing compression suffixes, and a preceding .tar if present
                    while suffixes and suffixes[-1] in compression_suffixes:
                        last = suffixes.pop()
                        stem = stem[: -len(last)]
                        if suffixes and suffixes[-1] == ".tar":
                            last_tar = suffixes.pop()
                            stem = stem[: -len(last_tar)]

                    # If we still have a trailing archive-like suffix, strip that too
                    if suffixes and suffixes[-1] in archive_suffixes:
                        last = suffixes.pop()
                        stem = stem[: -len(last)]

                sdist_dir = archive_dir / stem
                if not sdist_dir.is_dir():
                    sdist_dir = archive_dir

This change uses Path(stem).suffixes. If Path is not already imported in this module, add:

  • from pathlib import Path

near the other imports at the top of src/poetry/installation/chef.py.

if stem.endswith(ext):
stem = stem[: -len(ext)]
break
sdist_dir = archive_dir / stem
if not sdist_dir.is_dir():
sdist_dir = archive_dir

Expand Down