Skip to content

Untangle Python workers initialization steps - #8516

Merged
ryanking13 merged 1 commit into
mainfrom
gyeongjae/pyodide-entrypoint-init
Nov 25, 2026
Merged

ryanking13 merged 1 commit into
mainfrom
gyeongjae/pyodide-entrypoint-init

Conversation

@ryanking13

Copy link
Copy Markdown
Contributor

Refactors Python workers entrypoint code, without functional change.

  • python-entrypoint.js is a user module, used as an entrypoint for Python workers.
  • python-entrypoint-helper.ts is a builtin module, which have an access to internal modules. python-entrypoint.js calls python-entrypoint-helper.ts.

Previously, python-entrypoint-helper.ts was exporting a few functions to python-entrypoint and python-entrypoint was calling those functions in a top-level, making the top-level execution steps quite tangled and hard to understand.

This changes it as follows:

  1. python-entrypoint-helper.ts expose initPython() function only.
  2. The only job of python-entrypoint.js now is just calling initPython() and pass objects that python-entrypoint-helper.ts cannot read directly.
  3. All the operations happen inside initPython() in a right order.

@ryanking13
ryanking13 requested review from a team as code owners November 17, 2026 05:06

@clanky-the-clanker clanky-the-clanker Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Superseded by the review of 49e8ebf0.

This review, of 68fabb20

✅ Approved — This is a refactor with no functional change. The initialization order, how imports are proxied and the exported values are all the same as before, and I found no issues.

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


✅ All checks passed

🔒 Security: ✅ LGTM

import() is still called from the user-bundle module, so INTERNAL modules stay unreachable from Python imports.


📖 AGENTS.md: ✅ LGTM

No AGENTS.md updates needed.


📋 Code Quality: ✅ LGTM

The initialization steps keep their old order inside initPythonOnce(), and the exported values are unchanged.


⚡ Performance: ✅ LGTM

No performance impact.


📝 Documentation: ✅ LGTM

The new comments describe accurately why the import and the base classes are passed in from python-entrypoint.js, and why initPython() can only be called once.


Reviewed commit: 68fabb20

Comment thread src/pyodide/python-entrypoint-helper.ts Resolved

@hoodmane hoodmane left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@ryanking13
ryanking13 force-pushed the gyeongjae/pyodide-entrypoint-init branch from 68fabb2 to 49e8ebf Compare November 25, 2026 04:26

@clanky-the-clanker clanky-the-clanker Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Approved — This refactor makes no functional change, and nothing was found to flag. Since the last review, the only change is to doAnImport, which takes the approver's suggestion. The initialization order, how imports are proxied, and the exported values are all the same as before.

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


✅ All checks passed

🔒 Security: ✅ LGTM

import() is still called from python-entrypoint.js, which is a user-bundle module. Internal modules therefore still can't be imported from Python.


📖 AGENTS.md: ✅ LGTM

No AGENTS.md updates are needed.


📋 Code Quality: ✅ LGTM

  • initPython() runs the setup steps in the same order as before.
  • doAnImport still wraps the result of import(name) in createImportProxy.
  • setDoAnImport, createImportProxy and makeEntrypointClass used to be exported. Nothing uses them as exports any more.
  • defaultExport and pythonEntrypoints are computed with the same logic that used to be in python-entrypoint.js.
  • The module-level initialized guard starts unset in every new isolate. python-entrypoint.js calls initPython() once, at the top level.

⚡ Performance: ✅ LGTM

No performance impact. The one-time setup runs in the same order as before, pythonEntrypoints is built once at startup, and the initialized guard only adds a boolean check.


📝 Documentation: ✅ LGTM

The new comments correctly explain:

  • why the import function and the base classes are passed in from python-entrypoint.js;
  • why initPython() can only be called once;
  • when createImportProxy wraps an import.

Reviewed commit: 49e8ebf0

@ryanking13
ryanking13 merged commit 25c2041 into main Nov 25, 2026
38 of 40 checks passed
@ryanking13
ryanking13 deleted the gyeongjae/pyodide-entrypoint-init branch November 25, 2026 05:31
ryanking13 added a commit that referenced this pull request Nov 25, 2026
…-init

Untangle Python workers initialization steps
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants