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