MCPcopy Create free account
hub / github.com/GoogleCloudPlatform/buildpacks / copySharedLibs

Function copySharedLibs

pkg/python/python.go:457–478  ·  view source on GitHub ↗

copySharedLibs moves the shared libs from the runtime layer into pip layer. This is required to support building native extensions in python37 and python38 because virtual env does not copy the correctly.

(ctx *gcp.Context, l *libcnb.Layer)

Source from the content-addressed store, hash-verified

455// a directory that is not writeable in the buildpacks world (/env). In order to keep
456// compatiblity with base image updates, we replace the virtual environment with a writeable one.
457func requiresVirtualEnv() bool {
458 runtime := os.Getenv(env.Runtime)
459 return runtime == "python37" || runtime == "python38"
460}
461
462// copySharedLibs moves the shared libs from the runtime layer into pip layer. This is required to
463// support building native extensions in python37 and python38 because virtual env does not copy
464// the correctly.
465func copySharedLibs(ctx *gcp.Context, l *libcnb.Layer) error {
466 var oldPath string
467 var newPath string
468 if os.Getenv(env.Runtime) == "python37" {
469 oldPath = python37SharedLibDir
470 newPath = filepath.Join(l.Path, "lib", "python3.7", filepath.Base(oldPath))
471 }
472 if os.Getenv(env.Runtime) == "python38" {
473 oldPath = python38SharedLibDir
474 newPath = filepath.Join(l.Path, "lib", "python3.8", filepath.Base(oldPath))
475 }
476 exists, err := ctx.FileExists(oldPath)
477 if err != nil {
478 return gcp.InternalErrorf("finding shared libs in %v: %w", oldPath, err)
479 }
480 if exists {
481 if err := os.Symlink(oldPath, newPath); err != nil {

Callers 1

PIPInstallRequirementsFunction · 0.85

Calls 2

FileExistsMethod · 0.80
SymlinkMethod · 0.80

Tested by

no test coverage detected