Skip to content

Commit 8db6cc3

Browse files
committed
first version
1 parent 6707c19 commit 8db6cc3

File tree

6 files changed

+182
-27
lines changed

6 files changed

+182
-27
lines changed

package-lock.json

Lines changed: 161 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
"description": "Python Compiler for learnpack tutorials",
44
"version": "0.0.1",
55
"author": "Alejandro Sanchez @alesanchezr",
6-
"bugs": "https://github.com/learnpack/python-compiler/issues",
6+
"bugs": "https://github.com/learnpack/learnpack/issues",
77
"dependencies": {
88
"@oclif/command": "^1.6.1",
99
"@oclif/config": "^1.15.1",
10+
"chalk": "^4.1.0",
1011
"compile-run": "^2.3.2",
1112
"shelljs": "^0.8.4"
1213
},

src/compile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module.exports = {
99
return true
1010
},
1111
run: async function ({ exercise, socket }) {
12-
12+
console.log("Compiling python for ", exercise)
1313
let entryPath = exercise.files.map(f => './'+f.path).find(f => f.indexOf('app.py') > -1);
1414
if(!entryPath) throw new Error("No app.py entry file");
1515

src/test.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
const fs = require('fs')
2+
const chalk = require("chalk")
23
const shell = require('shelljs')
34
const { Utils, TestingError } = require('./utils/index.js')
45

56
module.exports = {
6-
capture: "sys",
7-
color: "yes",
87
validate: async function({ exercise, configuration }){
98

109
if (!shell.which('pytest')) {
@@ -28,7 +27,7 @@ def pytest_generate_tests(metafunc):
2827
metafunc.parametrize("stdin",metafunc.configuration.getoption('stdin'))
2928
if 'app' in metafunc.fixturenames:
3029
try:
31-
sys.path.append('${configuration.configPath.output}')
30+
sys.path.append('${configuration.outputPath}')
3231
import cached_app
3332
metafunc.parametrize("app",[cached_app.execute_app])
3433
except SyntaxError:
@@ -46,8 +45,9 @@ def pytest_generate_tests(metafunc):
4645
run: async ({ exercise, socket, configuration }) => {
4746

4847
const getEntry = () => {
48+
console.log(exercise);
4949
let entryPath = exercise.files.map(f => './'+f.path).find(f => f.indexOf('test.py') > -1 || f.indexOf('tests.py') > -1)
50-
if (!fs.existsSync(entryPath)) throw TestingError(`🚫 No tests.py script found on the exercise files`)
50+
if (!fs.existsSync(entryPath)) throw TestingError(`🚫 No tests.py script found on the exercise in ${entryPath}`)
5151

5252
const appPath = exercise.files.map(f => './'+f.path).find(f => f.indexOf('app.py') > -1)
5353
if (fs.existsSync(appPath)){
@@ -58,7 +58,7 @@ def pytest_generate_tests(metafunc):
5858
// Adding main execute_app function for all the code
5959
content = `def execute_app():\n${Utils.indent(content, 4)}`
6060
}
61-
const directory = `${configuration.configPath.output}/cached_app.py`
61+
const directory = `${configuration.outputPath}/cached_app.py`
6262
fs.writeFileSync(directory, content)
6363
}
6464
else if(configuration.grading === "isolated") throw TestingError(`🚫 No app.py script found on the exercise files`)
@@ -74,10 +74,10 @@ def pytest_generate_tests(metafunc):
7474
const count = Utils.getMatches(/input\((?:["'`]{1}(.*)["'`]{1})?\)/gm, content)
7575
let answers = (count.length == 0) ? [] : await socket.ask(count)
7676

77-
return `pytest ${getEntry()} --testdox --capture=${this.capture} --color=${this.color} --stdin='${JSON.stringify(answers)}'`
77+
return `pytest ${getEntry()} --testdox --capture=sys --color=yes --stdin='${JSON.stringify(answers)}'`
7878
}
7979
else{
80-
return `pytest ${getEntry()} --testdox --capture=${this.capture} --color=${this.color}`
80+
return `pytest ${getEntry()} --testdox --capture=sys --color=yes`
8181
}
8282
}
8383

@@ -95,7 +95,9 @@ def pytest_generate_tests(metafunc):
9595

9696
let _stdout = [rawStdout]
9797
if(errors.length > 0){
98-
msg = `\n\n ${'Your code must to comply with the following tests:'.red} \n\n${[...new Set(errors)].map((e,i) => ` ${e.status !== 'failed' ? '✓ (done)'.green.bold : 'x (fail)'.red.bold} ${i}. ${e.title.white}`).join('\n')} \n\n`
98+
msg = `\n\n
99+
${chalk.red('Your code must to comply with the following tests:')} \n\n
100+
${[...new Set(errors)].map((e,i) => ` ${e.status !== 'failed' ? chalk.green.bold('✓ (done)') : chalk.red.bold('x (fail)')} ${i}. ${chalk.white(e.title)}`).join('\n')} \n\n`
99101
_stdout.push(msg)
100102
}
101103
return _stdout
@@ -111,7 +113,7 @@ def pytest_generate_tests(metafunc):
111113
stderr = resp.stderr
112114
if(code != 0) break
113115
}
114-
if(code != 0) return getStdout(stdout || stderr)
116+
if(code != 0) throw TestingError(getStdout(stdout || stderr).join())
115117
else return stdout
116118
}
117119
}

src/utils/command/test.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,18 @@ const TestingError = (messages) => {
1111
module.exports = {
1212
TestingError,
1313
default: async function(args){
14-
const { action, configuration, slug } = args;
14+
const { action, configuration, socket, exercise } = args;
1515

16-
if (!fs.existsSync(`${configuration.configPath.base}/reports`)){
16+
if (!fs.existsSync(`${configuration.dirPath}/reports`)){
1717
// reports directory
18-
fs.mkdirSync(`${configuration.configPath.base}/reports`);
18+
fs.mkdirSync(`${configuration.dirPath}/reports`);
1919
}
2020

21+
// compile
2122
const stdout = await action.run(args)
2223

23-
configuration.exercises = configuration.exercises.map(e => {
24-
if(e.slug === slug) e.done = true;
25-
return e;
26-
});
24+
// mark exercise as done
25+
exercise.done = true;
2726

2827
return stdout
2928
}

src/utils/plugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const shell = require('shelljs')
77
module.exports = (pluginConfig) => {
88
return async (args) => {
99
const { action, exercise, socket, configuration } = args
10-
console.log("asadsadsads", configuration)
10+
1111
if(pluginConfig.language === undefined) throw Error(`Missing language on the plugin configuration object`)
1212

1313
if(typeof action !== "string"){

0 commit comments

Comments
 (0)