python-shell
Advanced tools
Comparing version 3.0.1 to 4.0.0
@@ -0,1 +1,10 @@ | ||
## [4.0.0] - 2023-02-10 | ||
### Changed | ||
- run and runString now return a promise instead of a using a callback. | ||
- This is somewhat backwards compatible with previous behavior | ||
## [3.0.1] - 2021-10-09 | ||
### Fixed | ||
- Previously when you called the kill method the terminated attribute was always set to true, regardless of whether the process was actually killed. Now the terminated boolean is set to true if kill succeeds, false otherwise. [#255](https://github.com/extrabacon/python-shell/issues/255) | ||
## [3.0.0] - 2021-03-07 | ||
@@ -2,0 +11,0 @@ ### Changed |
@@ -32,2 +32,5 @@ /// <reference types="node" /> | ||
} | ||
export declare class PythonShellErrorWithLogs extends PythonShellError { | ||
logs: any[]; | ||
} | ||
/** | ||
@@ -103,17 +106,15 @@ * Takes in a string stream and emits batches seperated by newlines | ||
/** | ||
* Runs a Python script and returns collected messages | ||
* @param {string} scriptPath The path to the script to execute | ||
* @param {Options} options The execution options | ||
* @param {Function} callback The callback function to invoke with the script results | ||
* @return {PythonShell} The PythonShell instance | ||
* Runs a Python script and returns collected messages as a promise. | ||
* If the promise is rejected, the err will probably be of type PythonShellErrorWithLogs | ||
* @param scriptPath The path to the script to execute | ||
* @param options The execution options | ||
*/ | ||
static run(scriptPath: string, options?: Options, callback?: (err?: PythonShellError, output?: any[]) => any): PythonShell; | ||
static run(scriptPath: string, options?: Options): Promise<any[]>; | ||
/** | ||
* Runs the inputted string of python code and returns collected messages. DO NOT ALLOW UNTRUSTED USER INPUT HERE! | ||
* @param {string} code The python code to execute | ||
* @param {Options} options The execution options | ||
* @param {Function} callback The callback function to invoke with the script results | ||
* @return {PythonShell} The PythonShell instance | ||
* Runs the inputted string of python code and returns collected messages as a promise. DO NOT ALLOW UNTRUSTED USER INPUT HERE! | ||
* @param code The python code to execute | ||
* @param options The execution options | ||
* @return a promise with the output from the python script | ||
*/ | ||
static runString(code: string, options?: Options, callback?: (err: PythonShellError, output?: any[]) => any): PythonShell; | ||
static runString(code: string, options?: Options): Promise<any[]>; | ||
static getVersion(pythonPath?: string): import("child_process").PromiseWithChild<{ | ||
@@ -120,0 +121,0 @@ stdout: string; |
48
index.js
@@ -12,3 +12,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.PythonShell = exports.NewlineTransformer = exports.PythonShellError = void 0; | ||
exports.PythonShell = exports.NewlineTransformer = exports.PythonShellErrorWithLogs = exports.PythonShellError = void 0; | ||
const events_1 = require("events"); | ||
@@ -53,2 +53,5 @@ const child_process_1 = require("child_process"); | ||
exports.PythonShellError = PythonShellError; | ||
class PythonShellErrorWithLogs extends PythonShellError { | ||
} | ||
exports.PythonShellErrorWithLogs = PythonShellErrorWithLogs; | ||
/** | ||
@@ -244,15 +247,21 @@ * Takes in a string stream and emits batches seperated by newlines | ||
/** | ||
* Runs a Python script and returns collected messages | ||
* @param {string} scriptPath The path to the script to execute | ||
* @param {Options} options The execution options | ||
* @param {Function} callback The callback function to invoke with the script results | ||
* @return {PythonShell} The PythonShell instance | ||
* Runs a Python script and returns collected messages as a promise. | ||
* If the promise is rejected, the err will probably be of type PythonShellErrorWithLogs | ||
* @param scriptPath The path to the script to execute | ||
* @param options The execution options | ||
*/ | ||
static run(scriptPath, options, callback) { | ||
let pyshell = new PythonShell(scriptPath, options); | ||
let output = []; | ||
return pyshell.on('message', function (message) { | ||
output.push(message); | ||
}).end(function (err) { | ||
return callback(err ? err : null, output.length ? output : null); | ||
static run(scriptPath, options) { | ||
return new Promise((resolve, reject) => { | ||
let pyshell = new PythonShell(scriptPath, options); | ||
let output = []; | ||
pyshell.on('message', function (message) { | ||
output.push(message); | ||
}).end(function (err) { | ||
if (err) { | ||
err.logs = output; | ||
reject(err); | ||
} | ||
else | ||
resolve(output); | ||
}); | ||
}); | ||
@@ -262,9 +271,8 @@ } | ||
/** | ||
* Runs the inputted string of python code and returns collected messages. DO NOT ALLOW UNTRUSTED USER INPUT HERE! | ||
* @param {string} code The python code to execute | ||
* @param {Options} options The execution options | ||
* @param {Function} callback The callback function to invoke with the script results | ||
* @return {PythonShell} The PythonShell instance | ||
* Runs the inputted string of python code and returns collected messages as a promise. DO NOT ALLOW UNTRUSTED USER INPUT HERE! | ||
* @param code The python code to execute | ||
* @param options The execution options | ||
* @return a promise with the output from the python script | ||
*/ | ||
static runString(code, options, callback) { | ||
static runString(code, options) { | ||
// put code in temp file | ||
@@ -274,3 +282,3 @@ const randomInt = getRandomInt(); | ||
(0, fs_1.writeFileSync)(filePath, code); | ||
return PythonShell.run(filePath, options, callback); | ||
return PythonShell.run(filePath, options); | ||
} | ||
@@ -277,0 +285,0 @@ ; |
{ | ||
"name": "python-shell", | ||
"version": "3.0.1", | ||
"version": "4.0.0", | ||
"description": "Run Python scripts from Node.js with simple (but efficient) inter-process communication through stdio", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
54022
15
623