Skip to content

Commit ae6cee8

Browse files
committed
renamed script to scriptPath to avoid confusion and got rid of unnecessary code in run
1 parent 59ae034 commit ae6cee8

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

index.ts

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class PythonShellError extends Error{
5050
* @constructor
5151
*/
5252
export class PythonShell extends EventEmitter{
53-
script:string
53+
scriptPath:string
5454
command:string[]
5555
mode:string
5656
formatter:(param:string|Object)=>any
@@ -70,7 +70,7 @@ export class PythonShell extends EventEmitter{
7070
//@ts-ignore keeping it initialized to {} for backwards API compatability
7171
static defaultOptions:Options = {}; //allow global overrides for options
7272

73-
constructor(script:string, options?:Options) {
73+
constructor(scriptPath:string, options?:Options) {
7474
super();
7575

7676
/**
@@ -100,8 +100,8 @@ export class PythonShell extends EventEmitter{
100100
let pythonOptions = toArray(options.pythonOptions);
101101
let scriptArgs = toArray(options.args);
102102

103-
this.script = join(options.scriptPath || './', script);
104-
this.command = pythonOptions.concat(this.script, scriptArgs);
103+
this.scriptPath = join(options.scriptPath || './', scriptPath);
104+
this.command = pythonOptions.concat(this.scriptPath, scriptArgs);
105105
this.mode = options.mode || 'text';
106106
this.formatter = resolve('format', options.formatter || this.mode);
107107
this.parser = resolve('parse', options.parser || this.mode);
@@ -152,7 +152,7 @@ export class PythonShell extends EventEmitter{
152152
err = <PythonShellError>extend(err, {
153153
executable: pythonPath,
154154
options: pythonOptions.length ? pythonOptions : null,
155-
script: self.script,
155+
script: self.scriptPath,
156156
args: scriptArgs.length ? scriptArgs : null,
157157
exitCode: self.exitCode
158158
});
@@ -192,18 +192,13 @@ export class PythonShell extends EventEmitter{
192192

193193
/**
194194
* Runs a Python script and returns collected messages
195-
* @param {string} script The script to execute
195+
* @param {string} scriptPath The path to the script to execute
196196
* @param {Options} options The execution options
197197
* @param {Function} callback The callback function to invoke with the script results
198198
* @return {PythonShell} The PythonShell instance
199199
*/
200-
static run(script:string, options?:Options, callback?:(err:PythonShellError, output?:any[])=>any) {
201-
if (typeof options === 'function') {
202-
callback = options;
203-
options = null;
204-
}
205-
206-
let pyshell = new PythonShell(script, options);
200+
static run(scriptPath:string, options?:Options, callback?:(err:PythonShellError, output?:any[])=>any) {
201+
let pyshell = new PythonShell(scriptPath, options);
207202
let output = [];
208203

209204
return pyshell.on('message', function (message) {

0 commit comments

Comments
 (0)