Skip to content

Commit

Permalink
Merge pull request #2996 from cloudflare/dominik/fix-missing-imports-…
Browse files Browse the repository at this point in the history
…validator

Invalidate Python caches earlier so packages are picked up.
  • Loading branch information
dom96 authored Oct 25, 2024
2 parents 09f3380 + e664e3e commit 839f15d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
7 changes: 7 additions & 0 deletions src/pyodide/internal/python.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
getRandomValues,
} from 'pyodide-internal:topLevelEntropy/lib';
import { default as UnsafeEval } from 'internal:unsafe-eval';
import { simpleRunPython } from 'pyodide-internal:util';

/**
* This file is a simplified version of the Pyodide loader:
Expand Down Expand Up @@ -65,6 +66,12 @@ async function prepareWasmLinearMemory(Module: Module): Promise<void> {
Module.removeRunDependency('dynlibs');
if (SHOULD_RESTORE_SNAPSHOT) {
restoreSnapshot(Module);
// Invalidate caches if we have a snapshot because the contents of site-packages
// may have changed.
simpleRunPython(
Module,
'from importlib import invalidate_caches as f; f(); del f'
);
}
// entropyAfterRuntimeInit adjusts JS state ==> always needs to be called.
entropyAfterRuntimeInit(Module);
Expand Down
8 changes: 0 additions & 8 deletions src/pyodide/internal/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -404,14 +404,6 @@ let TEST_SNAPSHOT: Uint8Array | undefined = undefined;
})();

export function finishSnapshotSetup(pyodide: Pyodide): void {
if (LOADED_SNAPSHOT_VERSION !== undefined) {
// Invalidate caches if we have a snapshot because the contents of site-packages may have changed.
simpleRunPython(
pyodide._module,
'from importlib import invalidate_caches as f; f(); del f'
);
}

// This is just here for our test suite. Ugly but just about the only way to test this.
if (TEST_SNAPSHOT) {
const snapshotString = new TextDecoder().decode(TEST_SNAPSHOT);
Expand Down

0 comments on commit 839f15d

Please sign in to comment.