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`.
- `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

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() {
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;

View file

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

View file

@ -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}`);
}));
}));
}