Skip to content

Commit

Permalink
Remove --upgrade from pip install in the pip and functions-framework …
Browse files Browse the repository at this point in the history
…buildpack

Some dependencies are incompatible with the --upgrade and --target flag combination, e.g. pypa/pip#8799.

PiperOrigin-RevId: 328384678
Change-Id: Iea6962774a6bd82f02435ba785ba92445e762c8d
  • Loading branch information
lukasberger authored and copybara-github committed Aug 25, 2020
1 parent 7b79100 commit 7768ebe
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 5 additions & 1 deletion cmd/python/pip/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,14 @@ func buildFn(ctx *gcp.Context) error {
return nil
}
ctx.CacheMiss(layerName)
// pip install --target does no override existing dependencies, so remove everything.
// We cannot use --upgrade due to a bug in pip: https://github.com/pypa/pip/issues/8799.
// Any cached dependencies will be restored from PIP_CACHE_DIR.
ctx.ClearLayer(l)

// Install modules in requirements.txt.
ctx.Logf("Running pip install.")
ctx.Exec([]string{"python3", "-m", "pip", "install", "--upgrade", "-r", "requirements.txt", "-t", l.Path}, gcp.WithEnv("PIP_CACHE_DIR="+cl.Path), gcp.WithUserAttribution)
ctx.Exec([]string{"python3", "-m", "pip", "install", "-r", "requirements.txt", "--target", l.Path}, gcp.WithEnv("PIP_CACHE_DIR="+cl.Path), gcp.WithUserAttribution)

l.SharedEnvironment.PrependPath("PYTHONPATH", l.Path)

Expand Down
5 changes: 4 additions & 1 deletion pkg/python/python.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,10 @@ func InstallRequirements(ctx *gcp.Context, l *libcnb.Layer, req string) error {
ctx.CacheHit(l.Name)
} else {
ctx.CacheMiss(l.Name)
ctx.Exec([]string{"python3", "-m", "pip", "install", "-t", l.Path, "-r", req}, gcp.WithUserAttribution)
// pip install --target does no override existing dependencies, so remove everything.
// We cannot use --upgrade due to a bug in pip: https://github.com/pypa/pip/issues/8799.
ctx.ClearLayer(l)
ctx.Exec([]string{"python3", "-m", "pip", "install", "-r", req, "--target", l.Path}, gcp.WithUserAttribution)
}
l.SharedEnvironment.PrependPath("PYTHONPATH", l.Path)
return nil
Expand Down

0 comments on commit 7768ebe

Please sign in to comment.