Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ tmp

# pip-related files
*.egg-info
dist
pip-selfcheck.json

# ok-related files
Expand Down
Binary file added dist/pytutor-1.0.0-py3-none-any.whl
Binary file not shown.
Binary file added dist/pytutor-1.0.1-py3-none-any.whl
Binary file not shown.
Binary file added dist/pytutor-1.0.1.tar.gz
Binary file not shown.
13 changes: 13 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import json
from pytutor import generate_trace, server

code = """
num = input("Enter a number: ")
print(num)
"""
trace = generate_trace.run(code, "[]")
print(trace)

print("=========================================")
trace = generate_trace.run(code, "[10]")
print(trace)
15 changes: 15 additions & 0 deletions pytutor/generate_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,18 @@ def run_logger(source, setup, modules=None):
custom_modules={'pg_setup': setup},
extra_modules=modules)

def run(source, raw_input, setup="", modules=None):
modules = modules or {}
# Add current directory to path to make sure that imports work consistently
sys.path.append(os.getcwd() + '/')

finalizer = lambda code,trace: json_finalizer(code, trace, modules)
return pg_logger.exec_script_str_local(source,
raw_input, # JSON list of strings for simulated raw_
True, # output cumulative trace (to display exited frames)
False, # render primitives as heap objects
finalizer,
separate_stdout_by_module=False,
disable_security_checks=True,
custom_modules={'pg_setup': setup},
extra_modules=modules)
1 change: 1 addition & 0 deletions pytutor/pg_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -1354,6 +1354,7 @@ def _runscript(self, script_str):
for mn in self.custom_modules:
# http://code.activestate.com/recipes/82234-importing-a-dynamically-generated-module/
new_m = imp.new_module(mn)
# new_m = types.ModuleType(mn)
exec(self.custom_modules[mn], new_m.__dict__) # exec in custom globals
user_globals.update(new_m.__dict__)

Expand Down