|
1 | 1 | import fs from "node:fs"; |
2 | 2 | import assert from "node:assert"; |
3 | | -import { additionalFiles } from "./core/additionalFiles.js"; |
| 3 | +import { additionalFiles } from "@trigger.dev/build/extensions/core"; |
4 | 4 | import { BuildManifest } from "@trigger.dev/core/v3"; |
5 | 5 | import { BuildContext, BuildExtension } from "@trigger.dev/core/v3/build"; |
6 | | -import { logger } from "@trigger.dev/sdk/v3"; |
7 | | -import { x, Options as XOptions, Result } from "tinyexec"; |
8 | 6 |
|
9 | 7 | export type PythonOptions = { |
10 | 8 | requirements?: string[]; |
@@ -118,61 +116,4 @@ class PythonExtension implements BuildExtension { |
118 | 116 | } |
119 | 117 | } |
120 | 118 |
|
121 | | -export const run = async ( |
122 | | - scriptArgs: string[] = [], |
123 | | - options: Partial<XOptions> = {} |
124 | | -): Promise<Result> => { |
125 | | - const pythonBin = process.env.PYTHON_BIN_PATH || "python"; |
126 | | - |
127 | | - return await logger.trace("Python call", async (span) => { |
128 | | - span.addEvent("Properties", { |
129 | | - command: `${pythonBin} ${scriptArgs.join(" ")}`, |
130 | | - }); |
131 | | - |
132 | | - const result = await x(pythonBin, scriptArgs, { |
133 | | - ...options, |
134 | | - throwOnError: false, // Ensure errors are handled manually |
135 | | - }); |
136 | | - |
137 | | - span.addEvent("Output", { ...result }); |
138 | | - |
139 | | - if (result.exitCode !== 0) { |
140 | | - logger.error(result.stderr, { ...result }); |
141 | | - throw new Error(`Python command exited with non-zero code ${result.exitCode}`); |
142 | | - } |
143 | | - |
144 | | - return result; |
145 | | - }); |
146 | | -}; |
147 | | - |
148 | | -export const runScript = ( |
149 | | - scriptPath: string, |
150 | | - scriptArgs: string[] = [], |
151 | | - options: Partial<XOptions> = {} |
152 | | -) => { |
153 | | - assert(scriptPath, "Script path is required"); |
154 | | - assert(fs.existsSync(scriptPath), `Script does not exist: ${scriptPath}`); |
155 | | - |
156 | | - return run([scriptPath, ...scriptArgs], options); |
157 | | -}; |
158 | | - |
159 | | -export const runInline = async (scriptContent: string, options: Partial<XOptions> = {}) => { |
160 | | - assert(scriptContent, "Script content is required"); |
161 | | - |
162 | | - const tmpFile = `/tmp/script_${Date.now()}.py`; |
163 | | - await fs.promises.writeFile(tmpFile, scriptContent, { mode: 0o600 }); |
164 | | - |
165 | | - try { |
166 | | - return await runScript(tmpFile, [], options); |
167 | | - } finally { |
168 | | - try { |
169 | | - await fs.promises.unlink(tmpFile); |
170 | | - } catch (error) { |
171 | | - logger.warn(`Failed to clean up temporary file ${tmpFile}:`, { |
172 | | - error: (error as Error).stack || (error as Error).message, |
173 | | - }); |
174 | | - } |
175 | | - } |
176 | | -}; |
177 | | - |
178 | | -export default { run, runScript, runInline }; |
| 119 | +export default pythonExtension; |
0 commit comments