From 242abdf1b4e342af8b1329feab58dd7f3fdd96fd Mon Sep 17 00:00:00 2001 From: deepshekhardas Date: Thu, 5 Mar 2026 07:42:23 +0530 Subject: [PATCH] feat: support pyproject.toml and uv in python extension (#3118) --- packages/python/src/extension.ts | 49 ++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/packages/python/src/extension.ts b/packages/python/src/extension.ts index 53b5c2c8cf3..3f557cca381 100644 --- a/packages/python/src/extension.ts +++ b/packages/python/src/extension.ts @@ -7,6 +7,9 @@ import { BuildContext, BuildExtension } from "@trigger.dev/core/v3/build"; export type PythonOptions = { requirements?: string[]; requirementsFile?: string; + pyprojectFile?: string; + useUv?: boolean; + /** * [Dev-only] The path to the python binary. * @@ -54,6 +57,14 @@ class PythonExtension implements BuildExtension { fs.readFileSync(this.options.requirementsFile, "utf-8") ); } + + if (this.options.pyprojectFile) { + assert( + fs.existsSync(this.options.pyprojectFile), + `pyproject.toml not found: ${this.options.pyprojectFile}` + ); + } + } async onBuildComplete(context: BuildContext, manifest: BuildManifest) { @@ -88,6 +99,8 @@ class PythonExtension implements BuildExtension { # Set up Python environment RUN python3 -m venv /opt/venv ENV PATH="/opt/venv/bin:$PATH" + + ${this.options.useUv ? "RUN pip install uv" : ""} `), }, deploy: { @@ -123,7 +136,36 @@ class PythonExtension implements BuildExtension { # Copy the requirements file COPY ${this.options.requirementsFile} . # Install dependencies - RUN pip install --no-cache-dir -r ${this.options.requirementsFile} + ${this.options.useUv + ? `RUN uv pip install --no-cache -r ${this.options.requirementsFile}` + : `RUN pip install --no-cache-dir -r ${this.options.requirementsFile}` + } + `), + }, + deploy: { + override: true, + }, + }); + } else if (this.options.pyprojectFile) { + // Copy pyproject file to the container + await addAdditionalFilesToBuild( + "pythonExtension", + { + files: [this.options.pyprojectFile], + }, + context, + manifest + ); + + // Add a layer to the build that installs the dependencies + context.addLayer({ + id: "python-dependencies", + image: { + instructions: splitAndCleanComments(` + # Copy the pyproject file + COPY ${this.options.pyprojectFile} . + # Install dependencies + ${this.options.useUv ? "RUN uv pip install ." : "RUN pip install ."} `), }, deploy: { @@ -144,7 +186,10 @@ class PythonExtension implements BuildExtension { RUN echo "$REQUIREMENTS_CONTENT" > requirements.txt # Install dependencies - RUN pip install --no-cache-dir -r requirements.txt + ${this.options.useUv + ? "RUN uv pip install --no-cache -r requirements.txt" + : "RUN pip install --no-cache-dir -r requirements.txt" + } `), }, deploy: {