Skip to content

Commit e7fc08c

Browse files
author
Ryan Munro
committed
Run full tests, cleanup things, add Bluebird.Promise type
1 parent 2ea69ce commit e7fc08c

7 files changed

Lines changed: 69 additions & 124 deletions

File tree

.gitignore

Lines changed: 5 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,10 @@
1-
# Logs
2-
logs
3-
*.log
4-
npm-debug.log*
5-
6-
# Runtime data
7-
pids
8-
*.pid
9-
*.seed
10-
11-
# Directory for instrumented libs generated by jscoverage/JSCover
12-
lib-cov
13-
14-
# Coverage directory used by tools like istanbul
15-
coverage
16-
17-
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
18-
.grunt
19-
20-
# node-waf configuration
21-
.lock-wscript
22-
23-
# Compiled binary addons (http://nodejs.org/api/addons.html)
24-
build/Release
25-
26-
# Dependency directory
27-
node_modules
28-
29-
# Optional npm cache directory
30-
.npm
31-
32-
# Optional REPL history
1+
.*.swp
2+
.DS_Store
333
.node_repl_history
34-
4+
.npm
5+
node_modules
6+
npm-debug.log*
357
npm-shrinkwrap.json
368
package-lock.json
37-
38-
.*.swp
39-
40-
# TAP Coverage
41-
coverage
42-
.nyc_output
43-
44-
DS_Store
45-
yarn.lock
46-
.yarn/
47-
.yarn-cache/
48-
.v8flags.*
49-
tags
50-
519
package-lock.json
5210
test_typescript.js

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ python`hello(${a}, ${b})`.then(x => assert.equal(x, a + b));
7676

7777
## python.lock(...).then(...)
7878

79-
Locks access to the Python interpreter so code can be executed atomically. If possible, it's recommend to define a function in Python to handle atomicity.
79+
Locks access to the Python interpreter so code can be executed atomically. If possible, it's recommend to define a function in Python to handle atomicity.
8080

8181
```javascript
8282
python.lock(python => {

README.ts.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ assert.equal(a + b, await python`hello(${a}, ${b})`);
8181

8282
## python.lock(...).then(...)
8383

84-
Locks access to the Python interpreter so code can be executed atomically. If possible, it's recommend to define a function in Python to handle atomicity.
84+
Locks access to the Python interpreter so code can be executed atomically. If possible, it's recommend to define a function in Python to handle atomicity.
8585

8686
```javascript
8787
const x: number = await python.lock(async python =>{

index.d.ts

Lines changed: 53 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,60 @@
1-
// declare module "python-bridge" {
2-
interface pythonBridge extends Function {
3-
(options?: PythonBridgeOptions): PythonBridge;
4-
}
1+
interface pythonBridge extends Function {
2+
(options?: PythonBridgeOptions): PythonBridge;
3+
}
54

6-
export const pythonBridge: pythonBridge
75

8-
export interface PythonBridgeOptions {
9-
intepreter?: string;
10-
stdio?: [PipeStdin, PipeStdout, PipeStderr];
11-
cwd?: string;
12-
env?: { [key:string]: string; };
13-
uid?: number;
14-
gid?: number;
15-
}
6+
export const pythonBridge: pythonBridge
167

17-
export interface PythonBridge {
18-
(literals: TemplateStringsArray | string, ...placeholders: any[]): Promise<any>;
19-
ex(literals: TemplateStringsArray | string, ...placeholders: any[]): Promise<void>;
20-
lock<T>(withLock: (python: PythonBridge) => Promise<T>): Promise<T>
21-
pid: number;
22-
end(): Promise<void>;
23-
disconnect(): Promise<void>;
24-
kill(signal: string | number): void;
25-
stdin: NodeJS.WritableStream;
26-
stdout: NodeJS.ReadableStream;
27-
stderr: NodeJS.ReadableStream;
28-
connected: boolean;
29-
}
8+
export interface PythonBridgeOptions {
9+
intepreter?: string;
10+
stdio?: [PipeStdin, PipeStdout, PipeStderr];
11+
cwd?: string;
12+
env?: { [key:string]: string; };
13+
uid?: number;
14+
gid?: number;
15+
}
16+
17+
export interface PythonBridge {
18+
(literals: TemplateStringsArray | string, ...placeholders: any[]): Bluebird.Promise<any>;
19+
ex(literals: TemplateStringsArray | string, ...placeholders: any[]): Bluebird.Promise<void>;
20+
lock<T>(withLock: (python: PythonBridge) => Promise<T>): Bluebird.Promise<T>
21+
pid: number;
22+
end(): Promise<void>;
23+
disconnect(): Promise<void>;
24+
kill(signal: string | number): void;
25+
stdin: NodeJS.WritableStream;
26+
stdout: NodeJS.ReadableStream;
27+
stderr: NodeJS.ReadableStream;
28+
connected: boolean;
29+
}
3030

31-
export function isPythonException(name: string): (e: any) => boolean;
32-
export function isPythonException(name: string, e: any): boolean;
33-
34-
export class PythonException extends Error {
35-
exception: {
36-
message: string;
37-
args: any[];
38-
type: { name: string; module: string; }
39-
format: string[];
40-
};
41-
traceback: {
42-
lineno: number;
43-
strack: string[];
44-
format: string[]
45-
};
31+
export function isPythonException(name: string): (e: any) => boolean;
32+
export function isPythonException(name: string, e: any): boolean;
33+
34+
export class PythonException extends Error {
35+
exception: {
36+
message: string;
37+
args: any[];
38+
type: { name: string; module: string; }
39+
format: string[];
40+
};
41+
traceback: {
42+
lineno: number;
43+
strack: string[];
4644
format: string[]
45+
};
46+
format: string[]
47+
}
48+
49+
export type Pipe = "pipe" | "ignore" | "inherit";
50+
export type PipeStdin = Pipe | NodeJS.ReadableStream;
51+
export type PipeStdout = Pipe | NodeJS.WritableStream;
52+
export type PipeStderr = Pipe | NodeJS.WritableStream;
53+
54+
export namespace Bluebird {
55+
interface Promise<T> extends _Promise<T> {
56+
timeout(number): Bluebird.Promise<T>;
4757
}
58+
}
4859

49-
export type Pipe = "pipe" | "ignore" | "inherit";
50-
export type PipeStdin = Pipe | NodeJS.ReadableStream;
51-
export type PipeStdout = Pipe | NodeJS.WritableStream;
52-
export type PipeStderr = Pipe | NodeJS.WritableStream;
53-
// }
60+
type _Promise<T> = Promise<T>;

package.json

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
"lint:ts": "tslint --project tsconfig.json --type-check",
1010
"test": "npm run lint && npm run test:js && npm run test:ts",
1111
"test:js": "tap test.js",
12-
"test:ts": "ts-node test.ts",
13-
"test_ts": "ts-node node_modules/blue-tape/bin/blue-tape test_typescript.ts"
12+
"test:ts": "tsc --lib ES2015 test_typescript.ts && tap test_typescript.js"
1413
},
1514
"repository": {
1615
"type": "git",
@@ -28,14 +27,12 @@
2827
"author": "Ryan Munro <ryan@submersible.io>",
2928
"license": "MIT",
3029
"dependencies": {
31-
"bluebird": "^3.4.6"
30+
"bluebird": "^3.5.0"
3231
},
3332
"devDependencies": {
3433
"@types/node": "^8.0.14",
35-
"blue-tape": "^1.0.0",
3634
"tap": "^10.7.0",
3735
"temp": "^0.8.3",
38-
"ts-node": "^3.2.0",
3936
"tslint": "^5.5.0",
4037
"typescript": "^2.4.1"
4138
}

test.ts

Lines changed: 0 additions & 19 deletions
This file was deleted.

test_typescript.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { test } from 'blue-tape';
1+
import { test } from 'tap';
22
import { join as path_join } from 'path';
3-
import { promisify, promisifyAll } from 'bluebird';
4-
import { pythonBridge, PythonException, isPythonException } from './';
3+
import { promisify } from 'bluebird';
4+
import { pythonBridge, PythonException, isPythonException } from './index';
55

66
const mkdirTemp = promisify(require('temp').mkdir);
77

@@ -20,7 +20,7 @@ test('readme', t => {
2020
python.end();
2121
}
2222
});
23-
23+
2424
t.test('expression', async assert => {
2525
let python = pythonBridge();
2626
try {
@@ -102,7 +102,7 @@ test('readme', t => {
102102
sys.stdout.write(line)
103103
sys.stdout.flush()
104104
`;
105-
105+
106106
// write to Python process's stdin
107107
python.stdin.write('hello\n');
108108
await delay(10);
@@ -176,4 +176,6 @@ test('readme', t => {
176176

177177
python.end();
178178
});
179+
180+
t.end();
179181
});

0 commit comments

Comments
 (0)