Skip to content

Conversation

dom96
Copy link
Contributor

@dom96 dom96 commented Oct 8, 2025

Implements a new python_modules_excludes wrangler config field. The user can specify a list of globs in that field to exclude them from being vendored. By default every file in python_modules is included but for certain packages they contain so much stuff that sometimes it's good to be able to filter it out, especially since our bundle sizes are limited.



Test Plan

pnpm run test --filter wrangler -- -t "should print vendor modules correctly in table" src/__tests__/deploy.test.ts

cd packages/wrangler/
pnpm run build
pnpm test:e2e --run --testNamePattern="can exclude vendored module during"

Copy link

changeset-bot bot commented Oct 8, 2025

🦋 Changeset detected

Latest commit: 93c0915

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

pkg-pr-new bot commented Oct 8, 2025

create-cloudflare

npm i https://pkg.pr.new/create-cloudflare@10927

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/@cloudflare/kv-asset-handler@10927

miniflare

npm i https://pkg.pr.new/miniflare@10927

@cloudflare/pages-shared

npm i https://pkg.pr.new/@cloudflare/pages-shared@10927

@cloudflare/unenv-preset

npm i https://pkg.pr.new/@cloudflare/unenv-preset@10927

@cloudflare/vite-plugin

npm i https://pkg.pr.new/@cloudflare/vite-plugin@10927

@cloudflare/vitest-pool-workers

npm i https://pkg.pr.new/@cloudflare/vitest-pool-workers@10927

@cloudflare/workers-editor-shared

npm i https://pkg.pr.new/@cloudflare/workers-editor-shared@10927

wrangler

npm i https://pkg.pr.new/wrangler@10927

commit: 93c0915

@dom96 dom96 force-pushed the dominik/customise-python-modules branch 2 times, most recently from 63ae386 to 466f746 Compare October 9, 2025 10:33
@dom96 dom96 marked this pull request as ready for review October 9, 2025 10:44
@dom96 dom96 requested a review from a team as a code owner October 9, 2025 10:44
@dom96 dom96 force-pushed the dominik/customise-python-modules branch from 466f746 to fbade0e Compare October 9, 2025 11:43
@dom96 dom96 requested a review from hoodmane October 9, 2025 12:36
Copy link
Contributor

@hoodmane hoodmane left a comment

Choose a reason for hiding this comment

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

Looks very reasonable to me. Thanks @dom96!

@dom96 dom96 force-pushed the dominik/customise-python-modules branch 3 times, most recently from 23af335 to dd3cd86 Compare October 14, 2025 17:00
Copy link
Contributor

@vicb vicb left a comment

Choose a reason for hiding this comment

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

I am chiming in there because rules / find_additional_modules is something that is very hard to grasp for the users (and for me TBH).

I'm afraid that adding one more config that is Python specific would make things even more confusing.

Because we already have rules, couldn't we have a concept of exlcude rules, i.e. adding {exclude: true} and it would apply for any language?

@dom96
Copy link
Contributor Author

dom96 commented Oct 14, 2025

That's a fair point and I agree that all these options are challenging to understand.

I'd love to reuse find_additional_modules+rules here, but the problem is that the python_modules directory is outside the base_dir. Typically base_dir is set to ./src because that's where the source code lives. Whereas python_modules is at ./python_modules, so rules doesn't apply to it. Indeed, we have our own custom logic to include these files in findAdditionalModules.

Our pywrangler tool vendors the packages defined in a Worker's pyproject.toml file and it always creates the python_modules directory alongside pyproject.toml (and wrangler.toml/.jsonc). I suppose we could read the wrangler config file to grab its main and/or base_dir, then put the python_modules in the base_dir and treat these modules just like any other additional modules. We'd still need to define a default list of rules to add these modules, and then I think the problem would be that the user might accidentally override them without intending to when providing their own modules.

These modules are in some ways special, as they should always be implicitly included when present and wrangler should avoid printing out the full list of them (we have code that condenses these in the "Attaching additional modules" output).

So I think from that perspective allowing users to exclude certain modules explicitly makes sense. But maybe you have another idea of what might work better?

@dom96
Copy link
Contributor Author

dom96 commented Oct 15, 2025

Another alternative is to do what was implemented here #10929, though that behaviour is a lot more subtle

@dom96 dom96 force-pushed the dominik/customise-python-modules branch from dd3cd86 to 9aaf849 Compare October 16, 2025 16:47
@dom96 dom96 force-pushed the dominik/customise-python-modules branch from 9aaf849 to 93c0915 Compare October 16, 2025 16:48
@jamesopstad
Copy link
Contributor

Discussed this with @petebacondarwin and we would prefer that Python specific configuration has its own section in the config rather than being mixed together with other top-level properties. How about the following?

{
  "python": {
    "include": [],
    "exclude": []
  }
}

You can just have exclude for now if include is not needed. Thanks.

@petebacondarwin
Copy link
Contributor

Discussed this with @petebacondarwin and we would prefer that Python specific configuration has its own section in the config rather than being mixed together with other top-level properties. How about the following?

Or python_modules

@dom96
Copy link
Contributor Author

dom96 commented Oct 17, 2025

Sounds good, I'll add a new python_modules section for this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Untriaged

Development

Successfully merging this pull request may close these issues.

5 participants