Skip to content

Wire prepare_source and build_sdist for git-clone-based source resolvers #1205

Open

Description

@smoparth

Context

When a package uses the new source: config with a git-clone-based resolver (github-tag-git, gitlab-tag-git, pypi-git), the resolve and clone steps work correctly via source_resolver.resolver_provider() and source_resolver.download(). However, the prepare_source step doesn't yet handle the cloned directory.

Parent epic: #1254 (Phase 4)
Depends on: Phase 3 (download dispatch — #1293)

prepare_source crashes on git-clone directories

sources.prepare_source() decides how to prepare source based on req.url:

if req.url:
    source_root_dir = pathlib.Path(source_filename)
    prepare_new_source(...)
else:
    prepare_source_details = overrides.find_and_invoke("prepare_source", default_prepare_source, ...)

When a package uses the new source config with a git-clone-based resolver, req.url is None, so it takes the else path. That calls default_prepare_source() -> unpack_source(), which tries to open source_filename as a .tar.gz or .zip. But source_filename is a directory (the cloned git repo). This crashes with:

ValueError: Do not know how to unpack source archive /path/to/mypackage-1.0

Fix approach

The download step (Phase 3) returns (path, DownloadKind) from source_resolver.download(). Use DownloadKind.git_checkout to detect when the source is a directory:

if download_kind == DownloadKind.git_checkout or source_filename.is_dir():
    source_root_dir = pathlib.Path(source_filename)
    prepare_new_source(...)
else:
    # existing unpack logic

Related

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions