python-shell
Advanced tools
Comparing version 1.0.4 to 1.0.5
@@ -0,1 +1,4 @@ | ||
## 1.0.4 | ||
* added getVersionSync | ||
## 0.0.3 | ||
@@ -2,0 +5,0 @@ * fixed buffering in `PythonShell.receive`, fixing [#1](https://github.com/extrabacon/python-shell/issues/1) |
@@ -17,5 +17,5 @@ /// <reference types="node" /> | ||
/** | ||
* overrides scriptPath passed into PythonShell constructor | ||
* the scriptPath passed to PythonShell is executed relative to scriptFolder, if specified | ||
*/ | ||
scriptPath?: string; | ||
scriptFolder?: string; | ||
/** | ||
@@ -56,2 +56,7 @@ * arguments to your program | ||
static defaultOptions: Options; | ||
/** | ||
* spawns a python process | ||
* @param scriptPath path to script. Relative to current directory or options.scriptFolder if specified | ||
* @param options | ||
*/ | ||
constructor(scriptPath: string, options?: Options); | ||
@@ -77,3 +82,3 @@ static format: { | ||
*/ | ||
static checkSyntaxFile(filePath: string): Promise<{}>; | ||
static checkSyntaxFile(filePath: string): Promise<string>; | ||
/** | ||
@@ -95,2 +100,3 @@ * Runs a Python script and returns collected messages | ||
static runString(code: string, options?: Options, callback?: (err: PythonShellError, output?: any[]) => any): PythonShell; | ||
static getVersionSync(pythonPath?: string): string; | ||
/** | ||
@@ -97,0 +103,0 @@ * Parses an error thrown from the Python process through stderr |
16
index.js
@@ -47,2 +47,7 @@ "use strict"; | ||
class PythonShell extends events_1.EventEmitter { | ||
/** | ||
* spawns a python process | ||
* @param scriptPath path to script. Relative to current directory or options.scriptFolder if specified | ||
* @param options | ||
*/ | ||
constructor(scriptPath, options) { | ||
@@ -63,2 +68,4 @@ super(); | ||
} | ||
if (scriptPath.trim().length == 0) | ||
throw Error("scriptPath cannot be empty! You must give a script for python to run"); | ||
let self = this; | ||
@@ -76,3 +83,3 @@ let errorData = ''; | ||
let scriptArgs = toArray(options.args); | ||
this.scriptPath = path_1.join(options.scriptPath || '', scriptPath); | ||
this.scriptPath = path_1.join(options.scriptFolder || '', scriptPath); | ||
this.command = pythonOptions.concat(this.scriptPath, scriptArgs); | ||
@@ -148,3 +155,3 @@ this.mode = options.mode || 'text'; | ||
let randomInt = PythonShell.getRandomInt(); | ||
let filePath = os_1.tmpdir + path_1.sep + `pythonShellSyntaxCheck${randomInt}.py`; | ||
let filePath = os_1.tmpdir() + path_1.sep + `pythonShellSyntaxCheck${randomInt}.py`; | ||
// todo: replace this with util.promisify (once we no longer support node v7) | ||
@@ -212,2 +219,7 @@ return new Promise((resolve, reject) => { | ||
; | ||
static getVersionSync(pythonPath) { | ||
if (!pythonPath) | ||
pythonPath = this.defaultPythonPath; | ||
return child_process_1.execSync(pythonPath + " --version").toString(); | ||
} | ||
/** | ||
@@ -214,0 +226,0 @@ * Parses an error thrown from the Python process through stderr |
{ | ||
"name": "python-shell", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"description": "Run Python scripts from Node.js with simple (but efficient) inter-process communication through stdio", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -41,2 +41,7 @@ # [python-shell](https://www.npmjs.com/package/python-shell) [![Build status](https://ci.appveyor.com/api/projects/status/m8e3h53vvxg5wb2q?svg=true)](https://ci.appveyor.com/project/Almenon/python-shell) | ||
Or you can use require like so: | ||
```javascript | ||
let {PythonShell} = require('python-shell') | ||
``` | ||
### Running a Python script: | ||
@@ -227,3 +232,3 @@ | ||
// run a simple script | ||
PythonShell.run('x=1;print(x)', null, function (err, results) { | ||
PythonShell.runString('x=1;print(x)', null, function (err, results) { | ||
// script finished | ||
@@ -233,2 +238,17 @@ }); | ||
#### `#checkSyntax(code:string)` | ||
Checks the syntax of the code and returns a promise. | ||
Promise is rejected if there is a syntax error. | ||
#### `#checkSyntaxFile(filePath:string)` | ||
Checks the syntax of the file and returns a promise. | ||
Promise is rejected if there is a syntax error. | ||
#### `#getVersionSync(pythonPath?:string)` | ||
Returns the python version. Optional pythonPath param to get the version | ||
of a specific python interpreter. | ||
#### `.send(message)` | ||
@@ -266,12 +286,2 @@ | ||
#### `checkSyntax(code:string)` | ||
Checks the syntax of the code and returns a promise. | ||
Promise is rejected if there is a syntax error. | ||
#### `checkSyntaxFile(filePath:string)` | ||
Checks the syntax of the file and returns a promise. | ||
Promise is rejected if there is a syntax error. | ||
#### event: `message` | ||
@@ -278,0 +288,0 @@ |
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
42954
495
352