@@ -7,6 +7,9 @@ import { BuildContext, BuildExtension } from "@trigger.dev/core/v3/build";
77export type PythonOptions = {
88 requirements ?: string [ ] ;
99 requirementsFile ?: string ;
10+ pyprojectFile ?: string ;
11+ useUv ?: boolean ;
12+
1013 /**
1114 * [Dev-only] The path to the python binary.
1215 *
@@ -54,6 +57,14 @@ class PythonExtension implements BuildExtension {
5457 fs . readFileSync ( this . options . requirementsFile , "utf-8" )
5558 ) ;
5659 }
60+
61+ if ( this . options . pyprojectFile ) {
62+ assert (
63+ fs . existsSync ( this . options . pyprojectFile ) ,
64+ `pyproject.toml not found: ${ this . options . pyprojectFile } `
65+ ) ;
66+ }
67+
5768 }
5869
5970 async onBuildComplete ( context : BuildContext , manifest : BuildManifest ) {
@@ -88,6 +99,8 @@ class PythonExtension implements BuildExtension {
8899 # Set up Python environment
89100 RUN python3 -m venv /opt/venv
90101 ENV PATH="/opt/venv/bin:$PATH"
102+
103+ ${ this . options . useUv ? "RUN pip install uv" : "" }
91104 ` ) ,
92105 } ,
93106 deploy : {
@@ -123,7 +136,36 @@ class PythonExtension implements BuildExtension {
123136 # Copy the requirements file
124137 COPY ${ this . options . requirementsFile } .
125138 # Install dependencies
126- RUN pip install --no-cache-dir -r ${ this . options . requirementsFile }
139+ ${ this . options . useUv
140+ ? `RUN uv pip install --no-cache -r ${ this . options . requirementsFile } `
141+ : `RUN pip install --no-cache-dir -r ${ this . options . requirementsFile } `
142+ }
143+ ` ) ,
144+ } ,
145+ deploy : {
146+ override : true ,
147+ } ,
148+ } ) ;
149+ } else if ( this . options . pyprojectFile ) {
150+ // Copy pyproject file to the container
151+ await addAdditionalFilesToBuild (
152+ "pythonExtension" ,
153+ {
154+ files : [ this . options . pyprojectFile ] ,
155+ } ,
156+ context ,
157+ manifest
158+ ) ;
159+
160+ // Add a layer to the build that installs the dependencies
161+ context . addLayer ( {
162+ id : "python-dependencies" ,
163+ image : {
164+ instructions : splitAndCleanComments ( `
165+ # Copy the pyproject file
166+ COPY ${ this . options . pyprojectFile } .
167+ # Install dependencies
168+ ${ this . options . useUv ? "RUN uv pip install ." : "RUN pip install ." }
127169 ` ) ,
128170 } ,
129171 deploy : {
@@ -144,7 +186,10 @@ class PythonExtension implements BuildExtension {
144186 RUN echo "$REQUIREMENTS_CONTENT" > requirements.txt
145187
146188 # Install dependencies
147- RUN pip install --no-cache-dir -r requirements.txt
189+ ${ this . options . useUv
190+ ? "RUN uv pip install --no-cache -r requirements.txt"
191+ : "RUN pip install --no-cache-dir -r requirements.txt"
192+ }
148193 ` ) ,
149194 } ,
150195 deploy : {
0 commit comments