diff --git a/common/lib/calc/calc/__init__.py b/common/lib/calc/calc/__init__.py index e0d80d7b89..d79035ca09 100644 --- a/common/lib/calc/calc/__init__.py +++ b/common/lib/calc/calc/__init__.py @@ -3,4 +3,5 @@ Ideally, we wouldn't need to pull in all the calc symbols here, but courses were using 'import calc', so we need this for backwards compatibility """ -from calc import * +from __future__ import absolute_import +from .calc import * diff --git a/common/lib/calc/calc/calc.py b/common/lib/calc/calc/calc.py index 03af7d9b1c..47066e9c0f 100644 --- a/common/lib/calc/calc/calc.py +++ b/common/lib/calc/calc/calc.py @@ -4,6 +4,7 @@ Parser and evaluator for FormulaResponse and NumericalResponse Uses pyparsing to parse. Main function as of now is evaluator(). """ +from __future__ import absolute_import import math import numbers import operator @@ -27,7 +28,9 @@ from pyparsing import ( stringEnd ) -import functions +from . import functions +import six +from functools import reduce # Functions available by default # We use scimath variants which give complex results when needed. For example: @@ -103,7 +106,7 @@ def lower_dict(input_dict): variables that have the same lowercase representation. It would be hard to tell which is used in the final dict and which isn't. """ - return {k.lower(): v for k, v in input_dict.iteritems()} + return {k.lower(): v for k, v in six.iteritems(input_dict)} # The following few functions define evaluation actions, which are run on lists diff --git a/common/lib/calc/calc/functions.py b/common/lib/calc/calc/functions.py index d0ac4f7a3d..830e6faa85 100644 --- a/common/lib/calc/calc/functions.py +++ b/common/lib/calc/calc/functions.py @@ -4,6 +4,7 @@ Provide the mathematical functions that numpy doesn't. Specifically, the secant/cosecant/cotangents and their inverses and hyperbolic counterparts """ +from __future__ import absolute_import import numpy diff --git a/common/lib/calc/calc/preview.py b/common/lib/calc/calc/preview.py index d11d611de9..544776e4ad 100644 --- a/common/lib/calc/calc/preview.py +++ b/common/lib/calc/calc/preview.py @@ -8,7 +8,9 @@ Because intermediate values of the render contain more data than simply the string of latex, store it in a custom class `LatexRendered`. """ -from calc import DEFAULT_FUNCTIONS, DEFAULT_VARIABLES, SUFFIXES, ParseAugmenter +from __future__ import absolute_import +from .calc import DEFAULT_FUNCTIONS, DEFAULT_VARIABLES, SUFFIXES, ParseAugmenter +from functools import reduce class LatexRendered(object): diff --git a/common/lib/calc/calc/tests/test_calc.py b/common/lib/calc/calc/tests/test_calc.py index befb0afc25..f6ef992b01 100644 --- a/common/lib/calc/calc/tests/test_calc.py +++ b/common/lib/calc/calc/tests/test_calc.py @@ -2,10 +2,12 @@ Unit tests for calc.py """ +from __future__ import absolute_import import unittest import numpy import calc from pyparsing import ParseException +from six.moves import zip # numpy's default behavior when it evaluates a function outside its domain # is to raise a warning (not an exception) which is then printed to STDOUT. diff --git a/common/lib/calc/calc/tests/test_preview.py b/common/lib/calc/calc/tests/test_preview.py index 36d9acbd81..df3913c25f 100644 --- a/common/lib/calc/calc/tests/test_preview.py +++ b/common/lib/calc/calc/tests/test_preview.py @@ -3,6 +3,7 @@ Unit tests for preview.py """ +from __future__ import absolute_import import unittest from calc import preview import pyparsing diff --git a/common/lib/calc/setup.py b/common/lib/calc/setup.py index d62dd9b6eb..453783184e 100644 --- a/common/lib/calc/setup.py +++ b/common/lib/calc/setup.py @@ -1,3 +1,4 @@ +from __future__ import absolute_import from setuptools import setup setup(