Skip to content

Commit 966eee4

Browse files
authored
Merge pull request #2942 from cloudflare/hoodmane/python-external-autogate
Add autogate that forces on external python bundle loading
2 parents 48bba72 + c7547fd commit 966eee4

File tree

4 files changed

+11
-4
lines changed

4 files changed

+11
-4
lines changed

src/workerd/api/pyodide/pyodide.h

+6-3
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,8 @@ bool hasPythonModules(capnp::List<server::config::Worker::Module>::Reader module
425425
template <class Registry>
426426
void registerPyodideModules(Registry& registry, auto featureFlags) {
427427
// We add `pyodide:` packages here including python-entrypoint-helper.js.
428-
if (!featureFlags.getPythonExternalBundle()) {
428+
if (!featureFlags.getPythonExternalBundle() &&
429+
!util::Autogate::isEnabled(util::AutogateKey::PYTHON_EXTERNAL_BUNDLE)) {
429430
registry.addBuiltinBundle(PYODIDE_BUNDLE, kj::none);
430431
}
431432
registry.template addBuiltinModule<PackagesTarReader>(
@@ -435,7 +436,8 @@ void registerPyodideModules(Registry& registry, auto featureFlags) {
435436
kj::Own<jsg::modules::ModuleBundle> getInternalPyodideModuleBundle(auto featureFlags) {
436437
jsg::modules::ModuleBundle::BuiltinBuilder builder(
437438
jsg::modules::ModuleBundle::BuiltinBuilder::Type::BUILTIN_ONLY);
438-
if (!featureFlags.getPythonExternalBundle()) {
439+
if (!featureFlags.getPythonExternalBundle() &&
440+
!util::Autogate::isEnabled(util::AutogateKey::PYTHON_EXTERNAL_BUNDLE)) {
439441
jsg::modules::ModuleBundle::getBuiltInBundleFromCapnp(builder, PYODIDE_BUNDLE);
440442
}
441443
return builder.finish();
@@ -444,7 +446,8 @@ kj::Own<jsg::modules::ModuleBundle> getInternalPyodideModuleBundle(auto featureF
444446
kj::Own<jsg::modules::ModuleBundle> getExternalPyodideModuleBundle(auto featureFlags) {
445447
jsg::modules::ModuleBundle::BuiltinBuilder builder(
446448
jsg::modules::ModuleBundle::BuiltinBuilder::Type::BUILTIN);
447-
if (!featureFlags.getPythonExternalBundle()) {
449+
if (!featureFlags.getPythonExternalBundle() &&
450+
!util::Autogate::isEnabled(util::AutogateKey::PYTHON_EXTERNAL_BUNDLE)) {
448451
jsg::modules::ModuleBundle::getBuiltInBundleFromCapnp(builder, PYODIDE_BUNDLE);
449452
}
450453
return builder.finish();

src/workerd/server/workerd-api.c++

+2-1
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,8 @@ void WorkerdApi::compileModules(jsg::Lock& lockParam,
511511
KJ_REQUIRE(featureFlags.getPythonWorkers(),
512512
"The python_workers compatibility flag is required to use Python.");
513513
// Inject Pyodide bundle
514-
if (featureFlags.getPythonExternalBundle()) {
514+
if (featureFlags.getPythonExternalBundle() ||
515+
util::Autogate::isEnabled(util::AutogateKey::PYTHON_EXTERNAL_BUNDLE)) {
515516
auto pythonRelease = KJ_ASSERT_NONNULL(getPythonSnapshotRelease(featureFlags));
516517
auto version = getPythonBundleName(pythonRelease);
517518
auto bundle = KJ_ASSERT_NONNULL(

src/workerd/util/autogate.c++

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ kj::StringPtr KJ_STRINGIFY(AutogateKey key) {
1717
switch (key) {
1818
case AutogateKey::TEST_WORKERD:
1919
return "test-workerd"_kj;
20+
case AutogateKey::PYTHON_EXTERNAL_BUNDLE:
21+
return "python-external-bundle"_kj;
2022
case AutogateKey::NumOfKeys:
2123
KJ_FAIL_ASSERT("NumOfKeys should not be used in getName");
2224
}

src/workerd/util/autogate.h

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ namespace workerd::util {
1414
// Workerd-specific list of autogate keys (can also be used in internal repo).
1515
enum class AutogateKey {
1616
TEST_WORKERD,
17+
PYTHON_EXTERNAL_BUNDLE,
1718
NumOfKeys // Reserved for iteration.
1819
};
1920

0 commit comments

Comments
 (0)