Skip to content

Commit

Permalink
test separate py scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmyolo committed Jun 8, 2021
1 parent 0bc1b93 commit 5209eca
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 5 deletions.
20 changes: 20 additions & 0 deletions helper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict';

const path = require('path');
const util = require('util');

const { PythonShell } = require('python-shell');
const runPy = util.promisify(PythonShell.run);

const OPTIONS = {
mode: 'text',
pythonPath: '/usr/bin/python3',
pythonOptions: ['-u'], // get print results in real-time
scriptPath: path.resolve(__dirname, './scripts'),
args: [],
}

module.exports = {
defaultOptions: OPTIONS,
runPy,
};
6 changes: 6 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
'use strict';

module.exports = {
hello1: require('./src/hello1'),
hello2: require('./src/hello2'),
};
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
"name": "py-hello-test",
"version": "0.0.2",
"description": "",
"bin": {
"hello1": "./hello1.py",
"hello2": "./hello2.py"
},
"scripts": {
"hello1": "python hello1.py",
"hello1:py": "python scripts/hello1.py",
"hello1": "node src/hello1.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"devDependencies": {
"release-it": "^14.8.0"
},
"dependencies": {
"python-shell": "^3.0.0"
}
}
File renamed without changes.
File renamed without changes.
6 changes: 6 additions & 0 deletions src/hello1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
'use strict';

const { runPy, defaultOptions } = require('../helper');

module.exports = (opts = {}) =>
runPy('hello1.py', { ...defaultOptions, ...opts });
6 changes: 6 additions & 0 deletions src/hello2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
'use strict';

const { runPy, defaultOptions } = require('../helper');

module.exports = (opts = {}) =>
runPy('hello2.py', { ...defaultOptions, ...opts });

0 comments on commit 5209eca

Please sign in to comment.