diff --git a/README.md b/README.md index 706a534..97944df 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,7 @@ console.log(new Foo().bar); One of the following languages is set in `lang`. - `js` JavaScript (Node 10.14.2) -- `py` Python (CPython 3.6.8) +- `py` Python (CPython 3.6.8, CPython 2.7.15) - `hs` Haskell (GHC 8.4.3) - `pas` Pascal (FPC 3.0.4) - `go` Go (Go 1.12) @@ -73,7 +73,7 @@ For JavaScript: - `harmony` enables harmony features (`--harmony` on node) For Python: -- None +- `2` runs Python 2 instead of Python 3 For Haskell: - None @@ -96,7 +96,7 @@ For JavaScript: - cheerio For Python: -- numpy +- numpy (Python 3 only) For Haskell: - GHC libraries diff --git a/docker/python2/Dockerfile b/docker/python2/Dockerfile new file mode 100644 index 0000000..f71d20a --- /dev/null +++ b/docker/python2/Dockerfile @@ -0,0 +1,8 @@ +FROM alpine +LABEL author="1Computer1" + +RUN apk update +RUN apk add build-base python2 + +COPY run.sh /var/run/ +WORKDIR /var/ws diff --git a/docker/python2/run.sh b/docker/python2/run.sh new file mode 100644 index 0000000..f07bd5a --- /dev/null +++ b/docker/python2/run.sh @@ -0,0 +1,2 @@ +echo "$1" > program.py +python program.py diff --git a/src/languages/python.js b/src/languages/python.js index cb14b5b..3d5f0c3 100644 --- a/src/languages/python.js +++ b/src/languages/python.js @@ -4,9 +4,21 @@ class Python extends Language { constructor() { super('python', { highlight: 'py', - aliases: ['python', 'py'] + aliases: ['python', 'py'], + loads: ['python', 'python2'], + options: { + 2: () => '' + } }); } + + runWith(options) { + if (options.has('2')) { + return { id: 'python2', env: {} }; + } + + return { id: 'python', env: {} }; + } } module.exports = Python; diff --git a/src/struct/Language.js b/src/struct/Language.js index 77b91ee..cb22ca7 100644 --- a/src/struct/Language.js +++ b/src/struct/Language.js @@ -5,12 +5,14 @@ class Language extends AkairoModule { category, highlight, aliases, + loads = [id], options = {} } = {}) { super(id, { category }); this.highlight = highlight; this.aliases = aliases; + this.loads = loads; this.options = options; } diff --git a/src/struct/LanguageHandler.js b/src/struct/LanguageHandler.js index f362927..3f00fef 100644 --- a/src/struct/LanguageHandler.js +++ b/src/struct/LanguageHandler.js @@ -51,9 +51,11 @@ class LanguageHandler extends AkairoHandler { } buildDocker() { - return Promise.all(this.modules.map(({ id }) => { - const folder = path.join(__dirname, '../../docker', id); - return util.promisify(childProcess.exec)(`docker build -t "1computer1/comp_iler:${id}" ${folder}`); + return Promise.all(this.modules.map(({ loads }) => { + return Promise.all(loads.map(name => { + const folder = path.join(__dirname, '../../docker', name); + return util.promisify(childProcess.exec)(`docker build -t "1computer1/comp_iler:${name}" ${folder}`); + })); })); }