Commit 5bf168ac authored by serge-sans-paille's avatar serge-sans-paille Committed by Stefan Behnel

Make pythran version checks more resilient

Current checks breaks when setting 0.10.0 as a Pythran version :-/
parent 34de6ba8
...@@ -34,10 +34,8 @@ except ImportError: ...@@ -34,10 +34,8 @@ except ImportError:
try: try:
import pythran import pythran
import pythran.config
pythran_version = pythran.__version__
except: except:
pythran_version = None pythran = None
from .. import Utils from .. import Utils
from ..Utils import (cached_function, cached_method, path_exists, from ..Utils import (cached_function, cached_method, path_exists,
...@@ -125,13 +123,13 @@ def file_hash(filename): ...@@ -125,13 +123,13 @@ def file_hash(filename):
def update_pythran_extension(ext): def update_pythran_extension(ext):
if not pythran_version: if pythran is None:
raise RuntimeError("You first need to install Pythran to use the np_pythran directive.") raise RuntimeError("You first need to install Pythran to use the np_pythran directive.")
pythran_ext = ( try:
pythran.config.make_extension(python=True) pythran_ext = pythran.config.make_extension(python=True)
if pythran_version >= '0.9' or pythran_version >= '0.8.7' except TypeError: # older pythran version only
else pythran.config.make_extension() pythran_ext = pythran.config.make_extension()
)
ext.include_dirs.extend(pythran_ext['include_dirs']) ext.include_dirs.extend(pythran_ext['include_dirs'])
ext.extra_compile_args.extend(pythran_ext['extra_compile_args']) ext.extra_compile_args.extend(pythran_ext['extra_compile_args'])
ext.extra_link_args.extend(pythran_ext['extra_link_args']) ext.extra_link_args.extend(pythran_ext['extra_link_args'])
...@@ -947,8 +945,9 @@ def cythonize(module_list, exclude=None, nthreads=0, aliases=None, quiet=False, ...@@ -947,8 +945,9 @@ def cythonize(module_list, exclude=None, nthreads=0, aliases=None, quiet=False,
if 'common_utility_include_dir' in options: if 'common_utility_include_dir' in options:
safe_makedirs(options['common_utility_include_dir']) safe_makedirs(options['common_utility_include_dir'])
pythran_options = None if pythran is None:
if pythran_version: pythran_options = None
else:
pythran_options = CompilationOptions(**options) pythran_options = CompilationOptions(**options)
pythran_options.cplus = True pythran_options.cplus = True
pythran_options.np_pythran = True pythran_options.np_pythran = True
......
...@@ -8,11 +8,10 @@ import cython ...@@ -8,11 +8,10 @@ import cython
try: try:
import pythran import pythran
pythran_version = pythran.__version__ pythran_is_pre_0_9 = tuple(map(int, pythran.__version__.split('.')[0:2])) < (0, 9)
pythran_is_0_8_7 = pythran_version >= '0.9' or pythran_version >= '0.8.7'
except ImportError: except ImportError:
pythran_version = None pythran = None
pythran_is_0_8_7 = False pythran_is_pre_0_9 = True
# Pythran/Numpy specific operations # Pythran/Numpy specific operations
...@@ -41,10 +40,10 @@ def pythran_type(Ty, ptype="ndarray"): ...@@ -41,10 +40,10 @@ def pythran_type(Ty, ptype="ndarray"):
ctype = dtype.typedef_cname ctype = dtype.typedef_cname
else: else:
raise ValueError("unsupported type %s!" % dtype) raise ValueError("unsupported type %s!" % dtype)
if pythran_is_0_8_7: if pythran_is_pre_0_9:
return "pythonic::types::%s<%s,pythonic::types::pshape<%s>>" % (ptype,ctype, ",".join(("Py_ssize_t",)*ndim))
else:
return "pythonic::types::%s<%s,%d>" % (ptype,ctype, ndim) return "pythonic::types::%s<%s,%d>" % (ptype,ctype, ndim)
else:
return "pythonic::types::%s<%s,pythonic::types::pshape<%s>>" % (ptype,ctype, ",".join(("Py_ssize_t",)*ndim))
if Ty.is_pythran_expr: if Ty.is_pythran_expr:
return Ty.pythran_type return Ty.pythran_type
#if Ty.is_none: #if Ty.is_none:
...@@ -129,7 +128,10 @@ def np_func_to_list(func): ...@@ -129,7 +128,10 @@ def np_func_to_list(func):
return [] return []
return np_func_to_list(func.obj) + [func.attribute] return np_func_to_list(func.obj) + [func.attribute]
if pythran_version: if pythran is None:
def pythran_is_numpy_func_supported(name):
return False
else:
def pythran_is_numpy_func_supported(func): def pythran_is_numpy_func_supported(func):
CurF = pythran.tables.MODULES['numpy'] CurF = pythran.tables.MODULES['numpy']
FL = np_func_to_list(func) FL = np_func_to_list(func)
...@@ -138,9 +140,6 @@ if pythran_version: ...@@ -138,9 +140,6 @@ if pythran_version:
if CurF is None: if CurF is None:
return False return False
return True return True
else:
def pythran_is_numpy_func_supported(name):
return False
def pythran_functor(func): def pythran_functor(func):
func = np_func_to_list(func) func = np_func_to_list(func)
......
...@@ -758,12 +758,10 @@ class TestBuilder(object): ...@@ -758,12 +758,10 @@ class TestBuilder(object):
pythran_dir = self.pythran_dir pythran_dir = self.pythran_dir
if 'pythran' in tags['tag'] and not pythran_dir and 'cpp' in languages: if 'pythran' in tags['tag'] and not pythran_dir and 'cpp' in languages:
import pythran.config import pythran.config
from pythran import __version__ as pythran_version try:
pythran_ext = ( pythran_ext = pythran.config.make_extension(python=True)
pythran.config.make_extension(python=True) except TypeError: # old pythran version syntax
if pythran_version >= '0.9' or pythran_version >= '0.8.7' pythran_ext = pythran.config.make_extension()
else pythran.config.make_extension()
)
pythran_dir = pythran_ext['include_dirs'][0] pythran_dir = pythran_ext['include_dirs'][0]
preparse_list = tags.get('preparse', ['id']) preparse_list = tags.get('preparse', ['id'])
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment