diff --git a/setup.py b/setup.py index e735026a..6c55c6d6 100644 --- a/setup.py +++ b/setup.py @@ -24,6 +24,19 @@ import sys import setuptools from distutils.command.build_py import build_py +if sys.version_info[0] < 3: + import __builtin__ as builtins +else: + import builtins + +# This is a bit (!) hackish: we are setting a global variable so that the main +# skimage __init__ can detect if it is being loaded by the setup routine, to +# avoid attempting to load components that aren't built yet: +# the numpy distutils extensions that are used by scikit-image to recursively +# build the compiled extensions in sub-packages is based on the Python import +# machinery. +builtins.__SKIMAGE_SETUP__ = True + with open('skimage/__init__.py') as fid: for line in fid: diff --git a/skimage/__init__.py b/skimage/__init__.py index e38bf057..6099af3b 100644 --- a/skimage/__init__.py +++ b/skimage/__init__.py @@ -56,6 +56,7 @@ img_as_ubyte """ +import sys import os.path as osp import imp import functools @@ -111,4 +112,19 @@ doctest_verbose.__doc__ = doctest.__doc__ del warnings, functools, osp, imp -from . import __check_build +try: + # This variable is injected in the __builtins__ by the build + # process. It used to enable importing subpackages of skimage when + # the binaries are not built + __SKIMAGE_SETUP__ +except NameError: + __SKIMAGE_SETUP__ = False + +if __SKIMAGE_SETUP__: + sys.stderr.write('Partial import of skimage during the build process.\n') + # We are not importing the rest of the scikit during the build + # process, as it may not be compiled yet +else: + from . import __check_build + from .util.dtype import * + __check_build # avoid flakes unused varaible error