Skip to content
Open
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
4f8990d
remove dependency that was causing issues
abstractedfox Jun 28, 2026
3b8ea8f
Reconstitute work on this repo
abstractedfox Jun 29, 2026
96153da
Add index.py as default entry point
abstractedfox Jun 29, 2026
d651034
Start of basic package support
abstractedfox Jun 30, 2026
958f232
Python package proof of concept
abstractedfox Jul 1, 2026
98ad2f7
Clarifying comment
abstractedfox Jul 1, 2026
e01a96e
Use wheels properly
abstractedfox Jul 2, 2026
2fd4db5
Wheel changeover cleanup
abstractedfox Jul 6, 2026
248a149
Use simpler packages for minimal package support test
abstractedfox Jul 6, 2026
2ca7e73
Move python logic out of 'bundle' path
abstractedfox Jul 6, 2026
58e6874
Slight cleanup, remove test
abstractedfox Jul 6, 2026
1cf3db3
More cleanup
abstractedfox Jul 6, 2026
ceda163
Re-add parameter that was mistakenly deleted
abstractedfox Jul 7, 2026
7244ec5
Revert "remove dependency that was causing issues"
abstractedfox Jul 7, 2026
493cf55
Order deps alphabetically
abstractedfox Jul 7, 2026
4fa5fce
Remove unused variable
abstractedfox Jul 8, 2026
bf8d3a9
Make createWorker Python return more uniform with JS
abstractedfox Jul 8, 2026
6b365dd
Make createWorker registry pattern more consistent with JS
abstractedfox Jul 8, 2026
7a2a85f
Small fixes
abstractedfox Jul 8, 2026
ecbd776
Style fixes
abstractedfox Jul 10, 2026
8016a35
Remove parsing for version string
abstractedfox Jul 10, 2026
766e58c
Comment dep version parameter
abstractedfox Jul 10, 2026
40cbc98
Compensate for distribution packages' names not matching their imports
abstractedfox Jul 10, 2026
f3289dc
Remove default values from test
abstractedfox Jul 10, 2026
6fde2e0
Move Python package metadata collection into its own function
abstractedfox Jul 10, 2026
b711067
Move Py deps installation into its own function
abstractedfox Jul 10, 2026
4c56501
Account for type checker
abstractedfox Jul 10, 2026
7ade11e
Undo unintended compat date change
abstractedfox Jul 13, 2026
ca0ce79
Bump up compatibility date (test)
abstractedfox Jul 13, 2026
1a68186
Prevent adding python and JS deps to the same worker
abstractedfox Jul 13, 2026
bfcdec1
Implicitly add workers-runtime-sdk package
abstractedfox Jul 13, 2026
58b0743
Add python_workers flag if user-supplied flags exclude it
abstractedfox Jul 13, 2026
a088712
Typo
abstractedfox Jul 14, 2026
691e4cb
Clarifying comment
abstractedfox Jul 14, 2026
4740d96
Include installWarnings with returned object
abstractedfox Jul 14, 2026
dcdd6fd
Change tests to assert existence of compat flags
abstractedfox Jul 14, 2026
d6fd735
Remove redundant compat flag default
abstractedfox Jul 14, 2026
ee05c75
Mark comment as TODO
abstractedfox Jul 14, 2026
75fdf12
Change installDependenciesPython to replicate the JS impl's usage of …
abstractedfox Jul 14, 2026
79293af
Finish propagating `result` object and explicitly disable pyproject.t…
abstractedfox Jul 14, 2026
ae50567
Add more TODOs
abstractedfox Jul 14, 2026
5d45c40
Merge branch 'main' into python-packages
mattzcarey Jul 23, 2026
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
1 change: 1 addition & 0 deletions packages/worker-bundler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"@typescript/vfs": "^1.6.4",
"es-module-lexer": "^2.1.0",
"esbuild-wasm": "0.28.1",
"fflate": "^0.8.2",
"resolve.exports": "^2.0.3",
"semver": "^7.8.5",
"smol-toml": "^1.7.0",
Expand Down
29 changes: 26 additions & 3 deletions packages/worker-bundler/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { bundleWithEsbuild, bundlerOnlyOptionsWarning } from "./bundler";
import { hasNodejsCompat, parseWranglerConfig } from "./config";
import { hasDependencies, installDependencies } from "./installer";
import { transformAndResolve } from "./transformer";
import type { CreateWorkerOptions, CreateWorkerResult } from "./types";
import type { CreateWorkerOptions, CreateWorkerResult, Modules } from "./types";
import {
DEFAULT_ENTRY_POINTS,
detectEntryPoint,
Expand Down Expand Up @@ -117,7 +117,7 @@ export async function createWorker(
const wranglerConfig = parseWranglerConfig(fileSystem);
const nodejsCompat = hasNodejsCompat(wranglerConfig);

// Auto-install dependencies if package.json has dependencies
// Auto-install dependencies if package.json or pyproject.toml has dependencies
const installWarnings: string[] = [];
if (hasDependencies(fileSystem)) {
const installResult = await installDependencies(
Expand All @@ -143,6 +143,30 @@ export async function createWorker(
);
}

if (entryPoint.endsWith(".py")) {
const modules: Modules = {};
for (const path of fileSystem.list()) {
if (path === "pyproject.toml") {
continue;
}
Comment on lines +149 to +151

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Is this necessary? No one is likely to be specifying pyproject.toml in the createWorker call

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@dom96 This is the pyproject.toml that contains all the deps for the worker, so as far as I understand we do need to have it coming into createWorker

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Ahh, my mistake, for some reason I thought pyproject.toml wasn't in the "files" dict, but one level above (same for packages.json, but I just checked and it's also in the "files" dict).

All good to leave this then.

const content = fileSystem.read(path);
if (content !== null) {
modules[path] = content;
}
}
Comment on lines +148 to +156

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.

🔍 Python modules output includes all filesystem files, potentially including node_modules

The Python worker path at packages/worker-bundler/src/index.ts:148-155 iterates over all files in the filesystem (except pyproject.toml) and includes them in the output modules. If a project has both package.json with npm dependencies and a Python entry point, the installed node_modules/ tree would be included in the modules output. This could result in a very large modules object being passed to the Worker Loader. Consider filtering out node_modules/ and python_modules/ metadata directories.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

These are just files specified by the user in the createWorker call, right? So this AI review comment seems wrong.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

At that point it should be those files + all the packages that were just added, so my assumption is anything that's in there would've been put there deliberately


return {
mainModule: entryPoint,
modules,
wranglerConfig: {
compatibilityDate: wranglerConfig?.compatibilityDate ?? "2026-01-01",

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

How is this default compat date selected? How does the JS worker handle this?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I recall just choosing it as an arbitrary date that I thought would work, I can put a newer one. The JS worker as in the worker that creates the dynamic worker?

@ryanking13 ryanking13 Jul 16, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Yeah, following whatever the JS worker is doing would be a good idea.

compatibilityFlags: wranglerConfig?.compatibilityFlags ?? [

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

We will always need to add python_workers flag to make the worker work. So maybe we need to inject one if this flag does not exist?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

As in to the user-defined compatibility flags, in the event the user passed flags that didn't include python_workers? I can add that

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actually, that should no longer be needed for Python dynamic workers. You can run python dynamic workers without that flag.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@dom96 Should I remove it?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Yep

"python_workers"
]
}
};
Comment thread
abstractedfox marked this conversation as resolved.
}

if (bundle) {
// Try bundling with esbuild-wasm
const result = await bundleWithEsbuild({
Expand Down Expand Up @@ -171,7 +195,6 @@ export async function createWorker(
if (installWarnings.length > 0) {
result.warnings = [...(result.warnings ?? []), ...installWarnings];
}

return result;
} else {
// No bundling - transform files and resolve dependencies.
Expand Down
Loading
Loading