diff --git a/quantdsl/application/with_multithreading.py b/quantdsl/application/with_multithreading.py index ecc783d..afdd90a 100644 --- a/quantdsl/application/with_multithreading.py +++ b/quantdsl/application/with_multithreading.py @@ -5,7 +5,8 @@ from quantdsl.application.base import QuantDslApplication from quantdsl.domain.model.contract_valuation import ContractValuation -from quantdsl.exceptions import DslError, TimeoutError +from quantdsl.exceptions import DslError, TimeoutError, DslCompareArgsError, DslBinOpArgsError, \ + DslIfTestExpressionError class ServiceExit(Exception): @@ -34,6 +35,7 @@ def protected_loop_on_evaluation_queue(self): if not self.has_thread_errored.is_set(): self.thread_exception = e self.has_thread_errored.set() + if not isinstance(e, (TimeoutError, DslCompareArgsError, DslBinOpArgsError, DslIfTestExpressionError)): raise def get_result(self, contract_valuation): diff --git a/quantdsl/semantics.py b/quantdsl/semantics.py index a8ada56..f693c2d 100644 --- a/quantdsl/semantics.py +++ b/quantdsl/semantics.py @@ -7,7 +7,7 @@ from abc import ABCMeta, abstractmethod from collections import namedtuple -import numexpr +# import numexpr import scipy import scipy.linalg import six @@ -375,7 +375,8 @@ def op(self, value): return not value -NUMEXPR_OPS = ['+', '-', '*', '/', '**', '%'] +# NUMEXPR_OPS = ['+', '-', '*', '/', '**', '%'] +NUMEXPR_OPS = [] class BinOp(DslExpression): diff --git a/quantdsl/syntax.py b/quantdsl/syntax.py index b21492f..10c6f7c 100644 --- a/quantdsl/syntax.py +++ b/quantdsl/syntax.py @@ -1,11 +1,29 @@ import ast -import importlib import six +import sys from quantdsl.exceptions import DslSyntaxError from quantdsl.semantics import FunctionDef, DslNamespace +if six.PY3: + from importlib._bootstrap import PathFinder +else: + PathFinder = None + + +def find_module_path(name): + # Find path. + if PathFinder is not None: + path_finder = PathFinder() + spec = path_finder.find_spec(fullname=name) + path = spec.origin + else: + __import__(name) + module = sys.modules[name] + path = module.__file__.strip('c') # .py not .pyc + return path + class DslParser(object): @@ -96,21 +114,20 @@ def visitImportFrom(self, node): if node.module == 'quantdsl.semantics': return [] from_names = [a.name for a in node.names] - dsl_module = self.import_python_module(node.module) + dsl_module = self.import_dsl_module(node.module) nodes = [] for node in dsl_module.body: if isinstance(node, FunctionDef) and node.name in from_names: nodes.append(node) return nodes - def import_python_module(self, module_name): - nodes = [] - module = importlib.import_module(module_name) - path = module.__file__.strip('c') - source = open(path).read() # .py not .pyc - dsl_node = self.parse(source, filename=path) - assert isinstance(dsl_node, self.dsl_classes['Module']), type(dsl_node) - return dsl_node + def import_dsl_module(self, name): + path = find_module_path(name) + with open(path) as f: + source = f.read() + dsl_module = self.parse(source, filename=path) + assert isinstance(dsl_module, self.dsl_classes['Module']), type(dsl_module) + return dsl_module def visitReturn(self, node): """ diff --git a/requirements.txt b/requirements.txt index a103d2a..f947b1c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,6 +8,4 @@ eventsourcing==0.9.4 filelock pytz blist -importlib -matplotlib -numexpr +#numexpr diff --git a/scripts/prepare-distribution.py b/scripts/prepare-distribution.py index 0fa1668..1010a78 100755 --- a/scripts/prepare-distribution.py +++ b/scripts/prepare-distribution.py @@ -18,39 +18,40 @@ def build_and_test(cwd): tmpcwd27 = os.path.join(cwd, 'tmpve2.7') tmpcwd34 = os.path.join(cwd, 'tmpve3.4') - for (tmpcwd, python_executable) in [(tmpcwd27, 'python2.7'), (tmpcwd34, 'python3.4')]: - - # # Rebuild virtualenvs. - # rebuild_virtualenv(cwd, tmpcwd, python_executable) - # - # # Upgrade pip. - # subprocess.check_call(['bin/pip', 'install', '--upgrade', 'pip'], cwd=tmpcwd) - # - # # Install from project folder. - # # - assumes we are starting in the scripts folder - # subprocess.check_call(['bin/pip', 'install', '..'], cwd=tmpcwd) - # - # # Check installed tests all pass. - # test_installation(tmpcwd) + for (tmpcwd, python_executable) in [(tmpcwd34, 'python3.4'), (tmpcwd27, 'python2.7')]: # Rebuild virtualenvs. rebuild_virtualenv(cwd, tmpcwd, python_executable) - # Build and upload to Test PyPI. - subprocess.check_call([sys.executable, 'setup.py', 'sdist', 'upload', '-r', 'pypitest'], cwd=cwd) - - # Install from Test PyPI. + # Upgrade pip. subprocess.check_call(['bin/pip', 'install', '--upgrade', 'pip'], cwd=tmpcwd) + subprocess.check_call(['bin/pip', 'install', '--upgrade', 'setuptools'], cwd=tmpcwd) - subprocess.check_call(['bin/pip', 'install', 'quantdsl=='+get_version(), - '--index-url', 'https://testpypi.python.org/simple', - '--extra-index-url', 'https://pypi.python.org/simple' - ], - cwd=tmpcwd) + # Install from project folder. + # - assumes we are starting in the scripts folder + subprocess.check_call(['bin/pip', 'install', '..'], cwd=tmpcwd) # Check installed tests all pass. test_installation(tmpcwd) + # + # # Rebuild virtualenvs. + # rebuild_virtualenv(cwd, tmpcwd, python_executable) + # + # # Build and upload to Test PyPI. + # subprocess.check_call([sys.executable, 'setup.py', 'sdist', 'upload', '-r', 'pypitest'], cwd=cwd) + # + # # Install from Test PyPI. + # subprocess.check_call(['bin/pip', 'install', '--upgrade', 'pip'], cwd=tmpcwd) + # + # subprocess.check_call(['bin/pip', 'install', 'quantdsl=='+get_version(), + # '--index-url', 'https://testpypi.python.org/simple', + # '--extra-index-url', 'https://pypi.python.org/simple' + # ], + # cwd=tmpcwd) + # # Check installed tests all pass. + # test_installation(tmpcwd) + # remove_virtualenv(cwd, tmpcwd) diff --git a/setup.py b/setup.py index 8f574ec..6f7ced9 100644 --- a/setup.py +++ b/setup.py @@ -31,9 +31,7 @@ 'eventsourcing==0.9.4', 'pytz', 'blist', - 'importlib', - 'matplotlib', - 'numexpr' + # 'numexpr' ], scripts=[],