Skip to content

Commit

Permalink
Consolidate scripts.
Browse files Browse the repository at this point in the history
  • Loading branch information
rixner committed May 29, 2019
1 parent 4f8678d commit 10595dd
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 49 deletions.
22 changes: 5 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,10 @@
"regenparser": "node support/build/regenparser.js",
"prebrun": "npm run devbuild",
"brun": "node support/run/brun.js -p",
"prebrundebug": "npm run devbuild",
"brundebug": "node support/run/brun.js -d -p",
"prebrun3": "npm run devbuild",
"brun3": "node support/run/brun.js --python3 -p",
"brun3debug": "node support/run/brun.js -d -p",
"brun3debug": "node support/run/brun.js --python3 -d -p",
"prebtest": "npm run devbuild && node support/build/wrapmodules.js unit2 && node support/build/wrapmodules.js unit3",
"btest": "node support/run/brun.js -t",
"doc": "echo 'Building Documentation in docs/ProgMan' && jsdoc -c jsdoc.json HACKING.md",
"dist": "npm run build && npm run testopt && npm run test3opt && npm run doc && node support/build/copy2docs.js",
"dist": "npm run build && npm run test && npm run doc && node support/build/copy2docs.js",
"repl": "node repl/repl.js",
"prebuild": "node support/build/wrapmodules.js internal",
"build": "webpack --mode production",
Expand All @@ -27,16 +21,10 @@
"devbuild": "webpack --mode development",
"postdevbuild": "node support/build/wrapmodules.js builtin",
"watch": "webpack --watch --mode development",
"test": "node test/testwrapper.js && node test/testunit.js",
"testopt": "node test/testwrapper.js -o && node test/testunit.js -o",
"test3": "node test/testunit.js skulpt.js --python3",
"test3opt": "node test/testunit.js -o --python3",
"run": "node support/run/runfile.js -p",
"run3": "node support/run/runfile.js --python3 -p",
"profile": "node --prof --no-logfile-per-isolate --log-internal-timer-events support/run/runfile.js -o -p",
"postprofile": "node --prof-process v8.log",
"profile3": "node --prof --no-logfile-per-isolate --log-internal-timer-events support/run/runfile.js -o --python3 -p",
"postprofile3": "node --prof-process v8.log"
"test": "node test/testwrapper.js && node test/testunit.js && node test/testunit.js --python3",
"start": "node support/run/runfile.js",
"profile": "node --prof --no-logfile-per-isolate --log-internal-timer-events support/run/runfile.js -o",
"postprofile": "node --prof-process v8.log"
},
"repository": {
"type": "git",
Expand Down
21 changes: 4 additions & 17 deletions support/run/brun.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function getFileNames (dir) {
return filelist;
}

function brun (test, python3, debug, fname) {
function brun (test, fname) {
var app = express();

// set the view engine to ejs
Expand Down Expand Up @@ -56,8 +56,7 @@ function brun (test, python3, debug, fname) {
res.render(path.resolve('support', 'run', 'test_template'), {
test2: JSON.stringify(unit2),
test3: JSON.stringify(unit3),
files: filecontents,
debug_mode: "false"
files: filecontents
});
});

Expand Down Expand Up @@ -89,20 +88,10 @@ function brun (test, python3, debug, fname) {
// Test file
var prog = fs.readFileSync(fname, 'utf8');

// Python version
var pyver;
if (python3) {
pyver = "Sk.python3";
} else {
pyver = "Sk.python2";
}

// index page
app.get('/', function (req, res) {
res.render(path.resolve('support', 'run', 'run_template'), {
code: prog,
debug_mode: debug ? "true" : "false",
p3: pyver
code: prog
});
});
}
Expand All @@ -114,8 +103,6 @@ function brun (test, python3, debug, fname) {

program
.option('-t, --test', 'Run test suites')
.option('--python3', 'Python 3')
.option('-d, --debug', 'Debug')
.option('-p, --program <file>', 'file to run')
.parse(process.argv);

Expand All @@ -124,4 +111,4 @@ if (!program.test && !program.program) {
process.exit();
}

brun(program.test, program.python3, program.debug, program.program);
brun(program.test, program.program);
23 changes: 19 additions & 4 deletions support/run/run_template.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<html>
<head>
<title></title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.10.0/beautify.min.js"></script>
<script src="skulpt.js" type="text/javascript"></script>
<script src="skulpt-stdlib.js" type="text/javascript"></script>
</head>
Expand All @@ -11,6 +12,7 @@
<p>Remember that you can add a debugger statement to your Python below or in the Skulpt Javascript.</p>

<script type="text/javascript">
Sk.js_beautify = js_beautify;
function outf(text) {
var mypre = document.getElementById(Sk.pre);
Expand All @@ -36,7 +38,7 @@ function builtinRead(x) {
return file;
}
function runit(myDiv) {
function runit(myDiv, pyver) {
var prog = document.getElementById(myDiv+"_code").value;
var mypre = document.getElementById(myDiv+"_pre");
Expand All @@ -59,13 +61,22 @@ function runit(myDiv) {
Sk.pre = myDiv+"_pre";
var future;
if (pyver == "python2") {
future = Sk.python2;
} else if (pyver == "python3") {
future = Sk.python3;
}
var debug = document.getElementById("debug").checked;
Sk.configure({
output:outf,
read: builtinRead,
inputfunTakesPrompt: true,
debugout: showjs,
debugging: <%= debug_mode %>,
__future__: <%= p3 %>
debugging: debug,
__future__: future
});
Sk.onBeforeImport = function() {
Expand Down Expand Up @@ -99,7 +110,11 @@ function runit(myDiv) {
<textarea edit_id="eta_5" id="runbrowser_code" cols="72" rows="20" style="font-family: 'Lucida Console', Monaco, monospace;">
<%- code %>
</textarea>
<button onclick="runit('runbrowser')" type="button">Run</button>
<br>
<input type="checkbox" id="debug">Debug</input>
<br>
<button onclick="runit('runbrowser', 'python2')" type="button">Run Python 2</button>
<button onclick="runit('runbrowser', 'python3')" type="button">Run Python 3</button>
</form>

<h3>Canvas</h3>
Expand Down
21 changes: 15 additions & 6 deletions support/run/runfile.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const fs = require('fs');
const path = require('path');
const program = require('commander');
const chalk = require('chalk');
const reqskulpt = require('./require-skulpt').requireSkulpt;

function run (python3, opt, filename) {
Expand Down Expand Up @@ -47,14 +48,22 @@ function run (python3, opt, filename) {
}

program
.option('--python3', 'Python 3')
.option('-o, --opt', 'use optimized skulpt')
.option('-p, --program <file>', 'file to run')
.parse(process.argv);

if (!program.program) {
console.log("error: option `-p, --program <file>' must specify a program to run");
process.exit();
if (program.args.length != 2) {
console.log(chalk.red("error: must specify python version (py2/py3) and python program to run"));
process.exit(1);
}

run(program.python3, program.opt, program.program);
var py3;
if (program.args[0] == "py2") {
py3 = false;
} else if (program.args[0] == "py3") {
py3 = true;
} else {
console.log(chalk.red("error: must specify python version ('py2' or 'py3'), not '" + program.args[0] + "'"));
process.exit(1);
}

run(py3, program.opt, program.args[1]);
13 changes: 8 additions & 5 deletions test/testunit.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ function test (python3, opt) {
// Import Skulpt
var skulpt = reqskulpt(false);
if (skulpt === null) {
process.exit(1);
process.exit(1);
}

Sk.js_beautify = require('js-beautify').js;

// Setup for appropriate Python version
Expand Down Expand Up @@ -53,11 +53,14 @@ function test (python3, opt) {

function runtest (tests, passed, failed) {
if (tests.length == 0) {
endtime = Date.now();
elapsed = (endtime - starttime) / 1000;
endtime = Date.now();
elapsed = (endtime - starttime) / 1000;
console.log("Summary");
console.log("Passed: " + passed + " Failed: " + failed);
console.log("Total run time for all unit tests: " + elapsed.toString() + "s");
console.log("Total run time for all unit tests: " + elapsed.toString() + "s");
if (failed > 0) {
process.exit(1);
}
return;
}

Expand Down

0 comments on commit 10595dd

Please sign in to comment.