Skip to content
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
15 changes: 6 additions & 9 deletions packages/worker-bundler/src/installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import { parse as parseToml } from "smol-toml";

const NPM_REGISTRY = "https://registry.npmjs.org";
const PYPI_SIMPLE_API = "https://pypi.org/simple";
const PYODIDE_VERSION = "v0.28.2"; // Used for retrieving a pyodide lockfile, which is done per Pyodide version
// TODO: Update PYODIDE_VERSION once the patch addressing the Python version mismatch for dynamic workers is merged
const PYODIDE_VERSION = "v0.27.5"; // Used for retrieving a pyodide lockfile, which is done per Pyodide version. If incompatible wheels are being served, this may be why
Comment thread
abstractedfox marked this conversation as resolved.
const DEFAULT_TIMEOUT_MS = 30000; // 30 seconds

/**
Expand Down Expand Up @@ -961,15 +962,11 @@ function extractWheel(
continue;
}

// TODO: Remove this check once it's confirmed that compiled wasm binaries are working
// (blocking this for now so any such packages will fail gracefully in the interim)
if (!isTextFile(path)) {
result.warnings.push(
`Could not install file ${path}, extension must match an approved text format type. This may corrupt this dependency.`
);
continue;
if (isTextFile(path)) {
files[path] = textDecoder.decode(content);
} else {
files[path] = { data: new Uint8Array(content) };
}
files[path] = textDecoder.decode(content);
}

return files;
Expand Down
80 changes: 80 additions & 0 deletions packages/worker-bundler/src/tests/e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1147,6 +1147,86 @@ describe("createWorker with pyproject.toml", () => {
expect(body.typing_extensions).toBe("typing_extensions");
expect(body.typing_inspection).toBe("typing_inspection");
});

it("works with packages that include arbitrary binary files", async () => {
const id = "test-worker-" + testId++;
const createWorkerResult = await createWorker({
files: {
"index.py": [
"from workers import Response, WorkerEntrypoint",
"import certifi",
"class Default(WorkerEntrypoint):",
" async def fetch(self, request):",
" return Response.json({",
' "certifi": certifi.__name__,',
' "contents": certifi.contents()',
" })"
].join("\n"),
"pyproject.toml": [
"[project]",
'name = "dummy"',
'version = "0.0.0"',
'dependencies = ["certifi"]'
].join("\n")
},
preferPyodideIndex: true
});
const worker = env.LOADER.get(id, () => ({
mainModule: createWorkerResult.mainModule,
modules: createWorkerResult.modules,
compatibilityDate: createWorkerResult.wranglerConfig!.compatibilityDate!,
compatibilityFlags: createWorkerResult.wranglerConfig!.compatibilityFlags!
}));
const response = await worker
.getEntrypoint()
.fetch(new Request("http://worker/"));
expect(response.status).toBe(200);
const body = (await response.json()) as Record<string, unknown>;
expect(body.certifi).toBe("certifi");
expect(body.contents).toBeTruthy();
});

it("works with packages that have extensions", async () => {
const id = "test-worker-" + testId++;
const createWorkerResult = await createWorker({
files: {
"index.py": [
"from workers import Response, WorkerEntrypoint",
"import yaml",
"from yaml import _yaml",
"class Default(WorkerEntrypoint):",
" async def fetch(self, request):",
' parsed = yaml.load("hello: world", yaml.CLoader)',
" return Response.json({",
' "yaml": yaml.__name__,',
' "hasCLoader": yaml.CLoader is not None,',
' "parsed": parsed',
" })"
].join("\n"),
"pyproject.toml": [
"[project]",
'name = "dummy"',
'version = "0.0.0"',
'dependencies = ["pyyaml"]'
].join("\n")
},
preferPyodideIndex: true
});
const worker = env.LOADER.get(id, () => ({
mainModule: createWorkerResult.mainModule,
modules: createWorkerResult.modules,
compatibilityDate: createWorkerResult.wranglerConfig!.compatibilityDate!,
compatibilityFlags: createWorkerResult.wranglerConfig!.compatibilityFlags!
}));
const response = await worker
.getEntrypoint()
.fetch(new Request("http://worker/"));
expect(response.status).toBe(200);
const body = (await response.json()) as Record<string, unknown>;
expect(body.yaml).toBe("yaml");
expect(body.hasCLoader).toBe(true);
expect(body.parsed).toEqual({ hello: "world" });
});
}, 20000);

describe("comparePythonVersions", () => {
Expand Down
Loading