Skip to content

Commit

Permalink
Merge pull request #3082 from cloudflare/hoodmane/always-use-external…
Browse files Browse the repository at this point in the history
…-bundle

Remove code for Pyodide builtin bundle
  • Loading branch information
hoodmane authored Nov 19, 2024
2 parents 92b264e + 849bf07 commit d1badf9
Show file tree
Hide file tree
Showing 25 changed files with 30 additions and 51 deletions.
2 changes: 1 addition & 1 deletion samples/pyodide-fastapi/config.capnp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const mainWorker :Workerd.Worker = (
),
],
compatibilityDate = "2023-12-18",
compatibilityFlags = ["python_workers", "python_external_bundle"],
compatibilityFlags = ["python_workers"],
# Learn more about compatibility dates at:
# https://developers.cloudflare.com/workers/platform/compatibility-dates/
);
2 changes: 1 addition & 1 deletion samples/pyodide-langchain/config.capnp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const mainWorker :Workerd.Worker = (
(name = "langchain_openai", pythonRequirement = ""),
],
compatibilityDate = "2023-12-18",
compatibilityFlags = ["python_workers", "python_external_bundle"],
compatibilityFlags = ["python_workers"],
# Learn more about compatibility dates at:
# https://developers.cloudflare.com/workers/platform/compatibility-dates/
);
2 changes: 1 addition & 1 deletion samples/pyodide-secret/config.capnp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const mainWorker :Workerd.Worker = (
(name = "worker.py", pythonModule = embed "./worker.py"),
],
compatibilityDate = "2023-12-18",
compatibilityFlags = ["python_workers", "python_external_bundle"],
compatibilityFlags = ["python_workers"],
bindings = [
(
name = "secret",
Expand Down
2 changes: 1 addition & 1 deletion samples/pyodide/config.capnp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const mainWorker :Workerd.Worker = (
(name = "worker.py", pythonModule = embed "./worker.py"),
],
compatibilityDate = "2023-12-18",
compatibilityFlags = ["python_workers", "python_external_bundle"],
compatibilityFlags = ["python_workers"],
# Learn more about compatibility dates at:
# https://developers.cloudflare.com/workers/platform/compatibility-dates/
);
2 changes: 1 addition & 1 deletion samples/repl-server-python/config.capnp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const mainWorker :Workerd.Worker = (
(name = "worker.py", pythonModule = embed "./worker.py"),
],
compatibilityDate = "2023-12-18",
compatibilityFlags = ["python_workers", "python_external_bundle"],
compatibilityFlags = ["python_workers"],
# Learn more about compatibility dates at:
# https://developers.cloudflare.com/workers/platform/compatibility-dates/
);
3 changes: 2 additions & 1 deletion src/cloudflare/internal/test/ai/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
load("//:build/wd_test.bzl", "wd_test")
load("//src/workerd/server/tests/python:py_wd_test.bzl", "py_wd_test")

wd_test(
src = "ai-api-test.wd-test",
args = ["--experimental"],
data = glob(["*.js"]),
)

wd_test(
py_wd_test(
size = "large",
src = "python-ai-api-test.wd-test",
args = ["--experimental"],
Expand Down
2 changes: 1 addition & 1 deletion src/cloudflare/internal/test/ai/python-ai-api-test.wd-test
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const unitTests :Workerd.Config = (
(name = "worker.py", pythonModule = embed "ai-api-test.py")
],
compatibilityDate = "2023-01-15",
compatibilityFlags = ["nodejs_compat", "python_workers"],
compatibilityFlags = ["nodejs_compat", "python_workers_development"],
bindings = [
(
name = "ai",
Expand Down
3 changes: 2 additions & 1 deletion src/cloudflare/internal/test/d1/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
load("//:build/wd_test.bzl", "wd_test")
load("//src/workerd/server/tests/python:py_wd_test.bzl", "py_wd_test")

wd_test(
src = "d1-api-test.wd-test",
Expand All @@ -15,7 +16,7 @@ wd_test(
data = glob(["*.js"]),
)

wd_test(
py_wd_test(
size = "large",
src = "python-d1-api-test.wd-test",
args = ["--experimental"],
Expand Down
2 changes: 1 addition & 1 deletion src/cloudflare/internal/test/d1/python-d1-api-test.wd-test
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const unitTests :Workerd.Config = (
(name = "worker.py", pythonModule = embed "d1-api-test.py")
],
compatibilityDate = "2023-01-15",
compatibilityFlags = ["nodejs_compat", "python_workers"],
compatibilityFlags = ["nodejs_compat", "python_workers_development"],
bindings = [
(
name = "d1",
Expand Down
3 changes: 2 additions & 1 deletion src/cloudflare/internal/test/vectorize/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
load("//:build/wd_test.bzl", "wd_test")
load("//src/workerd/server/tests/python:py_wd_test.bzl", "py_wd_test")

wd_test(
src = "vectorize-api-test.wd-test",
data = glob(["*.js"]),
)

wd_test(
py_wd_test(
size = "large",
src = "python-vectorize-api-test.wd-test",
data = glob([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const unitTests :Workerd.Config = (
( name = "worker.py", pythonModule = embed "vectorize-api-test.py" )
],
compatibilityDate = "2023-11-21",
compatibilityFlags = ["nodejs_compat", "python_workers"],
compatibilityFlags = ["nodejs_compat", "python_workers_development"],
bindings = [
( name = "vectorSearch",
wrapped = (
Expand Down
1 change: 0 additions & 1 deletion src/workerd/api/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ wd_cc_library(
implementation_deps = ["//src/workerd/util:string-buffer"],
visibility = ["//visibility:public"],
deps = [
"//src/pyodide",
"//src/pyodide:pyodide_extra_capnp",
"//src/workerd/io",
"//src/workerd/jsg",
Expand Down
13 changes: 0 additions & 13 deletions src/workerd/api/pyodide/pyodide.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include <workerd/util/autogate.h>

#include <pyodide/generated/pyodide_extra.capnp.h>
#include <pyodide/pyodide.capnp.h>

#include <capnp/serialize.h>
#include <kj/array.h>
Expand Down Expand Up @@ -425,31 +424,19 @@ 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() &&
!util::Autogate::isEnabled(util::AutogateKey::PYTHON_EXTERNAL_BUNDLE)) {
registry.addBuiltinBundle(PYODIDE_BUNDLE, kj::none);
}
registry.template addBuiltinModule<PackagesTarReader>(
"pyodide-internal:packages_tar_reader", workerd::jsg::ModuleRegistry::Type::INTERNAL);
}

kj::Own<jsg::modules::ModuleBundle> getInternalPyodideModuleBundle(auto featureFlags) {
jsg::modules::ModuleBundle::BuiltinBuilder builder(
jsg::modules::ModuleBundle::BuiltinBuilder::Type::BUILTIN_ONLY);
if (!featureFlags.getPythonExternalBundle() &&
!util::Autogate::isEnabled(util::AutogateKey::PYTHON_EXTERNAL_BUNDLE)) {
jsg::modules::ModuleBundle::getBuiltInBundleFromCapnp(builder, PYODIDE_BUNDLE);
}
return builder.finish();
}

kj::Own<jsg::modules::ModuleBundle> getExternalPyodideModuleBundle(auto featureFlags) {
jsg::modules::ModuleBundle::BuiltinBuilder builder(
jsg::modules::ModuleBundle::BuiltinBuilder::Type::BUILTIN);
if (!featureFlags.getPythonExternalBundle() &&
!util::Autogate::isEnabled(util::AutogateKey::PYTHON_EXTERNAL_BUNDLE)) {
jsg::modules::ModuleBundle::getBuiltInBundleFromCapnp(builder, PYODIDE_BUNDLE);
}
return builder.finish();
}

Expand Down
7 changes: 1 addition & 6 deletions src/workerd/io/compatibility-date.capnp
Original file line number Diff line number Diff line change
Expand Up @@ -622,13 +622,8 @@ struct CompatibilityFlags @0x8f8c1b68151b6cef {
# compatibility flag we arrange to have such promise continuations scheduled to run
# in the correct IoContext if it is still alive, or dropped on the floor with a warning
# if the correct IoContext is not still alive.
pythonExternalBundle @63 :Bool
$compatEnableFlag("python_external_bundle")
obsolete63 @63 :Bool
$experimental;
# Temporary flag to load Python from external capnproto bundle loaded at runtime.
# We plan to turn this on always quite soon. It would be an autogate but we need to test
# our logic both at upload time and at runtime, and this seemed like the easiest way to
# make sure we keep things in sync.

setToStringTag @64 :Bool
$compatEnableFlag("set_tostring_tag")
Expand Down
1 change: 1 addition & 0 deletions src/workerd/server/tests/python/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ copy_file(
name = "pyodide_dev.capnp.bin@rule",
src = "//src/pyodide:pyodide.capnp.bin",
out = "pyodide-bundle-cache/pyodide_dev.capnp.bin",
visibility = ["//visibility:public"],
)

py_wd_test(
Expand Down
2 changes: 1 addition & 1 deletion src/workerd/server/tests/python/env-param/env.wd-test
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const unitTests :Workerd.Config = (
),
],
compatibilityDate = "2024-01-15",
compatibilityFlags = ["python_workers_development", "python_external_bundle"],
compatibilityFlags = ["python_workers_development"],
)
),
],
Expand Down
2 changes: 1 addition & 1 deletion src/workerd/server/tests/python/hello/hello.wd-test
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const unitTests :Workerd.Config = (
(name = "worker.py", pythonModule = embed "worker.py")
],
compatibilityDate = "2024-01-15",
compatibilityFlags = ["python_workers_development", "python_external_bundle"],
compatibilityFlags = ["python_workers_development"],
)
),
],
Expand Down
2 changes: 1 addition & 1 deletion src/workerd/server/tests/python/import_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const unitTests :Workerd.Config = (
(name = "{}", pythonRequirement = ""),
],
compatibilityDate = "2024-05-02",
compatibilityFlags = ["python_workers_development", "python_external_bundle"],
compatibilityFlags = ["python_workers_development"],
)
),
]
Expand Down
4 changes: 2 additions & 2 deletions src/workerd/server/tests/python/py_wd_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ def py_wd_test(
size = "enormous",
tags = [],
**kwargs):
data += ["pyodide_dev.capnp.bin@rule"]
args += ["--pyodide-bundle-disk-cache-dir", "$(location pyodide_dev.capnp.bin@rule)/.."]
data += ["//src/workerd/server/tests/python:pyodide_dev.capnp.bin@rule"]
args = args + ["--pyodide-bundle-disk-cache-dir", "$(location //src/workerd/server/tests/python:pyodide_dev.capnp.bin@rule)/..", "--experimental"]

wd_test(
src = src,
Expand Down
2 changes: 1 addition & 1 deletion src/workerd/server/tests/python/random/random.wd-test
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const unitTests :Workerd.Config = (
(name = "worker.py", pythonModule = embed "worker.py")
],
compatibilityDate = "2024-01-15",
compatibilityFlags = ["python_workers_development", "python_external_bundle"],
compatibilityFlags = ["python_workers_development"],
)
),
],
Expand Down
4 changes: 2 additions & 2 deletions src/workerd/server/tests/python/sdk/sdk.wd-test
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ const python :Workerd.Worker = (
( name = "SELF", service = "python-sdk" ),
],
compatibilityDate = "2024-10-01",
compatibilityFlags = ["python_workers_development", "python_external_bundle"],
compatibilityFlags = ["python_workers_development"],
);

const server :Workerd.Worker = (
modules = [
(name = "server.py", pythonModule = embed "server.py")
],
compatibilityDate = "2024-10-01",
compatibilityFlags = ["python_workers_development", "python_external_bundle"],
compatibilityFlags = ["python_workers_development"],
);

const unitTests :Workerd.Config = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const unitTests :Workerd.Config = (
(name = "subdir/a.py", pythonModule = embed "./subdir/a.py"),
],
compatibilityDate = "2023-12-18",
compatibilityFlags = ["python_workers_development", "python_external_bundle"],
compatibilityFlags = ["python_workers_development"],
)
),
],
Expand Down
13 changes: 5 additions & 8 deletions src/workerd/server/workerd-api.c++
Original file line number Diff line number Diff line change
Expand Up @@ -537,14 +537,11 @@ 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() ||
util::Autogate::isEnabled(util::AutogateKey::PYTHON_EXTERNAL_BUNDLE)) {
auto pythonRelease = KJ_ASSERT_NONNULL(getPythonSnapshotRelease(featureFlags));
auto version = getPythonBundleName(pythonRelease);
auto bundle = KJ_ASSERT_NONNULL(
fetchPyodideBundle(impl->pythonConfig, version), "Failed to get Pyodide bundle");
modules->addBuiltinBundle(bundle, kj::none);
}
auto pythonRelease = KJ_ASSERT_NONNULL(getPythonSnapshotRelease(featureFlags));
auto version = getPythonBundleName(pythonRelease);
auto bundle = KJ_ASSERT_NONNULL(
fetchPyodideBundle(impl->pythonConfig, version), "Failed to get Pyodide bundle");
modules->addBuiltinBundle(bundle, kj::none);
// Inject pyodide bootstrap module (TODO: load this from the capnproto bundle?)
{
auto mainModule = confModules.begin();
Expand Down
2 changes: 0 additions & 2 deletions src/workerd/util/autogate.c++
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ 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::COMPILE_CACHE_FOR_BUILTINS:
return "compile-cache-for-builtins"_kj;
case AutogateKey::NumOfKeys:
Expand Down
1 change: 0 additions & 1 deletion src/workerd/util/autogate.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ namespace workerd::util {
// Workerd-specific list of autogate keys (can also be used in internal repo).
enum class AutogateKey {
TEST_WORKERD,
PYTHON_EXTERNAL_BUNDLE,
COMPILE_CACHE_FOR_BUILTINS,
NumOfKeys // Reserved for iteration.
};
Expand Down

0 comments on commit d1badf9

Please sign in to comment.