Skip to content

Commit

Permalink
Trying to fix deployment bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
johnbywater committed Oct 4, 2017
1 parent d4a9f75 commit 9f5d3ea
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 42 deletions.
4 changes: 3 additions & 1 deletion quantdsl/application/with_multithreading.py
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down
5 changes: 3 additions & 2 deletions quantdsl/semantics.py
Expand Up @@ -7,7 +7,7 @@
from abc import ABCMeta, abstractmethod
from collections import namedtuple

import numexpr
# import numexpr
import scipy
import scipy.linalg
import six
Expand Down Expand Up @@ -375,7 +375,8 @@ def op(self, value):
return not value


NUMEXPR_OPS = ['+', '-', '*', '/', '**', '%']
# NUMEXPR_OPS = ['+', '-', '*', '/', '**', '%']
NUMEXPR_OPS = []


class BinOp(DslExpression):
Expand Down
37 changes: 27 additions & 10 deletions 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):

Expand Down Expand Up @@ -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):
"""
Expand Down
4 changes: 1 addition & 3 deletions requirements.txt
Expand Up @@ -8,6 +8,4 @@ eventsourcing==0.9.4
filelock
pytz
blist
importlib
matplotlib
numexpr
#numexpr
47 changes: 24 additions & 23 deletions scripts/prepare-distribution.py
Expand Up @@ -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)


Expand Down
4 changes: 1 addition & 3 deletions setup.py
Expand Up @@ -31,9 +31,7 @@
'eventsourcing==0.9.4',
'pytz',
'blist',
'importlib',
'matplotlib',
'numexpr'
# 'numexpr'
],

scripts=[],
Expand Down

0 comments on commit 9f5d3ea

Please sign in to comment.