@trigger.dev/python 0.0.0-python-preview-20250226140121 → 3.3.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -14,7 +14,7 @@ This extension introduces the <code>pythonExtension</code> build extension, whic
14
14
  - <code>run</code>: Executes Python commands with proper environment setup.
15
15
  - <code>runInline</code>: Executes inline Python code directly from Node.
16
16
  - <code>runScript</code>: Executes standalone <code>.py</code> script files.
17
- - **Custom Python Path:** In development, you can configure <code>pythonBinaryPath</code> to point to a custom Python installation.
17
+ - **Custom Python Path:** In development, you can configure <code>devPythonBinaryPath</code> to point to a custom Python installation.
18
18
 
19
19
  ## Usage
20
20
 
@@ -22,7 +22,7 @@ This extension introduces the <code>pythonExtension</code> build extension, whic
22
22
 
23
23
  ```typescript
24
24
  import { defineConfig } from "@trigger.dev/sdk/v3";
25
- import pythonExtension from "@trigger.dev/python/extension";
25
+ import { pythonExtension } from "@trigger.dev/python/extension";
26
26
 
27
27
  export default defineConfig({
28
28
  project: "<project ref>",
@@ -30,8 +30,8 @@ export default defineConfig({
30
30
  extensions: [
31
31
  pythonExtension({
32
32
  requirementsFile: "./requirements.txt", // Optional: Path to your requirements file
33
- pythonBinaryPath: path.join(rootDir, `.venv/bin/python`), // Optional: Custom Python binary path
34
- scripts: ["my_script.py"], // List of Python scripts to include
33
+ devPythonBinaryPath: ".venv/bin/python", // Optional: Custom Python binary path
34
+ scripts: ["src/python/**/*.py"], // Glob pattern for Python scripts
35
35
  }),
36
36
  ],
37
37
  },
@@ -40,13 +40,34 @@ export default defineConfig({
40
40
 
41
41
  2. (Optional) Create a <code>requirements.txt</code> file in your project root with the necessary Python dependencies.
42
42
 
43
+ ```plaintext title="requirements.txt"
44
+ pandas==1.3.3
45
+ numpy==1.21.2
46
+ ```
47
+
48
+ ```typescript title="trigger.config.ts"
49
+ import { defineConfig } from "@trigger.dev/sdk/v3";
50
+ import { pythonExtension } from "@trigger.dev/python/extension";
51
+
52
+ export default defineConfig({
53
+ project: "<project ref>",
54
+ build: {
55
+ extensions: [
56
+ pythonExtension({
57
+ requirementsFile: "./requirements.txt",
58
+ }),
59
+ ],
60
+ },
61
+ });
62
+ ```
63
+
43
64
  3. Execute Python scripts within your tasks using one of the provided functions:
44
65
 
45
66
  ### Running a Python Script
46
67
 
47
68
  ```typescript
48
69
  import { task } from "@trigger.dev/sdk/v3";
49
- import python from "@trigger.dev/python";
70
+ import { python } from "@trigger.dev/python";
50
71
 
51
72
  export const myScript = task({
52
73
  id: "my-python-script",
@@ -55,13 +76,29 @@ export const myScript = task({
55
76
  return result.stdout;
56
77
  },
57
78
  });
79
+
80
+ export const myStreamingScript = task({
81
+ id: "my-streaming-python-script",
82
+ run: async () => {
83
+ // You can also stream the output of the script
84
+ const result = python.stream.runScript("my_script.py", ["hello", "world"]);
85
+
86
+ // result is an async iterable/readable stream
87
+ for await (const chunk of streamingResult) {
88
+ logger.debug("convert-url-to-markdown", {
89
+ url: payload.url,
90
+ chunk,
91
+ });
92
+ }
93
+ },
94
+ });
58
95
  ```
59
96
 
60
97
  ### Running Inline Python Code
61
98
 
62
99
  ```typescript
63
100
  import { task } from "@trigger.dev/sdk/v3";
64
- import python from "@trigger.dev/python";
101
+ import { python } from "@trigger.dev/python";
65
102
 
66
103
  export const myTask = task({
67
104
  id: "to_datetime-task",
@@ -69,7 +106,7 @@ export const myTask = task({
69
106
  const result = await python.runInline(`
70
107
  import pandas as pd
71
108
 
72
- pandas.to_datetime("${+new Date() / 1000}")
109
+ pd.to_datetime("${+new Date() / 1000}")
73
110
  `);
74
111
  return result.stdout;
75
112
  },
@@ -80,7 +117,7 @@ pandas.to_datetime("${+new Date() / 1000}")
80
117
 
81
118
  ```typescript
82
119
  import { task } from "@trigger.dev/sdk/v3";
83
- import python from "@trigger.dev/python";
120
+ import { python } from "@trigger.dev/python";
84
121
 
85
122
  export const pythonVersionTask = task({
86
123
  id: "python-version-task",
@@ -94,7 +131,6 @@ export const pythonVersionTask = task({
94
131
  ## Limitations
95
132
 
96
133
  - This is a **partial implementation** and does not provide full Python support as an execution runtime for tasks.
97
- - Only basic Python script execution is supported; scripts are not automatically copied to staging/production containers.
98
134
  - Manual intervention may be required for installing and configuring binary dependencies in development environments.
99
135
 
100
136
  ## Additional Information
@@ -11,7 +11,7 @@ export type PythonOptions = {
11
11
  *
12
12
  * Example: `/usr/bin/python3` or `C:\\Python39\\python.exe`
13
13
  */
14
- pythonBinaryPath?: string;
14
+ devPythonBinaryPath?: string;
15
15
  /**
16
16
  * An array of glob patterns that specify which Python scripts are allowed to be executed.
17
17
  *
@@ -21,4 +21,3 @@ export type PythonOptions = {
21
21
  scripts?: string[];
22
22
  };
23
23
  export declare function pythonExtension(options?: PythonOptions): BuildExtension;
24
- export default pythonExtension;
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.pythonExtension = pythonExtension;
7
7
  const node_fs_1 = __importDefault(require("node:fs"));
8
8
  const node_assert_1 = __importDefault(require("node:assert"));
9
- const core_1 = require("@trigger.dev/build/extensions/core");
9
+ const internal_1 = require("@trigger.dev/build/internal");
10
10
  const splitAndCleanComments = (str) => str
11
11
  .split("\n")
12
12
  .map((line) => line.trim())
@@ -26,12 +26,12 @@ class PythonExtension {
26
26
  }
27
27
  }
28
28
  async onBuildComplete(context, manifest) {
29
- await (0, core_1.additionalFiles)({
29
+ await (0, internal_1.addAdditionalFilesToBuild)("pythonExtension", {
30
30
  files: this.options.scripts ?? [],
31
- }).onBuildComplete(context, manifest);
31
+ }, context, manifest);
32
32
  if (context.target === "dev") {
33
- if (this.options.pythonBinaryPath) {
34
- process.env.PYTHON_BIN_PATH = this.options.pythonBinaryPath;
33
+ if (this.options.devPythonBinaryPath) {
34
+ process.env.PYTHON_BIN_PATH = this.options.devPythonBinaryPath;
35
35
  }
36
36
  return;
37
37
  }
@@ -57,27 +57,52 @@ class PythonExtension {
57
57
  override: true,
58
58
  },
59
59
  });
60
- context.addLayer({
61
- id: "python-dependencies",
62
- build: {
63
- env: {
64
- REQUIREMENTS_CONTENT: this.options.requirements?.join("\n") || "",
60
+ if (this.options.requirementsFile) {
61
+ if (this.options.requirements) {
62
+ context.logger.warn(`[pythonExtension] Both options.requirements and options.requirementsFile are specified. requirements will be ignored.`);
63
+ }
64
+ // Copy requirements file to the container
65
+ await (0, internal_1.addAdditionalFilesToBuild)("pythonExtension", {
66
+ files: [this.options.requirementsFile],
67
+ }, context, manifest);
68
+ // Add a layer to the build that installs the requirements
69
+ context.addLayer({
70
+ id: "python-dependencies",
71
+ image: {
72
+ instructions: splitAndCleanComments(`
73
+ # Copy the requirements file
74
+ COPY ${this.options.requirementsFile} .
75
+ # Install dependencies
76
+ RUN pip install --no-cache-dir -r ${this.options.requirementsFile}
77
+ `),
65
78
  },
66
- },
67
- image: {
68
- instructions: splitAndCleanComments(`
79
+ deploy: {
80
+ override: true,
81
+ },
82
+ });
83
+ }
84
+ else if (this.options.requirements) {
85
+ context.addLayer({
86
+ id: "python-dependencies",
87
+ build: {
88
+ env: {
89
+ REQUIREMENTS_CONTENT: this.options.requirements?.join("\n") || "",
90
+ },
91
+ },
92
+ image: {
93
+ instructions: splitAndCleanComments(`
69
94
  ARG REQUIREMENTS_CONTENT
70
95
  RUN echo "$REQUIREMENTS_CONTENT" > requirements.txt
71
96
 
72
97
  # Install dependencies
73
98
  RUN pip install --no-cache-dir -r requirements.txt
74
99
  `),
75
- },
76
- deploy: {
77
- override: true,
78
- },
79
- });
100
+ },
101
+ deploy: {
102
+ override: true,
103
+ },
104
+ });
105
+ }
80
106
  }
81
107
  }
82
- exports.default = pythonExtension;
83
108
  //# sourceMappingURL=extension.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"extension.js","sourceRoot":"","sources":["../../src/extension.ts"],"names":[],"mappings":";;;;;AAkCA,0CAEC;AApCD,sDAAyB;AACzB,8DAAiC;AACjC,6DAAqE;AA0BrE,MAAM,qBAAqB,GAAG,CAAC,GAAW,E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qBAClE;iBACF;gBACD,KAAK,EAAE;oBACL,YAAY,EAAE,qBAAqB,CAAC;;;;;;SAMrC,CAAC;iBACD;gBACD,MAAM,EAAE;oBACN,QAAQ,EAAE,IAAI;iBACf;aACF,CAAC,CAAC;QACL,CAAC;IACH,CAAC;CACF"}
@@ -1,10 +1,17 @@
1
- import { Options as XOptions, Result } from "tinyexec";
2
- export declare const run: (scriptArgs?: string[], options?: Partial<XOptions>) => Promise<Result>;
3
- export declare const runScript: (scriptPath: string, scriptArgs?: string[], options?: Partial<XOptions>) => Promise<Result>;
4
- export declare const runInline: (scriptContent: string, options?: Partial<XOptions>) => Promise<import("tinyexec").Output>;
5
- declare const _default: {
6
- run: (scriptArgs?: string[], options?: Partial<XOptions>) => Promise<Result>;
7
- runScript: (scriptPath: string, scriptArgs?: string[], options?: Partial<XOptions>) => Promise<Result>;
8
- runInline: (scriptContent: string, options?: Partial<XOptions>) => Promise<import("tinyexec").Output>;
1
+ import { AsyncIterableStream } from "@trigger.dev/core/v3";
2
+ import { Result, Options as XOptions } from "tinyexec";
3
+ export type PythonExecOptions = Partial<XOptions> & {
4
+ env?: {
5
+ [key: string]: string | undefined;
6
+ };
7
+ };
8
+ export declare const python: {
9
+ run(scriptArgs?: string[], options?: PythonExecOptions): Promise<Result>;
10
+ runScript(scriptPath: string, scriptArgs?: string[], options?: PythonExecOptions): Promise<Result>;
11
+ runInline(scriptContent: string, options?: PythonExecOptions): Promise<Result>;
12
+ stream: {
13
+ run(scriptArgs?: string[], options?: PythonExecOptions): AsyncIterableStream<string>;
14
+ runScript(scriptPath: string, scriptArgs?: string[], options?: PythonExecOptions): AsyncIterableStream<string>;
15
+ runInline(scriptContent: string, options?: PythonExecOptions): AsyncIterableStream<string>;
16
+ };
9
17
  };
10
- export default _default;
@@ -3,54 +3,204 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.runInline = exports.runScript = exports.run = void 0;
7
- const node_fs_1 = __importDefault(require("node:fs"));
6
+ exports.python = void 0;
7
+ const v3_1 = require("@trigger.dev/core/v3");
8
+ const v3_2 = require("@trigger.dev/sdk/v3");
8
9
  const node_assert_1 = __importDefault(require("node:assert"));
9
- const v3_1 = require("@trigger.dev/sdk/v3");
10
+ const node_fs_1 = __importDefault(require("node:fs"));
10
11
  const tinyexec_1 = require("tinyexec");
11
- const run = async (scriptArgs = [], options = {}) => {
12
- const pythonBin = process.env.PYTHON_BIN_PATH || "python";
13
- return await v3_1.logger.trace("Python call", async (span) => {
14
- span.addEvent("Properties", {
15
- command: `${pythonBin} ${scriptArgs.join(" ")}`,
12
+ const tempFiles_js_1 = require("./utils/tempFiles.js");
13
+ exports.python = {
14
+ async run(scriptArgs = [], options = {}) {
15
+ const pythonBin = process.env.PYTHON_BIN_PATH || "python";
16
+ return await v3_2.logger.trace("python.run()", async (span) => {
17
+ const result = await (0, tinyexec_1.x)(pythonBin, scriptArgs, {
18
+ ...options,
19
+ nodeOptions: {
20
+ ...(options.nodeOptions || {}),
21
+ env: {
22
+ ...process.env,
23
+ ...options.env,
24
+ },
25
+ },
26
+ throwOnError: false, // Ensure errors are handled manually
27
+ });
28
+ if (result.exitCode) {
29
+ span.setAttribute("exitCode", result.exitCode);
30
+ }
31
+ if (result.exitCode !== 0) {
32
+ throw new Error(`${scriptArgs.join(" ")} exited with a non-zero code ${result.exitCode}:\n${result.stderr}`);
33
+ }
34
+ return result;
35
+ }, {
36
+ attributes: {
37
+ pythonBin,
38
+ args: scriptArgs.join(" "),
39
+ [v3_1.SemanticInternalAttributes.STYLE_ICON]: "brand-python",
40
+ },
41
+ });
42
+ },
43
+ async runScript(scriptPath, scriptArgs = [], options = {}) {
44
+ (0, node_assert_1.default)(scriptPath, "Script path is required");
45
+ (0, node_assert_1.default)(node_fs_1.default.existsSync(scriptPath), `Script does not exist: ${scriptPath}`);
46
+ return await v3_2.logger.trace("python.runScript()", async (span) => {
47
+ span.setAttribute("scriptPath", scriptPath);
48
+ const result = await (0, tinyexec_1.x)(process.env.PYTHON_BIN_PATH || "python", [scriptPath, ...scriptArgs], {
49
+ ...options,
50
+ nodeOptions: {
51
+ ...(options.nodeOptions || {}),
52
+ env: {
53
+ ...process.env,
54
+ ...options.env,
55
+ },
56
+ },
57
+ throwOnError: false,
58
+ });
59
+ if (result.exitCode) {
60
+ span.setAttribute("exitCode", result.exitCode);
61
+ }
62
+ if (result.exitCode !== 0) {
63
+ throw new Error(`${scriptPath} ${scriptArgs.join(" ")} exited with a non-zero code ${result.exitCode}:\n${result.stderr}`);
64
+ }
65
+ return result;
66
+ }, {
67
+ attributes: {
68
+ pythonBin: process.env.PYTHON_BIN_PATH || "python",
69
+ scriptPath,
70
+ args: scriptArgs.join(" "),
71
+ [v3_1.SemanticInternalAttributes.STYLE_ICON]: "brand-python",
72
+ },
16
73
  });
17
- const result = await (0, tinyexec_1.x)(pythonBin, scriptArgs, {
18
- ...options,
19
- throwOnError: false, // Ensure errors are handled manually
74
+ },
75
+ async runInline(scriptContent, options = {}) {
76
+ (0, node_assert_1.default)(scriptContent, "Script content is required");
77
+ return await v3_2.logger.trace("python.runInline()", async (span) => {
78
+ span.setAttribute("contentLength", scriptContent.length);
79
+ // Using the withTempFile utility to handle the temporary file
80
+ return await (0, tempFiles_js_1.withTempFile)(`script_${Date.now()}.py`, async (tempFilePath) => {
81
+ span.setAttribute("tempFilePath", tempFilePath);
82
+ const pythonBin = process.env.PYTHON_BIN_PATH || "python";
83
+ const result = await (0, tinyexec_1.x)(pythonBin, [tempFilePath], {
84
+ ...options,
85
+ nodeOptions: {
86
+ ...(options.nodeOptions || {}),
87
+ env: {
88
+ ...process.env,
89
+ ...options.env,
90
+ },
91
+ },
92
+ throwOnError: false,
93
+ });
94
+ if (result.exitCode) {
95
+ span.setAttribute("exitCode", result.exitCode);
96
+ }
97
+ if (result.exitCode !== 0) {
98
+ throw new Error(`Inline script exited with a non-zero code ${result.exitCode}:\n${result.stderr}`);
99
+ }
100
+ return result;
101
+ }, scriptContent);
102
+ }, {
103
+ attributes: {
104
+ pythonBin: process.env.PYTHON_BIN_PATH || "python",
105
+ contentPreview: scriptContent.substring(0, 100) + (scriptContent.length > 100 ? "..." : ""),
106
+ [v3_1.SemanticInternalAttributes.STYLE_ICON]: "brand-python",
107
+ },
20
108
  });
21
- span.addEvent("Output", { ...result });
22
- if (result.exitCode !== 0) {
23
- v3_1.logger.error(result.stderr, { ...result });
24
- throw new Error(`Python command exited with non-zero code ${result.exitCode}`);
25
- }
26
- return result;
27
- });
28
- };
29
- exports.run = run;
30
- const runScript = (scriptPath, scriptArgs = [], options = {}) => {
31
- (0, node_assert_1.default)(scriptPath, "Script path is required");
32
- (0, node_assert_1.default)(node_fs_1.default.existsSync(scriptPath), `Script does not exist: ${scriptPath}`);
33
- return (0, exports.run)([scriptPath, ...scriptArgs], options);
34
- };
35
- exports.runScript = runScript;
36
- const runInline = async (scriptContent, options = {}) => {
37
- (0, node_assert_1.default)(scriptContent, "Script content is required");
38
- const tmpFile = `/tmp/script_${Date.now()}.py`;
39
- await node_fs_1.default.promises.writeFile(tmpFile, scriptContent, { mode: 0o600 });
40
- try {
41
- return await (0, exports.runScript)(tmpFile, [], options);
42
- }
43
- finally {
44
- try {
45
- await node_fs_1.default.promises.unlink(tmpFile);
46
- }
47
- catch (error) {
48
- v3_1.logger.warn(`Failed to clean up temporary file ${tmpFile}:`, {
49
- error: error.stack || error.message,
50
- });
51
- }
52
- }
109
+ },
110
+ // Stream namespace for streaming functions
111
+ stream: {
112
+ run(scriptArgs = [], options = {}) {
113
+ const pythonBin = process.env.PYTHON_BIN_PATH || "python";
114
+ const pythonProcess = (0, tinyexec_1.x)(pythonBin, scriptArgs, {
115
+ ...options,
116
+ nodeOptions: {
117
+ ...(options.nodeOptions || {}),
118
+ env: {
119
+ ...process.env,
120
+ ...options.env,
121
+ },
122
+ },
123
+ throwOnError: false,
124
+ });
125
+ const span = v3_2.logger.startSpan("python.stream.run()", {
126
+ attributes: {
127
+ pythonBin,
128
+ args: scriptArgs.join(" "),
129
+ [v3_1.SemanticInternalAttributes.STYLE_ICON]: "brand-python",
130
+ },
131
+ });
132
+ return (0, v3_1.createAsyncIterableStreamFromAsyncIterable)(pythonProcess, {
133
+ transform: (chunk, controller) => {
134
+ controller.enqueue(chunk);
135
+ },
136
+ flush: () => {
137
+ span.end();
138
+ },
139
+ });
140
+ },
141
+ runScript(scriptPath, scriptArgs = [], options = {}) {
142
+ (0, node_assert_1.default)(scriptPath, "Script path is required");
143
+ (0, node_assert_1.default)(node_fs_1.default.existsSync(scriptPath), `Script does not exist: ${scriptPath}`);
144
+ const pythonBin = process.env.PYTHON_BIN_PATH || "python";
145
+ const pythonProcess = (0, tinyexec_1.x)(pythonBin, [scriptPath, ...scriptArgs], {
146
+ ...options,
147
+ nodeOptions: {
148
+ ...(options.nodeOptions || {}),
149
+ env: {
150
+ ...process.env,
151
+ ...options.env,
152
+ },
153
+ },
154
+ throwOnError: false,
155
+ });
156
+ const span = v3_2.logger.startSpan("python.stream.runScript()", {
157
+ attributes: {
158
+ pythonBin,
159
+ scriptPath,
160
+ args: scriptArgs.join(" "),
161
+ [v3_1.SemanticInternalAttributes.STYLE_ICON]: "brand-python",
162
+ },
163
+ });
164
+ return (0, v3_1.createAsyncIterableStreamFromAsyncIterable)(pythonProcess, {
165
+ transform: (chunk, controller) => {
166
+ controller.enqueue(chunk);
167
+ },
168
+ flush: () => {
169
+ span.end();
170
+ },
171
+ });
172
+ },
173
+ runInline(scriptContent, options = {}) {
174
+ (0, node_assert_1.default)(scriptContent, "Script content is required");
175
+ const pythonBin = process.env.PYTHON_BIN_PATH || "python";
176
+ const pythonScriptPath = (0, tempFiles_js_1.createTempFileSync)(`script_${Date.now()}.py`, scriptContent);
177
+ const pythonProcess = (0, tinyexec_1.x)(pythonBin, [pythonScriptPath], {
178
+ ...options,
179
+ nodeOptions: {
180
+ ...(options.nodeOptions || {}),
181
+ env: {
182
+ ...process.env,
183
+ ...options.env,
184
+ },
185
+ },
186
+ throwOnError: false,
187
+ });
188
+ const span = v3_2.logger.startSpan("python.stream.runInline()", {
189
+ attributes: {
190
+ pythonBin,
191
+ contentPreview: scriptContent.substring(0, 100) + (scriptContent.length > 100 ? "..." : ""),
192
+ [v3_1.SemanticInternalAttributes.STYLE_ICON]: "brand-python",
193
+ },
194
+ });
195
+ return (0, v3_1.createAsyncIterableStreamFromAsyncIterable)(pythonProcess, {
196
+ transform: (chunk, controller) => {
197
+ controller.enqueue(chunk);
198
+ },
199
+ flush: () => {
200
+ span.end();
201
+ },
202
+ });
203
+ },
204
+ },
53
205
  };
54
- exports.runInline = runInline;
55
- exports.default = { run: exports.run, runScript: exports.runScript, runInline: exports.runInline };
56
206
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,sDAAyB;AACzB,8DAAiC;AACjC,4CAA6C;AAC7C,uCAA0D;AAEnD,MAAM,GAAG,GAAG,KAAK,EACtB,aAAuB,EAAE,EACzB,UAA6B,EAAE,EACd,EAAE;IACnB,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,eAAe,IAAI,QAAQ,CAAC;IAE1D,OAAO,MAAM,WAAM,CAAC,KAAK,CAAC,aAAa,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE;QACtD,IAAI,CAAC,QAAQ,CAAC,YAAY,EAAE;YAC1B,OAAO,EAAE,GAAG,SAAS,IAAI,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE;SAChD,CAAC,CAAC;QAEH,MAAM,MAAM,GAAG,MAAM,IAAA,YAAC,EAAC,SAAS,EAAE,UAAU,EAAE;YAC5C,GAAG,OAAO;YACV,YAAY,EAAE,KAAK,EAAE,qCAAqC;SAC3D,CAAC,CAAC;QAEH,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,EAAE,G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,GAAG,CAAC,aAAa,CAAC,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;oBAC7E,CAAC,+BAA0B,CAAC,UAAU,CAAC,EAAE,cAAc;iBACxD;aACF,CAAC,CAAC;YAEH,OAAO,IAAA,+CAA0C,EAAC,aAAa,EAAE;gBAC/D,SAAS,EAAE,CAAC,KAAK,EAAE,UAAU,EAAE,EAAE;oBAC/B,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;gBAC5B,CAAC;gBACD,KAAK,EAAE,GAAG,EAAE;oBACV,IAAI,CAAC,GAAG,EAAE,CAAC;gBACb,CAAC;aACF,CAAC,CAAC;QACL,CAAC;KACF;CACF,CAAC"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Creates a temporary file with a custom filename, passes it to the callback function, and ensures cleanup
3
+ * @param filename The filename to use for the temporary file
4
+ * @param callback Function that receives the path to the temporary file
5
+ * @param content Optional content to write to the file
6
+ * @returns Whatever the callback returns
7
+ */
8
+ export declare function withTempFile<T>(filename: string, callback: (filePath: string) => Promise<T>, content?: string | Buffer): Promise<T>;
9
+ export declare function createTempFileSync(filename: string, content?: string | Buffer): string;
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.withTempFile = withTempFile;
4
+ exports.createTempFileSync = createTempFileSync;
5
+ const node_fs_1 = require("node:fs");
6
+ const promises_1 = require("node:fs/promises");
7
+ const node_os_1 = require("node:os");
8
+ const node_path_1 = require("node:path");
9
+ /**
10
+ * Creates a temporary file with a custom filename, passes it to the callback function, and ensures cleanup
11
+ * @param filename The filename to use for the temporary file
12
+ * @param callback Function that receives the path to the temporary file
13
+ * @param content Optional content to write to the file
14
+ * @returns Whatever the callback returns
15
+ */
16
+ async function withTempFile(filename, callback, content = "") {
17
+ // Create temporary directory with random suffix
18
+ const tempDir = await (0, promises_1.mkdtemp)((0, node_path_1.join)((0, node_os_1.tmpdir)(), "app-"));
19
+ const tempFile = (0, node_path_1.join)(tempDir, filename);
20
+ try {
21
+ // Write to the temporary file with appropriate permissions
22
+ await (0, promises_1.writeFile)(tempFile, content, { mode: 0o600 });
23
+ // Use the file
24
+ return await callback(tempFile);
25
+ }
26
+ finally {
27
+ // Clean up
28
+ await (0, promises_1.rm)(tempDir, { recursive: true, force: true });
29
+ }
30
+ }
31
+ function createTempFileSync(filename, content = "") {
32
+ const tempDir = (0, node_fs_1.mkdtempSync)((0, node_path_1.join)((0, node_os_1.tmpdir)(), "app-"));
33
+ const tempFile = (0, node_path_1.join)(tempDir, filename);
34
+ (0, node_fs_1.writeFileSync)(tempFile, content, { mode: 0o600 });
35
+ return tempFile;
36
+ }
37
+ //# sourceMappingURL=tempFiles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tempFiles.js","sourceRoot":"","sources":["../../../src/utils/tempFiles.ts"],"names":[],"mappings":";;AAYA,oCAkBC;AAED,gDAMC;AAtCD,qCAAqD;AACrD,+CAA0D;AAC1D,qCAAiC;AACjC,yCAAiC;AAEjC;;;;;;GAMG;AACI,KAAK,UAAU,YAAY,CAChC,QAAgB,EAChB,QAA0C,EAC1C,UAA2B,EAAE;IAE7B,gDAAgD;IAChD,MAAM,OAAO,GAAG,MAAM,IAAA,kBAAO,EAAC,IAAA,gBAAI,EAAC,IAAA,gBAAM,GAAE,EAAE,MAAM,CAAC,CAAC,CAAC;IACtD,MAAM,QAAQ,GAAG,IAAA,gBAAI,EAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IAEzC,IAAI,CAAC;QACH,2DAA2D;QAC3D,MAAM,IAAA,oBAAS,EAAC,QAAQ,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;QACpD,eAAe;QACf,OAAO,MAAM,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAClC,CAAC;YAAS,CAAC;QACT,WAAW;QACX,MAAM,IAAA,aAAE,EAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IACtD,CAAC;AACH,CAAC;AAED,SAAgB,kBAAkB,CAAC,QAAgB,EAAE,UAA2B,EAAE;IAChF,MAAM,OAAO,GAAG,IAAA,qBAAW,EAAC,IAAA,gBAAI,EAAC,IAAA,gBAAM,GAAE,EAAE,MAAM,CAAC,CAAC,CAAC;IACpD,MAAM,QAAQ,GAAG,IAAA,gBAAI,EAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IAEzC,IAAA,uBAAa,EAAC,QAAQ,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;IAClD,OAAO,QAAQ,CAAC;AAClB,CAAC"}
@@ -11,7 +11,7 @@ export type PythonOptions = {
11
11
  *
12
12
  * Example: `/usr/bin/python3` or `C:\\Python39\\python.exe`
13
13
  */
14
- pythonBinaryPath?: string;
14
+ devPythonBinaryPath?: string;
15
15
  /**
16
16
  * An array of glob patterns that specify which Python scripts are allowed to be executed.
17
17
  *
@@ -21,4 +21,3 @@ export type PythonOptions = {
21
21
  scripts?: string[];
22
22
  };
23
23
  export declare function pythonExtension(options?: PythonOptions): BuildExtension;
24
- export default pythonExtension;
@@ -1,6 +1,6 @@
1
1
  import fs from "node:fs";
2
2
  import assert from "node:assert";
3
- import { additionalFiles } from "@trigger.dev/build/extensions/core";
3
+ import { addAdditionalFilesToBuild } from "@trigger.dev/build/internal";
4
4
  const splitAndCleanComments = (str) => str
5
5
  .split("\n")
6
6
  .map((line) => line.trim())
@@ -20,12 +20,12 @@ class PythonExtension {
20
20
  }
21
21
  }
22
22
  async onBuildComplete(context, manifest) {
23
- await additionalFiles({
23
+ await addAdditionalFilesToBuild("pythonExtension", {
24
24
  files: this.options.scripts ?? [],
25
- }).onBuildComplete(context, manifest);
25
+ }, context, manifest);
26
26
  if (context.target === "dev") {
27
- if (this.options.pythonBinaryPath) {
28
- process.env.PYTHON_BIN_PATH = this.options.pythonBinaryPath;
27
+ if (this.options.devPythonBinaryPath) {
28
+ process.env.PYTHON_BIN_PATH = this.options.devPythonBinaryPath;
29
29
  }
30
30
  return;
31
31
  }
@@ -51,27 +51,52 @@ class PythonExtension {
51
51
  override: true,
52
52
  },
53
53
  });
54
- context.addLayer({
55
- id: "python-dependencies",
56
- build: {
57
- env: {
58
- REQUIREMENTS_CONTENT: this.options.requirements?.join("\n") || "",
54
+ if (this.options.requirementsFile) {
55
+ if (this.options.requirements) {
56
+ context.logger.warn(`[pythonExtension] Both options.requirements and options.requirementsFile are specified. requirements will be ignored.`);
57
+ }
58
+ // Copy requirements file to the container
59
+ await addAdditionalFilesToBuild("pythonExtension", {
60
+ files: [this.options.requirementsFile],
61
+ }, context, manifest);
62
+ // Add a layer to the build that installs the requirements
63
+ context.addLayer({
64
+ id: "python-dependencies",
65
+ image: {
66
+ instructions: splitAndCleanComments(`
67
+ # Copy the requirements file
68
+ COPY ${this.options.requirementsFile} .
69
+ # Install dependencies
70
+ RUN pip install --no-cache-dir -r ${this.options.requirementsFile}
71
+ `),
59
72
  },
60
- },
61
- image: {
62
- instructions: splitAndCleanComments(`
73
+ deploy: {
74
+ override: true,
75
+ },
76
+ });
77
+ }
78
+ else if (this.options.requirements) {
79
+ context.addLayer({
80
+ id: "python-dependencies",
81
+ build: {
82
+ env: {
83
+ REQUIREMENTS_CONTENT: this.options.requirements?.join("\n") || "",
84
+ },
85
+ },
86
+ image: {
87
+ instructions: splitAndCleanComments(`
63
88
  ARG REQUIREMENTS_CONTENT
64
89
  RUN echo "$REQUIREMENTS_CONTENT" > requirements.txt
65
90
 
66
91
  # Install dependencies
67
92
  RUN pip install --no-cache-dir -r requirements.txt
68
93
  `),
69
- },
70
- deploy: {
71
- override: true,
72
- },
73
- });
94
+ },
95
+ deploy: {
96
+ override: true,
97
+ },
98
+ });
99
+ }
74
100
  }
75
101
  }
76
- export default pythonExtension;
77
102
  //# sourceMappingURL=extension.js.map
@@ -1 +1 @@
1
-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;aAAM,IAAI,IAAI,CAAC,OAAO,CAAC,YAAY,EAAE,CAAC;YACrC,OAAO,CAAC,QAAQ,CAAC;gBACf,EAAE,EAAE,qBAAqB;gBACzB,KAAK,EAAE;oBACL,GAAG,EAAE;wBACH,oBAAoB,EAAE,IAAI,CAAC,OAAO,CAAC,YAAY,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE;qBAClE;iBACF;gBACD,KAAK,EAAE;oBACL,YAAY,EAAE,qBAAqB,CAAC;;;;;;SAMrC,CAAC;iBACD;gBACD,MAAM,EAAE;oBACN,QAAQ,EAAE,IAAI;iBACf;aACF,CAAC,CAAC;QACL,CAAC;IACH,CAAC;CACF"}
@@ -1,10 +1,17 @@
1
- import { Options as XOptions, Result } from "tinyexec";
2
- export declare const run: (scriptArgs?: string[], options?: Partial<XOptions>) => Promise<Result>;
3
- export declare const runScript: (scriptPath: string, scriptArgs?: string[], options?: Partial<XOptions>) => Promise<Result>;
4
- export declare const runInline: (scriptContent: string, options?: Partial<XOptions>) => Promise<import("tinyexec").Output>;
5
- declare const _default: {
6
- run: (scriptArgs?: string[], options?: Partial<XOptions>) => Promise<Result>;
7
- runScript: (scriptPath: string, scriptArgs?: string[], options?: Partial<XOptions>) => Promise<Result>;
8
- runInline: (scriptContent: string, options?: Partial<XOptions>) => Promise<import("tinyexec").Output>;
1
+ import { AsyncIterableStream } from "@trigger.dev/core/v3";
2
+ import { Result, Options as XOptions } from "tinyexec";
3
+ export type PythonExecOptions = Partial<XOptions> & {
4
+ env?: {
5
+ [key: string]: string | undefined;
6
+ };
7
+ };
8
+ export declare const python: {
9
+ run(scriptArgs?: string[], options?: PythonExecOptions): Promise<Result>;
10
+ runScript(scriptPath: string, scriptArgs?: string[], options?: PythonExecOptions): Promise<Result>;
11
+ runInline(scriptContent: string, options?: PythonExecOptions): Promise<Result>;
12
+ stream: {
13
+ run(scriptArgs?: string[], options?: PythonExecOptions): AsyncIterableStream<string>;
14
+ runScript(scriptPath: string, scriptArgs?: string[], options?: PythonExecOptions): AsyncIterableStream<string>;
15
+ runInline(scriptContent: string, options?: PythonExecOptions): AsyncIterableStream<string>;
16
+ };
9
17
  };
10
- export default _default;
package/dist/esm/index.js CHANGED
@@ -1,47 +1,200 @@
1
- import fs from "node:fs";
2
- import assert from "node:assert";
1
+ import { createAsyncIterableStreamFromAsyncIterable, SemanticInternalAttributes, } from "@trigger.dev/core/v3";
3
2
  import { logger } from "@trigger.dev/sdk/v3";
3
+ import assert from "node:assert";
4
+ import fs from "node:fs";
4
5
  import { x } from "tinyexec";
5
- export const run = async (scriptArgs = [], options = {}) => {
6
- const pythonBin = process.env.PYTHON_BIN_PATH || "python";
7
- return await logger.trace("Python call", async (span) => {
8
- span.addEvent("Properties", {
9
- command: `${pythonBin} ${scriptArgs.join(" ")}`,
6
+ import { createTempFileSync, withTempFile } from "./utils/tempFiles.js";
7
+ export const python = {
8
+ async run(scriptArgs = [], options = {}) {
9
+ const pythonBin = process.env.PYTHON_BIN_PATH || "python";
10
+ return await logger.trace("python.run()", async (span) => {
11
+ const result = await x(pythonBin, scriptArgs, {
12
+ ...options,
13
+ nodeOptions: {
14
+ ...(options.nodeOptions || {}),
15
+ env: {
16
+ ...process.env,
17
+ ...options.env,
18
+ },
19
+ },
20
+ throwOnError: false, // Ensure errors are handled manually
21
+ });
22
+ if (result.exitCode) {
23
+ span.setAttribute("exitCode", result.exitCode);
24
+ }
25
+ if (result.exitCode !== 0) {
26
+ throw new Error(`${scriptArgs.join(" ")} exited with a non-zero code ${result.exitCode}:\n${result.stderr}`);
27
+ }
28
+ return result;
29
+ }, {
30
+ attributes: {
31
+ pythonBin,
32
+ args: scriptArgs.join(" "),
33
+ [SemanticInternalAttributes.STYLE_ICON]: "brand-python",
34
+ },
10
35
  });
11
- const result = await x(pythonBin, scriptArgs, {
12
- ...options,
13
- throwOnError: false, // Ensure errors are handled manually
36
+ },
37
+ async runScript(scriptPath, scriptArgs = [], options = {}) {
38
+ assert(scriptPath, "Script path is required");
39
+ assert(fs.existsSync(scriptPath), `Script does not exist: ${scriptPath}`);
40
+ return await logger.trace("python.runScript()", async (span) => {
41
+ span.setAttribute("scriptPath", scriptPath);
42
+ const result = await x(process.env.PYTHON_BIN_PATH || "python", [scriptPath, ...scriptArgs], {
43
+ ...options,
44
+ nodeOptions: {
45
+ ...(options.nodeOptions || {}),
46
+ env: {
47
+ ...process.env,
48
+ ...options.env,
49
+ },
50
+ },
51
+ throwOnError: false,
52
+ });
53
+ if (result.exitCode) {
54
+ span.setAttribute("exitCode", result.exitCode);
55
+ }
56
+ if (result.exitCode !== 0) {
57
+ throw new Error(`${scriptPath} ${scriptArgs.join(" ")} exited with a non-zero code ${result.exitCode}:\n${result.stderr}`);
58
+ }
59
+ return result;
60
+ }, {
61
+ attributes: {
62
+ pythonBin: process.env.PYTHON_BIN_PATH || "python",
63
+ scriptPath,
64
+ args: scriptArgs.join(" "),
65
+ [SemanticInternalAttributes.STYLE_ICON]: "brand-python",
66
+ },
14
67
  });
15
- span.addEvent("Output", { ...result });
16
- if (result.exitCode !== 0) {
17
- logger.error(result.stderr, { ...result });
18
- throw new Error(`Python command exited with non-zero code ${result.exitCode}`);
19
- }
20
- return result;
21
- });
22
- };
23
- export const runScript = (scriptPath, scriptArgs = [], options = {}) => {
24
- assert(scriptPath, "Script path is required");
25
- assert(fs.existsSync(scriptPath), `Script does not exist: ${scriptPath}`);
26
- return run([scriptPath, ...scriptArgs], options);
27
- };
28
- export const runInline = async (scriptContent, options = {}) => {
29
- assert(scriptContent, "Script content is required");
30
- const tmpFile = `/tmp/script_${Date.now()}.py`;
31
- await fs.promises.writeFile(tmpFile, scriptContent, { mode: 0o600 });
32
- try {
33
- return await runScript(tmpFile, [], options);
34
- }
35
- finally {
36
- try {
37
- await fs.promises.unlink(tmpFile);
38
- }
39
- catch (error) {
40
- logger.warn(`Failed to clean up temporary file ${tmpFile}:`, {
41
- error: error.stack || error.message,
42
- });
43
- }
44
- }
68
+ },
69
+ async runInline(scriptContent, options = {}) {
70
+ assert(scriptContent, "Script content is required");
71
+ return await logger.trace("python.runInline()", async (span) => {
72
+ span.setAttribute("contentLength", scriptContent.length);
73
+ // Using the withTempFile utility to handle the temporary file
74
+ return await withTempFile(`script_${Date.now()}.py`, async (tempFilePath) => {
75
+ span.setAttribute("tempFilePath", tempFilePath);
76
+ const pythonBin = process.env.PYTHON_BIN_PATH || "python";
77
+ const result = await x(pythonBin, [tempFilePath], {
78
+ ...options,
79
+ nodeOptions: {
80
+ ...(options.nodeOptions || {}),
81
+ env: {
82
+ ...process.env,
83
+ ...options.env,
84
+ },
85
+ },
86
+ throwOnError: false,
87
+ });
88
+ if (result.exitCode) {
89
+ span.setAttribute("exitCode", result.exitCode);
90
+ }
91
+ if (result.exitCode !== 0) {
92
+ throw new Error(`Inline script exited with a non-zero code ${result.exitCode}:\n${result.stderr}`);
93
+ }
94
+ return result;
95
+ }, scriptContent);
96
+ }, {
97
+ attributes: {
98
+ pythonBin: process.env.PYTHON_BIN_PATH || "python",
99
+ contentPreview: scriptContent.substring(0, 100) + (scriptContent.length > 100 ? "..." : ""),
100
+ [SemanticInternalAttributes.STYLE_ICON]: "brand-python",
101
+ },
102
+ });
103
+ },
104
+ // Stream namespace for streaming functions
105
+ stream: {
106
+ run(scriptArgs = [], options = {}) {
107
+ const pythonBin = process.env.PYTHON_BIN_PATH || "python";
108
+ const pythonProcess = x(pythonBin, scriptArgs, {
109
+ ...options,
110
+ nodeOptions: {
111
+ ...(options.nodeOptions || {}),
112
+ env: {
113
+ ...process.env,
114
+ ...options.env,
115
+ },
116
+ },
117
+ throwOnError: false,
118
+ });
119
+ const span = logger.startSpan("python.stream.run()", {
120
+ attributes: {
121
+ pythonBin,
122
+ args: scriptArgs.join(" "),
123
+ [SemanticInternalAttributes.STYLE_ICON]: "brand-python",
124
+ },
125
+ });
126
+ return createAsyncIterableStreamFromAsyncIterable(pythonProcess, {
127
+ transform: (chunk, controller) => {
128
+ controller.enqueue(chunk);
129
+ },
130
+ flush: () => {
131
+ span.end();
132
+ },
133
+ });
134
+ },
135
+ runScript(scriptPath, scriptArgs = [], options = {}) {
136
+ assert(scriptPath, "Script path is required");
137
+ assert(fs.existsSync(scriptPath), `Script does not exist: ${scriptPath}`);
138
+ const pythonBin = process.env.PYTHON_BIN_PATH || "python";
139
+ const pythonProcess = x(pythonBin, [scriptPath, ...scriptArgs], {
140
+ ...options,
141
+ nodeOptions: {
142
+ ...(options.nodeOptions || {}),
143
+ env: {
144
+ ...process.env,
145
+ ...options.env,
146
+ },
147
+ },
148
+ throwOnError: false,
149
+ });
150
+ const span = logger.startSpan("python.stream.runScript()", {
151
+ attributes: {
152
+ pythonBin,
153
+ scriptPath,
154
+ args: scriptArgs.join(" "),
155
+ [SemanticInternalAttributes.STYLE_ICON]: "brand-python",
156
+ },
157
+ });
158
+ return createAsyncIterableStreamFromAsyncIterable(pythonProcess, {
159
+ transform: (chunk, controller) => {
160
+ controller.enqueue(chunk);
161
+ },
162
+ flush: () => {
163
+ span.end();
164
+ },
165
+ });
166
+ },
167
+ runInline(scriptContent, options = {}) {
168
+ assert(scriptContent, "Script content is required");
169
+ const pythonBin = process.env.PYTHON_BIN_PATH || "python";
170
+ const pythonScriptPath = createTempFileSync(`script_${Date.now()}.py`, scriptContent);
171
+ const pythonProcess = x(pythonBin, [pythonScriptPath], {
172
+ ...options,
173
+ nodeOptions: {
174
+ ...(options.nodeOptions || {}),
175
+ env: {
176
+ ...process.env,
177
+ ...options.env,
178
+ },
179
+ },
180
+ throwOnError: false,
181
+ });
182
+ const span = logger.startSpan("python.stream.runInline()", {
183
+ attributes: {
184
+ pythonBin,
185
+ contentPreview: scriptContent.substring(0, 100) + (scriptContent.length > 100 ? "..." : ""),
186
+ [SemanticInternalAttributes.STYLE_ICON]: "brand-python",
187
+ },
188
+ });
189
+ return createAsyncIterableStreamFromAsyncIterable(pythonProcess, {
190
+ transform: (chunk, controller) => {
191
+ controller.enqueue(chunk);
192
+ },
193
+ flush: () => {
194
+ span.end();
195
+ },
196
+ });
197
+ },
198
+ },
45
199
  };
46
- export default { run, runScript, runInline };
47
200
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,CAAC,EAA+B,MAAM,UAAU,CAAC;AAE1D,MAAM,CAAC,MAAM,GAAG,GAAG,KAAK,EACtB,aAAuB,EAAE,EACzB,UAA6B,EAAE,EACd,EAAE;IACnB,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,eAAe,IAAI,QAAQ,CAAC;IAE1D,OAAO,MAAM,MAAM,CAAC,KAAK,CAAC,aAAa,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE;QACtD,IAAI,CAAC,QAAQ,CAAC,YAAY,EAAE;YAC1B,OAAO,EAAE,GAAG,SAAS,IAAI,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE;SAChD,CAAC,CAAC;QAEH,MAAM,MAAM,GAAG,MAAM,CAAC,CAAC,SAAS,EAAE,UAAU,EAAE;YAC5C,GAAG,OAAO;YACV,YAAY,EAAE,KAAK,EAAE,qCAAqC;SAC3D,CAAC,CAAC;QAEH,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,EAAE,GAAG,MAAM,EAAE,CAAC,CAAC;QAEvC,IAAI,MAAM,CAAC,QAAQ,KAAK,CAAC,EAAE,CAAC;YAC1B,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE,GAAG,MAAM,EAAE,CAAC,CAAC;YAC3C,MAAM,IAAI,KAAK,CAAC,4CAA4C,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC;QACjF,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC,CA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BAC5B,CAAC;gBACD,KAAK,EAAE,GAAG,EAAE;oBACV,IAAI,CAAC,GAAG,EAAE,CAAC;gBACb,CAAC;aACF,CAAC,CAAC;QACL,CAAC;KACF;CACF,CAAC"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Creates a temporary file with a custom filename, passes it to the callback function, and ensures cleanup
3
+ * @param filename The filename to use for the temporary file
4
+ * @param callback Function that receives the path to the temporary file
5
+ * @param content Optional content to write to the file
6
+ * @returns Whatever the callback returns
7
+ */
8
+ export declare function withTempFile<T>(filename: string, callback: (filePath: string) => Promise<T>, content?: string | Buffer): Promise<T>;
9
+ export declare function createTempFileSync(filename: string, content?: string | Buffer): string;
@@ -0,0 +1,33 @@
1
+ import { mkdtempSync, writeFileSync } from "node:fs";
2
+ import { mkdtemp, writeFile, rm } from "node:fs/promises";
3
+ import { tmpdir } from "node:os";
4
+ import { join } from "node:path";
5
+ /**
6
+ * Creates a temporary file with a custom filename, passes it to the callback function, and ensures cleanup
7
+ * @param filename The filename to use for the temporary file
8
+ * @param callback Function that receives the path to the temporary file
9
+ * @param content Optional content to write to the file
10
+ * @returns Whatever the callback returns
11
+ */
12
+ export async function withTempFile(filename, callback, content = "") {
13
+ // Create temporary directory with random suffix
14
+ const tempDir = await mkdtemp(join(tmpdir(), "app-"));
15
+ const tempFile = join(tempDir, filename);
16
+ try {
17
+ // Write to the temporary file with appropriate permissions
18
+ await writeFile(tempFile, content, { mode: 0o600 });
19
+ // Use the file
20
+ return await callback(tempFile);
21
+ }
22
+ finally {
23
+ // Clean up
24
+ await rm(tempDir, { recursive: true, force: true });
25
+ }
26
+ }
27
+ export function createTempFileSync(filename, content = "") {
28
+ const tempDir = mkdtempSync(join(tmpdir(), "app-"));
29
+ const tempFile = join(tempDir, filename);
30
+ writeFileSync(tempFile, content, { mode: 0o600 });
31
+ return tempFile;
32
+ }
33
+ //# sourceMappingURL=tempFiles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tempFiles.js","sourceRo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AAClB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trigger.dev/python",
3
- "version": "0.0.0-python-preview-20250226140121",
3
+ "version": "3.3.17",
4
4
  "description": "Python runtime and build extension for Trigger.dev",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -37,9 +37,7 @@
37
37
  }
38
38
  },
39
39
  "dependencies": {
40
- "@trigger.dev/build": "0.0.0-python-preview-20250226140121",
41
- "@trigger.dev/core": "0.0.0-python-preview-20250226140121",
42
- "@trigger.dev/sdk": "0.0.0-python-preview-20250226140121",
40
+ "@trigger.dev/core": "3.3.17",
43
41
  "tinyexec": "^0.3.2"
44
42
  },
45
43
  "devDependencies": {
@@ -49,7 +47,13 @@
49
47
  "typescript": "^5.5.4",
50
48
  "tsx": "4.17.0",
51
49
  "esbuild": "^0.23.0",
52
- "@arethetypeswrong/cli": "^0.15.4"
50
+ "@arethetypeswrong/cli": "^0.15.4",
51
+ "@trigger.dev/build": "3.3.17",
52
+ "@trigger.dev/sdk": "3.3.17"
53
+ },
54
+ "peerDependencies": {
55
+ "@trigger.dev/sdk": "^3.3.17",
56
+ "@trigger.dev/build": "^3.3.17"
53
57
  },
54
58
  "engines": {
55
59
  "node": ">=18.20.0"