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

Function compileBytecode

pkg/python/python.go:406–427  ·  view source on GitHub ↗

compileBytecode is a helper that generates deterministic hash-based pyc files for faster startup.

(ctx *gcp.Context, path string)

Source from the content-addressed store, hash-verified

404 }
405
406 // Update layer metadata for caching
407 cache.Add(ctx, l, dependencyHashKey, hash)
408 ctx.SetMetadata(l, pythonVersionKey, currentPythonVersion)
409 ctx.SetMetadata(l, expiryTimestampKey, time.Now().Add(expirationTime).Format(dateFormat))
410
411 return true, nil
412}
413
414// compileBytecode is a helper that generates deterministic hash-based pyc files for faster startup.
415func compileBytecode(ctx *gcp.Context, path string) error {
416 // Generate deterministic hash-based pycs (https://www.python.org/dev/peps/pep-0552/).
417 // Use the unchecked version to skip hash validation at run time (for faster startup).
418 result, err := ctx.Exec([]string{
419 "python3", "-m", "compileall",
420 "--invalidation-mode", "unchecked-hash",
421 "-qq", // Do not print any message (matches `pip install` behavior).
422 path,
423 }, gcp.WithUserAttribution)
424
425 if err != nil {
426 if result != nil {
427 if result.ExitCode == 1 {
428 // Ignore file compilation errors (matches `pip install` behavior).
429 return nil
430 }

Callers 2

UVInstallRequirementsFunction · 0.85
PIPInstallRequirementsFunction · 0.85

Calls 1

ExecMethod · 0.80

Tested by

no test coverage detected