feat: support pyproject.toml and uv in python extension (#3118)#3177
feat: support pyproject.toml and uv in python extension (#3118)#3177deepshekhardas wants to merge 1 commit intotriggerdotdev:mainfrom
Conversation
|
|
Hi @deepshekhardas, thanks for your interest in contributing! This project requires that pull request authors are vouched, and you are not in the list of vouched users. This PR will be closed automatically. See https://github.com/triggerdotdev/trigger.dev/blob/main/CONTRIBUTING.md for more details. |
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughThe PR introduces optional UV package manager support to the Python extension. Two new configuration options are added to PythonOptions: Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
| if (this.options.pyprojectFile) { | ||
| assert( | ||
| fs.existsSync(this.options.pyprojectFile), | ||
| `pyproject.toml not found: ${this.options.pyprojectFile}` | ||
| ); | ||
| } |
There was a problem hiding this comment.
🟡 Missing mutual-exclusion validation for pyprojectFile against requirements/requirementsFile
The constructor validates that requirements and requirementsFile cannot both be specified (line 46-48), but pyprojectFile is never checked against either option. Because onBuildComplete uses an if/else if chain (requirementsFile → pyprojectFile → requirements), conflicting combinations are silently resolved by priority rather than flagged as errors. For example, passing { pyprojectFile: "pyproject.toml", requirementsFile: "requirements.txt" } silently ignores pyprojectFile, and passing { pyprojectFile: "pyproject.toml", requirements: ["numpy"] } silently ignores requirements. This is inconsistent with the existing assertion pattern that explicitly rejects conflicting options.
| if (this.options.pyprojectFile) { | |
| assert( | |
| fs.existsSync(this.options.pyprojectFile), | |
| `pyproject.toml not found: ${this.options.pyprojectFile}` | |
| ); | |
| } | |
| if (this.options.pyprojectFile) { | |
| assert( | |
| !(this.options.requirements || this.options.requirementsFile), | |
| "Cannot specify pyprojectFile together with requirements or requirementsFile" | |
| ); | |
| assert( | |
| fs.existsSync(this.options.pyprojectFile), | |
| `pyproject.toml not found: ${this.options.pyprojectFile}` | |
| ); | |
| } |
Was this helpful? React with 👍 or 👎 to provide feedback.
| // 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 ."} |
There was a problem hiding this comment.
🚩 pip install . with only pyproject.toml may fail at Docker build time
When using the pyprojectFile path (line 149-174), only the pyproject.toml file itself is copied into the container via addAdditionalFilesToBuild. The subsequent RUN pip install . (or uv pip install .) expects a full installable Python package directory — at minimum the source code referenced by the pyproject config. Unless the user also copies the rest of their project via the scripts option or another mechanism, this Docker layer will fail at build time. This isn't necessarily a code bug (the user controls what gets copied), but the ergonomics are surprising — most users would expect pyprojectFile to "just work" like requirementsFile does. Consider documenting this requirement or automatically including sibling files.
Was this helpful? React with 👍 or 👎 to provide feedback.
Summary
Modern Python projects are increasingly adopting
pyproject.tomlfor dependency management and project configuration, often using faster tools likeuv. The current Trigger.dev Python extension only supportsrequirements.txtor inline requirements.This PR adds support for
pyproject.tomland the optional use of theuvpackage manager during the build process.Closes #3118
Changes
pyprojectFileanduseUvtoPythonOptions.uvifuseUvis set totrue.pyproject.tomlfor dependency installation (pip install .oruv pip install .).requirements.txtor inline requirements withuvsupport if enabled.Testing
uvinstallation and usage instructions are correctly injected into the build layers.