diff --git a/build_helpers.py b/build_helpers.py index 2b52170..3faadd1 100644 --- a/build_helpers.py +++ b/build_helpers.py @@ -224,8 +224,9 @@ def package_check(pkg_name, version=None, Parameters ---------- - pkg_name : str - name of package as imported into python + pkg_name : str or sequence of str + name of package as imported into python. Alternative names + (e.g. for different versions) may be given in a list. version : {None, str}, optional minimum version of the package that we require. If None, we don't check the version. Default is None @@ -260,14 +261,29 @@ def package_check(pkg_name, version=None, 'version too old': 'You have version %s of package "%s"' ' but we need version >= %s', } msgs.update(messages) - try: - __import__(pkg_name) - except ImportError: + + if isinstance(pkg_name, str): + names = [pkg_name] + + else: + names = pkg_name + + import_ok = False + for pkg_name in names: + try: + __import__(pkg_name) + except ImportError: + pass + else: + import_ok = True + + if not import_ok: if not optional: raise RuntimeError(msgs['missing'] % pkg_name) log.warn(msgs['missing opt'] % pkg_name + msgs['opt suffix']) return + if not version: return try: diff --git a/setup.py b/setup.py index c9e6d92..0b6290c 100644 --- a/setup.py +++ b/setup.py @@ -82,7 +82,12 @@ def configuration(parent_package='',top_path=None): return config def _mayavi_version(pkg_name): - from enthought.mayavi import version + try: + from enthought.mayavi import version + + except: + from mayavi import version + return version.version def _cython_version(pkg_name): @@ -100,7 +105,7 @@ package_check('IPython', INFO.IPYTHON_MIN_VERSION, optional=True, : '%s was not found: ' 'isfepy will use regular Python shell', 'opt suffix' : ''}) -package_check('enthought.mayavi', +package_check(('enthought.mayavi', 'mayavi'), INFO.MAYAVI_MIN_VERSION, optional=True, version_getter=_mayavi_version)