New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

python-shell

Package Overview
Dependencies
Maintainers
2
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

python-shell - npm Package Compare versions

Comparing version 1.0.8 to 2.0.0

7

CHANGELOG.md

@@ -0,1 +1,8 @@

## 1.0.8
* @joaoe fixed a bug with pythonshell not working with unset std streams
* https://github.com/extrabacon/python-shell/milestone/9
## 1.0.7
* default python path updated to py on windows
## 1.0.4

@@ -2,0 +9,0 @@ * added getVersionSync

19

index.d.ts

@@ -1,2 +0,1 @@

/// <reference types="node" />
import { EventEmitter } from 'events';

@@ -6,2 +5,5 @@ import { ChildProcess, SpawnOptions } from 'child_process';

export interface Options extends SpawnOptions {
/**
* if binary is enabled message and stderr events will not be emitted
*/
mode?: 'text' | 'json' | 'binary';

@@ -72,3 +74,2 @@ formatter?: (param: string) => any;

* checks syntax without executing code
* @param {string} code
* @returns {Promise} rejects w/ stderr if syntax failure

@@ -80,3 +81,2 @@ */

* checks syntax without executing code
* @param {string} filePath
* @returns {Promise} rejects w/ stderr if syntax failure

@@ -115,3 +115,2 @@ */

* Override this method to format data to be sent to the Python process
* @param {string|Object} data The message to send
* @returns {PythonShell} The same instance for chaining calls

@@ -136,3 +135,4 @@ */

/**
* Closes the stdin stream, which should cause the process to finish its work and close
* Closes the stdin stream. Unless python is listening for stdin in a loop
* this should cause the process to finish its work and close.
* @returns {PythonShell} The same instance for chaining calls

@@ -142,6 +142,11 @@ */

/**
* Closes the stdin stream, which should cause the process to finish its work and close
* Sends a kill signal to the process
* @returns {PythonShell} The same instance for chaining calls
*/
terminate(signal?: string): this;
kill(signal?: NodeJS.Signals): this;
/**
* Alias for kill.
* @deprecated
*/
terminate(signal?: NodeJS.Signals): this;
}

@@ -106,6 +106,8 @@ "use strict";

// listen to stderr and emit errors for incoming data
if (this.stderrParser && this.stderr) {
this.stderr.on('data', this.receiveStderr.bind(this));
}
if (this.stderr) {
this.stderr.on('data', function (data) {
errorData += '' + data;
self.receiveStderr(data);
});

@@ -165,3 +167,2 @@ this.stderr.on('end', function () {

* checks syntax without executing code
* @param {string} code
* @returns {Promise} rejects w/ stderr if syntax failure

@@ -188,3 +189,2 @@ */

* checks syntax without executing code
* @param {string} filePath
* @returns {Promise} rejects w/ stderr if syntax failure

@@ -261,3 +261,3 @@ */

// traceback data is available
let lines = ('' + data).trim().split(new RegExp(os_1.EOL, 'g'));
let lines = text.trim().split(os_1.EOL);
let exception = lines.pop();

@@ -280,3 +280,2 @@ error = new PythonShellError(exception);

* Override this method to format data to be sent to the Python process
* @param {string|Object} data The message to send
* @returns {PythonShell} The same instance for chaining calls

@@ -286,3 +285,3 @@ */

if (!this.stdin)
throw new Error("stdin not open for writting");
throw new Error("stdin not open for writing");
let data = this.formatter ? this.formatter(message) : message;

@@ -317,3 +316,3 @@ if (this.mode !== 'binary')

let self = this;
let parts = ('' + data).split(new RegExp(os_1.EOL, 'g'));
let parts = ('' + data).split(os_1.EOL);
if (parts.length === 1) {

@@ -338,3 +337,4 @@ // an incomplete record, keep buffering

/**
* Closes the stdin stream, which should cause the process to finish its work and close
* Closes the stdin stream. Unless python is listening for stdin in a loop
* this should cause the process to finish its work and close.
* @returns {PythonShell} The same instance for chaining calls

@@ -351,6 +351,6 @@ */

/**
* Closes the stdin stream, which should cause the process to finish its work and close
* Sends a kill signal to the process
* @returns {PythonShell} The same instance for chaining calls
*/
terminate(signal) {
kill(signal) {
this.childProcess.kill(signal);

@@ -361,2 +361,10 @@ this.terminated = true;

;
/**
* Alias for kill.
* @deprecated
*/
terminate(signal) {
// todo: remove this next breaking release
return this.kill(signal);
}
}

@@ -363,0 +371,0 @@ // starting 2020 python2 is deprecated so we choose 3 as default

{
"name": "python-shell",
"version": "1.0.8",
"version": "2.0.0",
"description": "Run Python scripts from Node.js with simple (but efficient) inter-process communication through stdio",

@@ -9,3 +9,3 @@ "keywords": [

"scripts": {
"test": "tsc -p ./ && mocha",
"test": "tsc -p ./ && mocha -r ts-node/register",
"appveyorTest": "tsc -p ./ && nyc mocha --reporter mocha-appveyor-reporter test/*.js",

@@ -17,3 +17,3 @@ "compile": "tsc -watch -p ./"

"@types/mocha": "^5.2.5",
"@types/node": "^9.3.0",
"@types/node": "^10.5.2",
"mocha": "^5.2.0",

@@ -20,0 +20,0 @@ "mocha-appveyor-reporter": "^0.4.0",

@@ -100,3 +100,2 @@ # [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) [![codecov](https://codecov.io/gh/extrabacon/python-shell/branch/master/graph/badge.svg)](https://codecov.io/gh/extrabacon/python-shell)

console.log('finished');
console.log('finished');
});

@@ -266,7 +265,7 @@ ```

// send a message in text mode
let shell = new PythonShell('script.py', { mode: 'text '});
let shell = new PythonShell('script.py', { mode: 'text'});
shell.send('hello world!');
// send a message in JSON mode
let shell = new PythonShell('script.py', { mode: 'json '});
let shell = new PythonShell('script.py', { mode: 'json'});
shell.send({ command: "do_stuff", args: [1, 2, 3] });

@@ -287,5 +286,5 @@ ```

#### `.terminate(signal)`
#### `.kill(signal)`
Terminates the python script, the optional end callback is invoked if specified. A kill signal may be provided by `signal`, if `signal` is not specified SIGTERM is sent.
Terminates the python script. A kill signal may be provided by `signal`, if `signal` is not specified SIGTERM is sent.

@@ -300,3 +299,3 @@ #### event: `message`

// receive a message in text mode
let shell = new PythonShell('script.py', { mode: 'text '});
let shell = new PythonShell('script.py', { mode: 'text'});
shell.on('message', function (message) {

@@ -307,3 +306,3 @@ // handle message (a line of text from stdout)

// receive a message in JSON mode
let shell = new PythonShell('script.py', { mode: 'json '});
let shell = new PythonShell('script.py', { mode: 'json'});
shell.on('message', function (message) {

@@ -322,3 +321,3 @@ // handle message (a line of text from stdout, parsed as JSON)

// receive a message in text mode
let shell = new PythonShell('script.py', { mode: 'text '});
let shell = new PythonShell('script.py', { mode: 'text'});
shell.on('stderr', function (stderr) {

@@ -339,3 +338,3 @@ // handle stderr (a line of text from stderr)

Python-Shell is used by [arepl-vscode](https://github.com/almenon/arepl-vscode), [gitinspector](https://github.com/ejwa/gitinspector), [pyspreadsheet](https://github.com/extrabacon/pyspreadsheet), and more!
Python-Shell is used by [arepl-vscode](https://github.com/almenon/arepl-vscode), [gitinspector](https://github.com/ejwa/gitinspector), [pyspreadsheet](https://github.com/extrabacon/pyspreadsheet), [AtlantOS Ocean Data QC](https://github.com/ocean-data-qc/ocean-data-qc) and more!

@@ -342,0 +341,0 @@ ## License

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc