From e418f6589c296566a084258db1f5ceb90b9ff5e3 Mon Sep 17 00:00:00 2001 From: angelasofiaremolinagutierrez Date: Sat, 12 Jun 2021 19:14:32 -0500 Subject: [PATCH 1/2] Work-in-progress python3_interpreter activecode directive --- runestone/activecode/activecode.py | 9 ++- runestone/activecode/js/acfactory.js | 9 +++ runestone/activecode/js/activecode.js | 1 + runestone/activecode/js/activecode_brython.js | 59 +++++++++++++++++++ runestone/activecode/js/timed_activecode.js | 9 +++ .../test/_sources/brython_tests.rst | 36 +++++++++++ 6 files changed, 122 insertions(+), 1 deletion(-) create mode 100644 runestone/activecode/js/activecode_brython.js create mode 100644 runestone/activecode/test/_sources/brython_tests.rst diff --git a/runestone/activecode/activecode.py b/runestone/activecode/activecode.py index 3ba7d22cf..b960e3115 100644 --- a/runestone/activecode/activecode.py +++ b/runestone/activecode/activecode.py @@ -71,7 +71,7 @@ def setup(app): %(hidecode)s %(include)s %(timelimit)s %(coach)s %(codelens)s %(enabledownload)s %(chatcodes)s %(optional)s data-audio='%(ctext)s' %(sourcefile)s %(datafile)s %(stdin)s %(tie)s %(dburl)s %(nopair)s %(cargs)s %(largs)s %(rargs)s %(iargs)s %(gradebutton)s %(caption)s %(hidehistory)s %(wasmuri)s - %(showlastsql)s style="visibility: hidden;"> + %(showlastsql)s %(python3_interpreter)s style="visibility: hidden;"> %(initialcode)s @@ -162,6 +162,7 @@ class ActiveCode(RunestoneIdDirective): :nopair: -- disable pair programming features :dburl: url to load database for sql mode :showlastsql: -- Only show the last sql result in output + :python3_interpreter: brython (uses brython as interpreter of python3) If this is a homework problem instead of an example in the text then the assignment text should go here. The assignment text ends with @@ -217,6 +218,7 @@ class ActiveCode(RunestoneIdDirective): "nopair": directives.flag, "dburl": directives.unchanged, "showlastsql": directives.flag, + "python3_interpreter": directives.unchanged } ) @@ -393,6 +395,11 @@ def run(self): else: self.options["wasmuri"] = "" + if ("python3_interpreter" in self.options): #and (self.options["language"]=="python3") : + self.options["python3_interpreter"] = "data-python3_interpreter='{}'".format(self.options["python3_interpreter"]) + else: + self.options["python3_interpreter"] = "" + if self.content: if "^^^^" in self.content: idx = self.content.index("^^^^") diff --git a/runestone/activecode/js/acfactory.js b/runestone/activecode/js/acfactory.js index b064754d8..a3b464f03 100644 --- a/runestone/activecode/js/acfactory.js +++ b/runestone/activecode/js/acfactory.js @@ -2,6 +2,7 @@ import { ActiveCode } from "./activecode.js"; import JSActiveCode from "./activecode_js.js"; import HTMLActiveCode from "./activecode_html.js"; import SQLActiveCode from "./activecode_sql.js"; +import BrythonActiveCode from "./activecode_brython.js"; import LiveCode from "./livecode.js"; import { TimedActiveCode, @@ -9,6 +10,7 @@ import { TimedJSActiveCode, TimedHTMLActiveCode, TimedSQLActiveCode, + TimedBrythonActiveCode } from "./timed_activecode"; import "../../common/js/jquery.highlight.js"; @@ -30,7 +32,11 @@ export default class ACFactory { if (lang === undefined) { lang = $(opts.orig).find("[data-lang]").data("lang"); } + var python3_interpreter = $(opts.orig).data("python3_interpreter"); if (opts.timed == true) { + if(python3_interpreter==="brython"){ + return new TimedBrythonActiveCode(opts); + } if (lang === "python") { return new TimedActiveCode(opts); } else if ( @@ -50,6 +56,9 @@ export default class ACFactory { return new TimedActiveCode(opts); } } else { + if(python3_interpreter==="brython"){ + return new BrythonActiveCode(opts); + } if (lang === "javascript") { return new JSActiveCode(opts); } else if (lang === "htmlmixed") { diff --git a/runestone/activecode/js/activecode.js b/runestone/activecode/js/activecode.js index bf60c122b..db2a7584d 100755 --- a/runestone/activecode/js/activecode.js +++ b/runestone/activecode/js/activecode.js @@ -60,6 +60,7 @@ export class ActiveCode extends RunestoneBase { this.question = $(opts.orig).find(`#${this.divid}_question`)[0]; this.tie = $(orig).data("tie"); this.dburl = $(orig).data("dburl"); + this.python3_interpreter = $(orig).data("python3_interpreter"); this.runButton = null; this.enabledownload = $(orig).data("enabledownload"); this.downloadButton = null; diff --git a/runestone/activecode/js/activecode_brython.js b/runestone/activecode/js/activecode_brython.js new file mode 100644 index 000000000..2a3d2079e --- /dev/null +++ b/runestone/activecode/js/activecode_brython.js @@ -0,0 +1,59 @@ +import { ActiveCode } from "./activecode.js"; + +export default class BrythonActiveCode extends ActiveCode { + constructor(opts) { + super(opts); + opts.alignVertical = true; + //this.code = $("