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.
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)
3 changes: 1 addition & 2 deletions pytutor/pg_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
# of all in-scope data structures after each executed instruction.


import imp
import sys
import bdb # the KEY import here!
import re
Expand Down Expand Up @@ -1353,7 +1352,7 @@ def _runscript(self, script_str):
# which emulates "from <module> import *"
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
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
setup(
name='pytutor',
packages=['pytutor'], # this must be the same as the name above
version='1.0.0',
version='1.0.1',
description='An interface to run Phillip Guo\'s Python Tutor',
author='Sumukh Sridhara',
author_email='sumukh@berkeley.edu',
Expand Down