Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add autogate that forces on external python bundle loading #2942

Merged
merged 1 commit into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/workerd/api/pyodide/pyodide.h
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,8 @@ bool hasPythonModules(capnp::List<server::config::Worker::Module>::Reader module
template <class Registry>
void registerPyodideModules(Registry& registry, auto featureFlags) {
// We add `pyodide:` packages here including python-entrypoint-helper.js.
if (!featureFlags.getPythonExternalBundle()) {
if (!featureFlags.getPythonExternalBundle() &&
!util::Autogate::isEnabled(util::AutogateKey::PYTHON_EXTERNAL_BUNDLE)) {
registry.addBuiltinBundle(PYODIDE_BUNDLE, kj::none);
}
registry.template addBuiltinModule<PackagesTarReader>(
Expand All @@ -435,7 +436,8 @@ void registerPyodideModules(Registry& registry, auto featureFlags) {
kj::Own<jsg::modules::ModuleBundle> getInternalPyodideModuleBundle(auto featureFlags) {
jsg::modules::ModuleBundle::BuiltinBuilder builder(
jsg::modules::ModuleBundle::BuiltinBuilder::Type::BUILTIN_ONLY);
if (!featureFlags.getPythonExternalBundle()) {
if (!featureFlags.getPythonExternalBundle() &&
!util::Autogate::isEnabled(util::AutogateKey::PYTHON_EXTERNAL_BUNDLE)) {
jsg::modules::ModuleBundle::getBuiltInBundleFromCapnp(builder, PYODIDE_BUNDLE);
}
return builder.finish();
Expand All @@ -444,7 +446,8 @@ kj::Own<jsg::modules::ModuleBundle> getInternalPyodideModuleBundle(auto featureF
kj::Own<jsg::modules::ModuleBundle> getExternalPyodideModuleBundle(auto featureFlags) {
jsg::modules::ModuleBundle::BuiltinBuilder builder(
jsg::modules::ModuleBundle::BuiltinBuilder::Type::BUILTIN);
if (!featureFlags.getPythonExternalBundle()) {
if (!featureFlags.getPythonExternalBundle() &&
!util::Autogate::isEnabled(util::AutogateKey::PYTHON_EXTERNAL_BUNDLE)) {
jsg::modules::ModuleBundle::getBuiltInBundleFromCapnp(builder, PYODIDE_BUNDLE);
}
return builder.finish();
Expand Down
3 changes: 2 additions & 1 deletion src/workerd/server/workerd-api.c++
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,8 @@ void WorkerdApi::compileModules(jsg::Lock& lockParam,
KJ_REQUIRE(featureFlags.getPythonWorkers(),
"The python_workers compatibility flag is required to use Python.");
// Inject Pyodide bundle
if (featureFlags.getPythonExternalBundle()) {
if (featureFlags.getPythonExternalBundle() ||
util::Autogate::isEnabled(util::AutogateKey::PYTHON_EXTERNAL_BUNDLE)) {
auto pythonRelease = KJ_ASSERT_NONNULL(getPythonSnapshotRelease(featureFlags));
auto version = getPythonBundleName(pythonRelease);
auto bundle = KJ_ASSERT_NONNULL(
Expand Down
2 changes: 2 additions & 0 deletions src/workerd/util/autogate.c++
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ kj::StringPtr KJ_STRINGIFY(AutogateKey key) {
switch (key) {
case AutogateKey::TEST_WORKERD:
return "test-workerd"_kj;
case AutogateKey::PYTHON_EXTERNAL_BUNDLE:
return "python-external-bundle"_kj;
case AutogateKey::NumOfKeys:
KJ_FAIL_ASSERT("NumOfKeys should not be used in getName");
}
Expand Down
1 change: 1 addition & 0 deletions src/workerd/util/autogate.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace workerd::util {
// Workerd-specific list of autogate keys (can also be used in internal repo).
enum class AutogateKey {
TEST_WORKERD,
PYTHON_EXTERNAL_BUNDLE,
NumOfKeys // Reserved for iteration.
};

Expand Down