compileBytecode is a helper that generates deterministic hash-based pyc files for faster startup.
(ctx *gcp.Context, path string)
| 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. |
| 415 | func 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 | } |
no test coverage detected