Skip to content

feat: support local package artifacts in requirements - #3095

Open
anish-sahoo wants to merge 8 commits into
mainfrom
issue-1945
Open

feat: support local package artifacts in requirements#3095
anish-sahoo wants to merge 8 commits into
mainfrom
issue-1945

Conversation

@anish-sahoo

@anish-sahoo anish-sahoo commented Jul 7, 2026

Copy link
Copy Markdown
Member

Summary

  • Add support for bare local wheel and source archive paths in build.python_requirements.
  • Resolve paths relative to the requirements file and stage only referenced artifacts through cog_build before dependency installation.
  • Keep config loading and custom Dockerfile builds unchanged by applying local artifact validation only to Cog-generated Dockerfiles.
  • Preserve requirement filenames, confine symlink and staging access to project/build roots, and restore Cog's managed runtime after user artifacts are installed.
  • Document the supported syntax and add unit and integration coverage for wheels, ZIP source archives, tarballs, and paths containing spaces.

Fixes #1945

Usage

Local artifacts can be listed directly in a requirements file:

./dist/mylib-0.1.0-py3-none-any.whl
./vendor/helper library.zip
./packages/localpkg.tar.gz

Cog supports .whl, .zip, .tar.gz, .tgz, .tar.bz2, and .tar.xz. Paths may contain spaces, are resolved relative to the requirements file, and must point to regular files inside the project after symlink resolution.

Remote URLs, remote direct references, and remote requirements options continue to pass through unchanged.

Limits

  • build.run: pip install ./artifact.zip does not stage local source files.
  • Local package directories are not supported.
  • Local file URLs and local direct references such as name @ path are rejected.
  • Local --find-links directories and recursive local requirements includes are rejected.
  • Inline markers, extras, hashes, and options on local artifact lines are rejected.
  • Any cog or coglet distribution installed by a local artifact is overridden by Cog's configured runtime. Use build.sdk_version, COG_SDK_WHEEL, or COGLET_WHEEL to select those packages.

Testing

  • gotestsum -- -short -timeout 1200s -parallel 5 ./...
  • golangci-lint run ./...
  • go test -tags integration -run "TestIntegration/local_python_requirement_artifact" ./integration-tests/...

@anish-sahoo
anish-sahoo requested a review from a team as a code owner July 7, 2026 21:10
@ask-bonk

ask-bonk Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

LGTM

github run

@anish-sahoo anish-sahoo changed the title Support local package artifacts in requirements feat: support local package artifacts in requirements Jul 7, 2026

@ask-bonk ask-bonk Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm Bonk, and I've done a quick review of your PR.

This PR adds support for staging local wheel/source-archive paths from requirements.txt through the cog_build context before pip install. Overall the approach is clean and well-tested. I found one issue where a valid pip syntax that references local paths can slip through and cause a confusing build failure.

Comment thread pkg/requirements/local_artifact.go
Comment thread pkg/requirements/requirements_test.go
@ask-bonk

ask-bonk Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

I'm Bonk, and I've done a quick review of your PR.

This PR adds support for staging local wheel/source-archive paths from requirements.txt through the cog_build context before pip install. Overall the approach is clean and well-tested. I found one issue where a valid pip syntax that references local paths can slip through and cause a confusing build failure.

Posted a batch review with 2 suggestions on PR #3095:
#3095 (review)

github run

@ask-bonk

ask-bonk Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

@anish-sahoo Bonk workflow was cancelled.

View workflow run · To retry, trigger Bonk again.

2 similar comments
@ask-bonk

ask-bonk Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

@anish-sahoo Bonk workflow was cancelled.

View workflow run · To retry, trigger Bonk again.

@ask-bonk

ask-bonk Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

@anish-sahoo Bonk workflow was cancelled.

View workflow run · To retry, trigger Bonk again.

@ask-bonk

ask-bonk Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

LGTM

github run

Copilot AI review requested due to automatic review settings August 3, 2026 21:52

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds support for referencing local Python wheel/source-archive artifacts from build.python_requirements, staging them into the existing cog_build context so Docker builds can pip install -r /tmp/requirements.txt without copying the whole project early.

Changes:

  • Parse and validate “bare” local artifact lines in requirements files, and collect/stage those files into the Docker build context.
  • Update Dockerfile generation to COPY staged artifacts into the image before running pip install -r ..., and rewrite requirements lines to container paths.
  • Add unit + integration coverage and document supported/unsupported syntax.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
pkg/requirements/requirements.go Tightens trailing-comment stripping by trimming whitespace after #.
pkg/requirements/requirements_test.go Adds unit tests for local-artifact requirement parsing and updates comment-strip fixture.
pkg/requirements/local_artifact.go Introduces parsing/validation for supported local artifact requirement forms.
pkg/dockerfile/standard_generator.go Stages local artifacts into the build context and injects a COPY --from=cog_build ... before pip install; rejects local cog/coglet artifacts.
pkg/dockerfile/standard_generator_test.go Validates artifact staging, Dockerfile ordering, and managed-package rejection behavior.
pkg/config/data/config_schema_v1.0.json Updates schema description to mention local artifact support.
pkg/config/config.go Collects/validates local artifact paths (exist, regular file, inside project) and exposes them to the generator.
pkg/config/config_test.go Adds tests covering artifact discovery and validation failures.
integration-tests/tests/local_python_requirement_artifact.txtar End-to-end test proving a local archive is installed during cog build and importable at runtime.
docs/yaml.md Documents supported local artifact syntax and clarifies run limitations.
docs/llms.txt Regenerated LLM doc snapshot reflecting the YAML docs change.
architecture/05-build-system.md Updates the build-system architecture narrative to include staged user-provided artifacts.
Suppressed comments (1)

pkg/requirements/local_artifact.go:70

  • unsupportedLocalOption currently does not flag -r/--requirement/-f/--find-links when the option value starts with file: (and isRemoteRequirement treats file:///... as remote due to "://"). This lets -r file:///... / --find-links file:///... through even though local file URLs and local includes are out of scope and won’t be staged into the build context.
			value, ok = strings.CutPrefix(line, option+"=")
		}
		value = strings.TrimSpace(value)
		if ok && value != "" && !isRemoteRequirement(value) && !strings.HasPrefix(value, "file:") {
			return option

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/requirements/local_artifact.go Outdated
Comment on lines +17 to +19
if strings.HasPrefix(line, "file:") {
return "", false, fmt.Errorf("local file URL requirements are not supported: %s", line)
}
@ask-bonk

ask-bonk Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

@anish-sahoo Bonk workflow failed. Check the logs for details.

View workflow run · To retry, trigger Bonk again.

Make the file: URL rejection case-insensitive so FILE:/// forms are not
mistaken for remote requirements, and reorder the option check ahead of
the remote short-circuit so file:-scheme options are rejected too.

Switch the integration test sdist from python3 -m zipfile (which flattens
paths and drops the package directory) to a tar.gz that preserves the
package layout, so pip install succeeds.
Copilot AI review requested due to automatic review settings August 4, 2026 15:16

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI review requested due to automatic review settings August 5, 2026 19:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI review requested due to automatic review settings August 5, 2026 21:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Installing local packages during cog build

2 participants