Add ability for multiple compilers; add Python2

This commit is contained in:
1computer1 2019-03-13 01:13:49 -04:00
parent 318a485bfb
commit 2dd50d8069
6 changed files with 33 additions and 7 deletions

View file

@ -60,7 +60,7 @@ console.log(new Foo().bar);
One of the following languages is set in `lang`. One of the following languages is set in `lang`.
- `js` JavaScript (Node 10.14.2) - `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) - `hs` Haskell (GHC 8.4.3)
- `pas` Pascal (FPC 3.0.4) - `pas` Pascal (FPC 3.0.4)
- `go` Go (Go 1.12) - `go` Go (Go 1.12)
@ -73,7 +73,7 @@ For JavaScript:
- `harmony` enables harmony features (`--harmony` on node) - `harmony` enables harmony features (`--harmony` on node)
For Python: For Python:
- None - `2` runs Python 2 instead of Python 3
For Haskell: For Haskell:
- None - None
@ -96,7 +96,7 @@ For JavaScript:
- cheerio - cheerio
For Python: For Python:
- numpy - numpy (Python 3 only)
For Haskell: For Haskell:
- GHC libraries - GHC libraries

View file

@ -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

2
docker/python2/run.sh Normal file
View file

@ -0,0 +1,2 @@
echo "$1" > program.py
python program.py

View file

@ -4,9 +4,21 @@ class Python extends Language {
constructor() { constructor() {
super('python', { super('python', {
highlight: 'py', 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; module.exports = Python;

View file

@ -5,12 +5,14 @@ class Language extends AkairoModule {
category, category,
highlight, highlight,
aliases, aliases,
loads = [id],
options = {} options = {}
} = {}) { } = {}) {
super(id, { category }); super(id, { category });
this.highlight = highlight; this.highlight = highlight;
this.aliases = aliases; this.aliases = aliases;
this.loads = loads;
this.options = options; this.options = options;
} }

View file

@ -51,9 +51,11 @@ class LanguageHandler extends AkairoHandler {
} }
buildDocker() { buildDocker() {
return Promise.all(this.modules.map(({ id }) => { return Promise.all(this.modules.map(({ loads }) => {
const folder = path.join(__dirname, '../../docker', id); return Promise.all(loads.map(name => {
return util.promisify(childProcess.exec)(`docker build -t "1computer1/comp_iler:${id}" ${folder}`); const folder = path.join(__dirname, '../../docker', name);
return util.promisify(childProcess.exec)(`docker build -t "1computer1/comp_iler:${name}" ${folder}`);
}));
})); }));
} }