Skip to content

Commit 0c76bc7

Browse files
committed
fixed compile and test
1 parent 4b2b354 commit 0c76bc7

File tree

4 files changed

+18
-10
lines changed

4 files changed

+18
-10
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ $ npm install -g learnpack-python
1919
$ oclif-example COMMAND
2020
running command...
2121
$ oclif-example (-v|--version|version)
22-
learnpack-python/0.0.34 darwin-x64 node-v10.17.0
22+
learnpack-python/0.0.35 darwin-x64 node-v14.16.0
2323
$ oclif-example --help [COMMAND]
2424
USAGE
2525
$ oclif-example COMMAND

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "learnpack-python",
33
"description": "Python Compiler for learnpack tutorials",
4-
"version": "0.0.34",
4+
"version": "0.0.35",
55
"author": "Alejandro Sanchez @alesanchezr",
66
"bugs": "https://github.com/learnpack/learnpack/issues",
77
"dependencies": {

src/compile.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,25 @@ module.exports = {
1010
},
1111
run: async function ({ exercise, socket }) {
1212

13-
let entryPath = exercise.entry || exercise.files.map(f => './'+f.path).find(f => f.indexOf('app.py') > -1);
13+
let entryPath = exercise.files.map(f => './'+f.path).find(f => f.includes(exercise.entry || 'app.py'));
1414
if(!entryPath) throw new Error("No entry file to compile, maybe you need to create an app.py in the exercise directory?");
1515

1616
const content = fs.readFileSync(entryPath, "utf8");
17-
const count = Utils.getMatches(/^([^\/])+input\((?:["'`]{1}(.*)["'`]{1})?\)/gm, content);
17+
const count = Utils.getMatches(/^(?:[^\/])+input\s*\(\s*(?:["'`]{1}(.*)["'`]{1})?\s*\)\s*/gm, content);
1818
let inputs = (count.length == 0) ? [] : await socket.ask(count);
19-
19+
2020
const result = await python.runFile(entryPath, { stdin: inputs.join('\n'), executionPath: 'python3' })
2121
if(result.exitCode > 0) throw CompilationError(result.stderr);
22-
return Utils.cleanStdout(result.stdout, count)
22+
return cleanStdout(result.stdout, inputs)
2323

2424
},
2525
}
26-
26+
27+
const cleanStdout = (buffer, inputs) => {
28+
29+
// if(Array.isArray(inputs))
30+
// for(let i = 0; i < inputs.length; i++)
31+
// if(inputs[i]) buffer = buffer.replace(inputs[i],'');
32+
33+
return buffer;
34+
}

src/test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ def pytest_generate_tests(metafunc):
5151

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

57-
const appPath = exercise.files.map(f => './'+f.path).find(f => f.indexOf('app.py') > -1)
57+
const appPath = exercise.files.map(f => './'+f.path).find(f => f.includes(exercise.entry || 'app.py'))
5858
if (fs.existsSync(appPath)){
5959
let content = fs.readFileSync(appPath, "utf8")
6060
const count = Utils.getMatches(/def\s[a-zA-Z]/gm, content)
@@ -73,7 +73,7 @@ def pytest_generate_tests(metafunc):
7373

7474
const getCommands = async function(){
7575

76-
const appPath = exercise.entry || exercise.files.map(f => './'+f.path).find(f => f.indexOf('app.py') > -1)
76+
const appPath = exercise.files.map(f => './'+f.path).find(f => f.includes(exercise.entry || 'app.py'))
7777
if(appPath !== undefined){
7878
const content = fs.readFileSync(appPath, "utf8")
7979
const count = Utils.getMatches(/^([^\/])+input\((?:["'`]{1}(.*)["'`]{1})?\)/gm, content)

0 commit comments

Comments
 (0)