Skip to content

Commit

Permalink
TIFA restructuring, minor changes to type stuff, improvements to bloc…
Browse files Browse the repository at this point in the history
…kpy environment, additions to CAIT.
  • Loading branch information
acbart committed Aug 6, 2020
1 parent 902fb15 commit 3dda9c7
Show file tree
Hide file tree
Showing 15 changed files with 1,780 additions and 1,683 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ __pycache__/
build/
develop-eggs/
dist/
dist-js/
downloads/
eggs/
.eggs/
Expand Down
2 changes: 1 addition & 1 deletion pedal/cait/cait_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ def get_data_state(self):
if self.ast_name != "Name":
return None
try:
return self.report['tifa']["top_level_variables"][self.id]
return self.report['tifa']['latest'].top_level_variables[self.id]
except KeyError:
return None

Expand Down
11 changes: 6 additions & 5 deletions pedal/cait/find_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,28 +37,29 @@ def find_operation(op_name, root=None, report=MAIN_REPORT):
Supports all comparison, boolean, binary, and unary operators.
"""
root = root or parse_program(report=report)
found = []
if op_name in COMPARE_OP_NAMES:
compares = root.find_all("Compare")
for compare in compares:
for op in compare.ops:
if op.ast_name == COMPARE_OP_NAMES[op_name]:
yield compare
found.append(compare)
elif op_name in BOOL_OP_NAMES:
boolops = root.find_all("BoolOp")
for boolop in boolops:
if boolop.op_name == BOOL_OP_NAMES[op_name]:
yield boolop
found.append(boolop)
elif op_name in BIN_OP_NAMES:
binops = root.find_all("BinOp")
for binop in binops:
if binop.op_name == BIN_OP_NAMES[op_name]:
yield binop
found.append(binop)
elif op_name in UNARY_OP_NAMES:
unaryops = root.find_all("UnaryOp")
for unaryop in unaryops:
if unaryop.op_name == UNARY_OP_NAMES[op_name]:
yield unaryop
return []
found.append(unaryop)
return found


def find_function_calls(name: str, root=None, report=MAIN_REPORT):
Expand Down
2 changes: 1 addition & 1 deletion pedal/core/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
__all__ = ['feedback', 'set_success', 'compliment', 'give_partial', 'explain',
'gently', 'hide_correctness', 'suppress', 'log', 'debug',
'system_error', 'clear_report', 'get_all_feedback', 'guidance',
'contextualize_report']
'contextualize_report', 'Feedback']

from pedal.core.feedback import (Feedback, FeedbackKind, FeedbackCategory,
FeedbackResponse)
Expand Down
6 changes: 4 additions & 2 deletions pedal/core/feedback.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ class Feedback:
_stored_args: tuple
_stored_kwargs: dict

#MAIN_REPORT

def __init__(self, *args, label=None,
category=None, justification=None,
fields=None, field_names=None,
Expand Down Expand Up @@ -239,8 +241,8 @@ def _handle_condition(self):
else:
self.report.add_ignored_feedback(self)
# Free up these temporary fields after condition is handled
del self._stored_args
del self._stored_kwargs
# del self._stored_args
# del self._stored_kwargs
if self._exception is not None:
raise self._exception

Expand Down
14 changes: 7 additions & 7 deletions pedal/environments/blockpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@
from pedal.cait.cait_api import parse_program
from pedal.sandbox.commands import *
# TODO: Set up mock coverage tool in BlockPy
# Monkey-patch trace_lines
from pedal.sandbox import commands
commands.trace_lines = trace_lines
# TODO: Refactor resolver to return instructions
# Monkey-patch questions
from pedal import questions
Expand All @@ -49,6 +45,8 @@
from pedal.core.environment import Environment
from pedal.core.report import MAIN_REPORT
from pedal.sandbox import Sandbox
from pedal.tifa import tifa_analysis


def enhance_runtime_errors(feedback):
line.replace(', in <module>', '', 1)
Expand All @@ -66,12 +64,14 @@ def __init__(self, files=None, main_file='answer.py', main_code=None,
user=user, assignment=assignment, course=course,
execution=execution, instructor_file=instructor_file,
report=report)
if not skip_tifa:
tifa_analysis(report=self.report)


def setup_pedal(self):
student = MAIN_REPORT['sandbox']['run'] = Sandbox(report=self.report)
student.report_exceptions_mode = True
commands.run_student(raise_exceptions=False)
pass
#student = MAIN_REPORT['sandbox']['run'] = Sandbox(report=self.report)
#commands.run_student()

setup_pedal = BlockPyEnvironment

Expand Down
8 changes: 4 additions & 4 deletions pedal/environments/standard.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ def __init__(self, files=None, main_file='answer.py', main_code=None,
else:
from pedal.tifa import tifa_analysis
self.tifa = tifa_analysis(report=report)
self.student = run(threaded=True, raise_exceptions=True, report=report)
self.student.report_exceptions_mode = True
self.student = run(threaded=True, report=report)
self.set_success = set_success

def print_resolve(self, *args, **kwargs):
Expand All @@ -66,8 +65,9 @@ def print_resolve(self, *args, **kwargs):
Title/Label/Score/Message. Any arguments are forwarded to
:py:func:`pedal.resolvers.simple.resolve`
"""
resolve_all(set_successful=self.set_success, no_phases_is_success=True,
report=self.report)
#resolve_all(set_successful=self.set_success, no_phases_is_success=True,
# report=self.report)
# TODO: Fix resolve_all
result = simple.resolve(*args, **kwargs)
# print("Feedback Label:", result.label)
print("Title:", result.title)
Expand Down
25 changes: 16 additions & 9 deletions pedal/tifa/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,24 +69,31 @@
(Path x Fully Qualified Names) => States
"""
from pedal.tifa.constants import TOOL_NAME
from pedal.tifa.tifa import Tifa
from pedal.tifa.tifa_visitor import Tifa
from pedal.core.report import MAIN_REPORT, Report



def tifa_analysis(report=None):
def tifa_analysis(code=None, report=MAIN_REPORT):
"""
Perform the TIFA analysis and attach the results to the Report.
Args:
code (str or None): The code to evaluate with TIFA. If ``code`` is not
given, then it will default to the student's main file.
report (:class:`pedal.core.report.Report`): The Report object to
attach results to.
Returns:
:py:class:`pedal.tifa.tifa_core.TifaAnalysis`: A TifaAnalysis data
bundle containing all the information that TIFA learned.
"""
if report is None:
report = MAIN_REPORT
t = Tifa(report=report)
t.process_code(report.submission.main_code)
return t
if code is None:
code = report.submission.main_code
if code in report[TOOL_NAME]['analyses']:
return report[TOOL_NAME]['analyses'][code]
result = report[TOOL_NAME]['instance'].process_code(code)
report[TOOL_NAME]['analyses'][code] = result
report[TOOL_NAME]['latest'] = result
return result


def reset(report=MAIN_REPORT):
Expand All @@ -99,7 +106,7 @@ def reset(report=MAIN_REPORT):
# TODO: Make it so we can reset TIFA through this, safely.
report[TOOL_NAME] = {
'analyses': {},
'main_analysis': None,
'latest': None,
'instance': Tifa(report=report)
}
return report[TOOL_NAME]
Expand Down
Loading

0 comments on commit 3dda9c7

Please sign in to comment.