File
Blob: src/pyodide/internal/metadata.ts
| 1 | // Copyright (c) 2026 Cloudflare, Inc. |
| 2 | // Licensed under the Apache 2.0 license found in the LICENSE file or at: |
| 3 | // https://opensource.org/licenses/Apache-2.0 |
| 4 | |
| 5 | import { default as MetadataReader } from 'pyodide-internal:runtime-generated/metadata'; |
| 6 | import { default as ArtifactBundler } from 'pyodide-internal:artifacts'; |
| 7 | |
| 8 | export const IS_WORKERD = MetadataReader.isWorkerd(); |
| 9 | export const IS_TRACING = MetadataReader.isTracing(); |
| 10 | export const SHOULD_ABORT_ISOLATE_ON_FATAL_ERROR = |
| 11 | MetadataReader.shouldAbortIsolateOnFatalError(); |
| 12 | |
| 13 | // Snapshots |
| 14 | export const SHOULD_SNAPSHOT_TO_DISK = MetadataReader.shouldSnapshotToDisk(); |
| 15 | export const IS_CREATING_BASELINE_SNAPSHOT = |
| 16 | MetadataReader.isCreatingBaselineSnapshot(); |
| 17 | export const IS_EW_VALIDATING = ArtifactBundler.isEwValidating(); |
| 18 | export const IS_DYNAMIC_WORKER = ArtifactBundler.isDynamicWorker(); |
| 19 | export const IS_CREATING_SNAPSHOT = IS_EW_VALIDATING || SHOULD_SNAPSHOT_TO_DISK; |
| 20 | |
| 21 | // There are two validations that we perform. The first one runs without a _bundled_ memory snapshot |
| 22 | // (but may use a baseline snapshot, though this is stored in the ArtfactBundler). The second one |
| 23 | // runs with a _bundled_ memory snapshot, which is expected to be a dedicated snapshot. When this |
| 24 | // bool is true, we verify that the bundled memory snapshot we receive is a dedicated snapshot. |
| 25 | export const IS_SECOND_VALIDATION_PHASE = |
| 26 | MetadataReader.hasMemorySnapshot() && IS_EW_VALIDATING; |
| 27 | export const MEMORY_SNAPSHOT_READER = MetadataReader.hasMemorySnapshot() |
| 28 | ? MetadataReader |
| 29 | : ArtifactBundler.hasMemorySnapshot() |
| 30 | ? ArtifactBundler |
| 31 | : undefined; |
| 32 | |
| 33 | // Packages |
| 34 | export const PACKAGES_VERSION = MetadataReader.getPackagesVersion(); |
| 35 | export const USING_OLDEST_PACKAGES_VERSION = PACKAGES_VERSION === '20240829.4'; |
| 36 | // The package lock is embedded in the binary. See `getPyodideLock` and `packageLocks`. |
| 37 | export const LOCKFILE = JSON.parse( |
| 38 | MetadataReader.getPackagesLock() |
| 39 | ) as PackageLock; |
| 40 | |
| 41 | export const REQUIREMENTS = MetadataReader.getRequirements(); |
| 42 | export const TRANSITIVE_REQUIREMENTS = |
| 43 | MetadataReader.getTransitiveRequirements(); |
| 44 | |
| 45 | // Entrypoints |
| 46 | export const MAIN_MODULE_NAME = MetadataReader.getMainModule(); |
| 47 | |
| 48 | export type CompatibilityFlags = MetadataReader.CompatibilityFlags; |
| 49 | export const COMPATIBILITY_FLAGS: MetadataReader.CompatibilityFlags = { |
| 50 | // Compat flags returned from getCompatibilityFlags is immutable, |
| 51 | // but in Pyodide 0.26, we modify the JS object that is exposed to the Python through |
| 52 | // registerJsModule so we create a new object here by copying the values. |
| 53 | ...MetadataReader.getCompatibilityFlags(), |
| 54 | }; |
| 55 | export const WORKFLOWS_ENABLED: boolean = |
| 56 | !!COMPATIBILITY_FLAGS.python_workflows; |
| 57 | const NO_GLOBAL_HANDLERS: boolean = |
| 58 | !!COMPATIBILITY_FLAGS.python_no_global_handlers; |
| 59 | const FORCE_NEW_VENDOR_PATH: boolean = |
| 60 | !!COMPATIBILITY_FLAGS.python_workers_force_new_vendor_path; |
| 61 | export const IS_DEDICATED_SNAPSHOT_ENABLED: boolean = |
| 62 | !!COMPATIBILITY_FLAGS.python_dedicated_snapshot; |
| 63 | export const EXTERNAL_SDK = !!COMPATIBILITY_FLAGS.enable_python_external_sdk; |
| 64 | |
| 65 | export const LEGACY_GLOBAL_HANDLERS = !NO_GLOBAL_HANDLERS; |
| 66 | export const LEGACY_VENDOR_PATH = !FORCE_NEW_VENDOR_PATH; |
| 67 | export const CHECK_RNG_STATE = !!COMPATIBILITY_FLAGS.python_check_rng_state; |
| 68 | export const PROCESS_PTH_FILES = !!COMPATIBILITY_FLAGS.python_process_pth_files; |
| 69 | |
| 70 | export const setCpuLimitNearlyExceededCallback = |
| 71 | MetadataReader.setCpuLimitNearlyExceededCallback.bind(MetadataReader); |