Commit 80e37fcd authored by Romain Casati's avatar Romain Casati
Browse files

Ignoring comments on import line in PythonTutor.

parent 9d9ffb60
......@@ -12,6 +12,7 @@ from urllib.parse import quote
import json
from .generate_trace import generate_trace
from basthon import kernel
import re
__author__ = "Romain Casati"
__license__ = "GNU GPL v3"
......@@ -70,16 +71,18 @@ def tutor(**kwargs):
lines = code.split('\n')
# listing tutor import lines then remove
# this is hacky... and should be implemented with inspect
# this is hacky... and should be implemented with inspect or tokenize
regex_comment = re.compile(r'^([^#]*)#(.*)$')
import_lines = [i for i, line in enumerate(lines)
if line in ('import tutor',
'from tutor import tutor',
'from tutor import *')]
if regex_comment.sub(r'\1', line).rstrip() in (
'import tutor',
'from tutor import tutor',
'from tutor import *')]
for index in import_lines[::-1]:
del lines[index]
# listing tutor() call lines
# this is hacky... and should be implemented with inspect
# this is hacky... and should be implemented with inspect or tokenize
tutor_lines = [i for i, line in enumerate(lines)
if line.startswith('tutor.tutor(')
or line.startswith('tutor(')]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment