From edc16c6b7543ac9d8703bdb409c17e72ebad0a37 Mon Sep 17 00:00:00 2001 From: michaelpacer Date: Sun, 12 Jul 2015 15:50:01 -0500 Subject: [PATCH 1/9] Added build location checker, does not fully work yet. Complicated error. --- skimage/__check_build/README | 34 +++++++++++++++++++ skimage/__check_build/__init__.py | 47 ++++++++++++++++++++++++++ skimage/__check_build/_check_build.pyx | 2 ++ skimage/__check_build/setup.py | 19 +++++++++++ skimage/__init__.py | 2 ++ skimage/setup.py | 1 + 6 files changed, 105 insertions(+) create mode 100644 skimage/__check_build/README create mode 100644 skimage/__check_build/__init__.py create mode 100644 skimage/__check_build/_check_build.pyx create mode 100644 skimage/__check_build/setup.py diff --git a/skimage/__check_build/README b/skimage/__check_build/README new file mode 100644 index 00000000..2c7ba992 --- /dev/null +++ b/skimage/__check_build/README @@ -0,0 +1,34 @@ +Files in this directory are derived from the scikit-learn project with the +following license: + +New BSD License + +Copyright (c) 2007–2014 The scikit-learn developers. +All rights reserved. + + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + a. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + b. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + c. Neither the name of the Scikit-learn Developers nor the names of + its contributors may be used to endorse or promote products + derived from this software without specific prior written + permission. + + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR + ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH + DAMAGE. diff --git a/skimage/__check_build/__init__.py b/skimage/__check_build/__init__.py new file mode 100644 index 00000000..81cd7bd6 --- /dev/null +++ b/skimage/__check_build/__init__.py @@ -0,0 +1,47 @@ +""" Module to give helpful messages to the user that did not +compile scikit-image properly. +This checking code was stolen from scikit-learn & pyart. +""" +import os + +INPLACE_MSG = """ +It appears that you are importing a local scikit-image source tree. For +this, you need to have an inplace install. Maybe you are in the source +directory and you need to try from another location.""" + +STANDARD_MSG = """ +If you have used an installer, please check that it is suited for your +Python version, your operating system and your platform.""" + + +def raise_build_error(e): + # Raise a comprehensible error and list the contents of the + # directory to help debugging on the mailing list. + local_dir = os.path.split(__file__)[0] + msg = STANDARD_MSG + if local_dir == "skimage/__check_build": + # Picking up the local install: this will work only if the + # install is an 'inplace build' + msg = INPLACE_MSG + dir_content = list() + for i, filename in enumerate(os.listdir(local_dir)): + if ((i + 1) % 3): + dir_content.append(filename.ljust(26)) + else: + dir_content.append(filename + '\n') + raise ImportError("""%s +___________________________________________________________________________ +Contents of %s: +%s +___________________________________________________________________________ +It seems that scikit-image has not been built correctly. + +If you have installed scikit-image from source, please do not forget +to build the package before using it: run `python setup.py install` or +`make` in the source directory. +%s""" % (e, local_dir, ''.join(dir_content).strip(), msg)) + +try: + from ._check_build import check_build +except ImportError as e: + raise_build_error(e) diff --git a/skimage/__check_build/_check_build.pyx b/skimage/__check_build/_check_build.pyx new file mode 100644 index 00000000..0409e73f --- /dev/null +++ b/skimage/__check_build/_check_build.pyx @@ -0,0 +1,2 @@ +def check_build(): + return diff --git a/skimage/__check_build/setup.py b/skimage/__check_build/setup.py new file mode 100644 index 00000000..1567114e --- /dev/null +++ b/skimage/__check_build/setup.py @@ -0,0 +1,19 @@ +# Author: Virgile Fritsch +# License: BSD 3 clause + +import numpy +from skimage._build import cython + +def configuration(parent_package='', top_path=None): + from numpy.distutils.misc_util import Configuration + + config = Configuration('__check_build', parent_package, top_path) + + cython(['_check_build.pyx'], working_path=base_path) + config.add_extension('_check_build', + sources=['_check_build.c']) + return config + +if __name__ == '__main__': + from numpy.distutils.core import setup + setup(**configuration(top_path='').todict()) diff --git a/skimage/__init__.py b/skimage/__init__.py index e9216950..e38bf057 100644 --- a/skimage/__init__.py +++ b/skimage/__init__.py @@ -110,3 +110,5 @@ doctest_verbose = functools.partial(test, doctest=True, verbose=True) doctest_verbose.__doc__ = doctest.__doc__ del warnings, functools, osp, imp + +from . import __check_build diff --git a/skimage/setup.py b/skimage/setup.py index b33f5e81..f28afb21 100644 --- a/skimage/setup.py +++ b/skimage/setup.py @@ -6,6 +6,7 @@ def configuration(parent_package='', top_path=None): config = Configuration('skimage', parent_package, top_path) + config.add_subpackage('__check_build') config.add_subpackage('_shared') config.add_subpackage('color') config.add_subpackage('data') From 64c4252eab91b0b48eedd698d0e23b9ba642bc41 Mon Sep 17 00:00:00 2001 From: Jonathan Helmus Date: Tue, 21 Jul 2015 13:06:33 -0500 Subject: [PATCH 2/9] BLD: __SKIMAGE_SETUP__ global variable for detecting build The __SKIMAGE_SETUP__ global variable is set to True if skimage is being build from the main setup.py file, False if not. This behavior is modeled after a similar setup in scikit-learn --- setup.py | 13 +++++++++++++ skimage/__init__.py | 18 +++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) 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 From 93366d1b572aecc942391502d749419c847552d2 Mon Sep 17 00:00:00 2001 From: Jonathan Helmus Date: Tue, 21 Jul 2015 13:08:47 -0500 Subject: [PATCH 3/9] MAINT: Fixed __check_build setup.py file --- skimage/__check_build/setup.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/skimage/__check_build/setup.py b/skimage/__check_build/setup.py index 1567114e..991cf916 100644 --- a/skimage/__check_build/setup.py +++ b/skimage/__check_build/setup.py @@ -1,9 +1,12 @@ -# Author: Virgile Fritsch -# License: BSD 3 clause +#!/usr/bin/env python + +import os -import numpy from skimage._build import cython +base_path = os.path.abspath(os.path.dirname(__file__)) + + def configuration(parent_package='', top_path=None): from numpy.distutils.misc_util import Configuration @@ -16,4 +19,11 @@ def configuration(parent_package='', top_path=None): if __name__ == '__main__': from numpy.distutils.core import setup - setup(**configuration(top_path='').todict()) + setup(maintainer='scikit-image Developers', + author='scikit-image Developers', + maintainer_email='scikit-image@googlegroups.com', + description='Build Check', + url='https://github.com/scikit-image/scikit-image', + license='SciPy License (BSD Style)', + **(configuration(top_path='').todict()) + ) From b92c5653cd5bd553a32077c65497e73c54bc0822 Mon Sep 17 00:00:00 2001 From: Jonathan Helmus Date: Tue, 21 Jul 2015 13:56:27 -0500 Subject: [PATCH 4/9] BLD: Updated bento.info with _check_build extension --- bento.info | 3 +++ 1 file changed, 3 insertions(+) diff --git a/bento.info b/bento.info index 659247d1..81910d34 100644 --- a/bento.info +++ b/bento.info @@ -38,6 +38,9 @@ Library: skimage.io._plugins, skimage.measure, skimage.morphology, skimage.scripts, skimage.restoration, skimage.segmentation, skimage.transform, skimage.util + Extension: skimage.__check_build._check_build + Sources: + skimage/__check_build/_check_build.pyx Extension: skimage.io._plugins._colormixer Sources: skimage/io/_plugins/_colormixer.pyx From 9727711405d9c450b23e0254d95c3e30efdf8600 Mon Sep 17 00:00:00 2001 From: Jonathan Helmus Date: Tue, 28 Jul 2015 13:42:02 -0500 Subject: [PATCH 5/9] Removed __check_build directory --- bento.info | 3 -- skimage/__check_build/README | 34 ------------------- skimage/__check_build/__init__.py | 47 -------------------------- skimage/__check_build/_check_build.pyx | 2 -- skimage/__check_build/setup.py | 29 ---------------- skimage/setup.py | 1 - 6 files changed, 116 deletions(-) delete mode 100644 skimage/__check_build/README delete mode 100644 skimage/__check_build/__init__.py delete mode 100644 skimage/__check_build/_check_build.pyx delete mode 100644 skimage/__check_build/setup.py diff --git a/bento.info b/bento.info index 81910d34..659247d1 100644 --- a/bento.info +++ b/bento.info @@ -38,9 +38,6 @@ Library: skimage.io._plugins, skimage.measure, skimage.morphology, skimage.scripts, skimage.restoration, skimage.segmentation, skimage.transform, skimage.util - Extension: skimage.__check_build._check_build - Sources: - skimage/__check_build/_check_build.pyx Extension: skimage.io._plugins._colormixer Sources: skimage/io/_plugins/_colormixer.pyx diff --git a/skimage/__check_build/README b/skimage/__check_build/README deleted file mode 100644 index 2c7ba992..00000000 --- a/skimage/__check_build/README +++ /dev/null @@ -1,34 +0,0 @@ -Files in this directory are derived from the scikit-learn project with the -following license: - -New BSD License - -Copyright (c) 2007–2014 The scikit-learn developers. -All rights reserved. - - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - - a. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - b. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - c. Neither the name of the Scikit-learn Developers nor the names of - its contributors may be used to endorse or promote products - derived from this software without specific prior written - permission. - - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR - ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH - DAMAGE. diff --git a/skimage/__check_build/__init__.py b/skimage/__check_build/__init__.py deleted file mode 100644 index 81cd7bd6..00000000 --- a/skimage/__check_build/__init__.py +++ /dev/null @@ -1,47 +0,0 @@ -""" Module to give helpful messages to the user that did not -compile scikit-image properly. -This checking code was stolen from scikit-learn & pyart. -""" -import os - -INPLACE_MSG = """ -It appears that you are importing a local scikit-image source tree. For -this, you need to have an inplace install. Maybe you are in the source -directory and you need to try from another location.""" - -STANDARD_MSG = """ -If you have used an installer, please check that it is suited for your -Python version, your operating system and your platform.""" - - -def raise_build_error(e): - # Raise a comprehensible error and list the contents of the - # directory to help debugging on the mailing list. - local_dir = os.path.split(__file__)[0] - msg = STANDARD_MSG - if local_dir == "skimage/__check_build": - # Picking up the local install: this will work only if the - # install is an 'inplace build' - msg = INPLACE_MSG - dir_content = list() - for i, filename in enumerate(os.listdir(local_dir)): - if ((i + 1) % 3): - dir_content.append(filename.ljust(26)) - else: - dir_content.append(filename + '\n') - raise ImportError("""%s -___________________________________________________________________________ -Contents of %s: -%s -___________________________________________________________________________ -It seems that scikit-image has not been built correctly. - -If you have installed scikit-image from source, please do not forget -to build the package before using it: run `python setup.py install` or -`make` in the source directory. -%s""" % (e, local_dir, ''.join(dir_content).strip(), msg)) - -try: - from ._check_build import check_build -except ImportError as e: - raise_build_error(e) diff --git a/skimage/__check_build/_check_build.pyx b/skimage/__check_build/_check_build.pyx deleted file mode 100644 index 0409e73f..00000000 --- a/skimage/__check_build/_check_build.pyx +++ /dev/null @@ -1,2 +0,0 @@ -def check_build(): - return diff --git a/skimage/__check_build/setup.py b/skimage/__check_build/setup.py deleted file mode 100644 index 991cf916..00000000 --- a/skimage/__check_build/setup.py +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env python - -import os - -from skimage._build import cython - -base_path = os.path.abspath(os.path.dirname(__file__)) - - -def configuration(parent_package='', top_path=None): - from numpy.distutils.misc_util import Configuration - - config = Configuration('__check_build', parent_package, top_path) - - cython(['_check_build.pyx'], working_path=base_path) - config.add_extension('_check_build', - sources=['_check_build.c']) - return config - -if __name__ == '__main__': - from numpy.distutils.core import setup - setup(maintainer='scikit-image Developers', - author='scikit-image Developers', - maintainer_email='scikit-image@googlegroups.com', - description='Build Check', - url='https://github.com/scikit-image/scikit-image', - license='SciPy License (BSD Style)', - **(configuration(top_path='').todict()) - ) diff --git a/skimage/setup.py b/skimage/setup.py index f28afb21..b33f5e81 100644 --- a/skimage/setup.py +++ b/skimage/setup.py @@ -6,7 +6,6 @@ def configuration(parent_package='', top_path=None): config = Configuration('skimage', parent_package, top_path) - config.add_subpackage('__check_build') config.add_subpackage('_shared') config.add_subpackage('color') config.add_subpackage('data') From d2519d610fbaac32665c9ff2df62b56ca698c1b5 Mon Sep 17 00:00:00 2001 From: Jonathan Helmus Date: Tue, 28 Jul 2015 14:00:32 -0500 Subject: [PATCH 6/9] ENH: Build check in skimage/__init__.py module --- skimage/__init__.py | 40 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/skimage/__init__.py b/skimage/__init__.py index 6099af3b..d667dc73 100644 --- a/skimage/__init__.py +++ b/skimage/__init__.py @@ -56,7 +56,6 @@ img_as_ubyte """ -import sys import os.path as osp import imp import functools @@ -110,6 +109,37 @@ doctest.__doc__ = doctest.__doc__ doctest_verbose = functools.partial(test, doctest=True, verbose=True) doctest_verbose.__doc__ = doctest.__doc__ + +# Logic for checking for improper install and importing while in the source +# tree when package has not been installed inplace. +# Code adapted from scikit-learn's __check_build module. +_INPLACE_MSG = """ +It appears that you are importing a local scikit-image source tree. For +this, you need to have an inplace install. Maybe you are in the source +directory and you need to try from another location.""" + +_STANDARD_MSG = """ +If you have used an installer, please check that it is suited for your +Python version, your operating system and your platform.""" + + +def _raise_build_error(e): + import os + # Raise a comprehensible error + local_dir = os.path.split(__file__)[0] + msg = _STANDARD_MSG + if local_dir == "skimage": + # Picking up the local install: this will work only if the + # install is an 'inplace build' + msg = _INPLACE_MSG + raise ImportError("""%s +It seems that scikit-image has not been built correctly. + +If you have installed scikit-image from source, please do not forget +to build the package before using it: run `python setup.py install` or +`make` in the source directory. +%s""" % (e, msg)) + del warnings, functools, osp, imp try: @@ -121,10 +151,14 @@ except NameError: __SKIMAGE_SETUP__ = False if __SKIMAGE_SETUP__: + import sys 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 + try: + from ._shared import geometry + del geometry + except ImportError as e: + _raise_build_error(e) from .util.dtype import * - __check_build # avoid flakes unused varaible error From f10ae88139945bf6decd4e502280793626d1477e Mon Sep 17 00:00:00 2001 From: Jonathan Helmus Date: Tue, 28 Jul 2015 14:06:03 -0500 Subject: [PATCH 7/9] MAINT: remove unchecked import from util.dtype --- skimage/__init__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/skimage/__init__.py b/skimage/__init__.py index d667dc73..0c29d338 100644 --- a/skimage/__init__.py +++ b/skimage/__init__.py @@ -60,7 +60,6 @@ import os.path as osp import imp import functools import warnings -from .util.dtype import * pkg_dir = osp.abspath(osp.dirname(__file__)) data_dir = osp.join(pkg_dir, 'data') From 00a841f1c2776dadee5e5b8627c2e296c646b162 Mon Sep 17 00:00:00 2001 From: Jonathan Helmus Date: Tue, 28 Jul 2015 14:11:51 -0500 Subject: [PATCH 8/9] MAINT: Refactored imports --- skimage/__init__.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/skimage/__init__.py b/skimage/__init__.py index 0c29d338..0552c614 100644 --- a/skimage/__init__.py +++ b/skimage/__init__.py @@ -60,6 +60,7 @@ import os.path as osp import imp import functools import warnings +import sys pkg_dir = osp.abspath(osp.dirname(__file__)) data_dir = osp.join(pkg_dir, 'data') @@ -123,9 +124,8 @@ Python version, your operating system and your platform.""" def _raise_build_error(e): - import os # Raise a comprehensible error - local_dir = os.path.split(__file__)[0] + local_dir = osp.split(__file__)[0] msg = _STANDARD_MSG if local_dir == "skimage": # Picking up the local install: this will work only if the @@ -139,8 +139,6 @@ to build the package before using it: run `python setup.py install` or `make` in the source directory. %s""" % (e, msg)) -del warnings, functools, osp, imp - try: # This variable is injected in the __builtins__ by the build # process. It used to enable importing subpackages of skimage when @@ -150,7 +148,6 @@ except NameError: __SKIMAGE_SETUP__ = False if __SKIMAGE_SETUP__: - import sys 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 @@ -161,3 +158,5 @@ else: except ImportError as e: _raise_build_error(e) from .util.dtype import * + +del warnings, functools, osp, imp, sys From 70d1afe153c363838560b8061e9a96cb3c488227 Mon Sep 17 00:00:00 2001 From: Jonathan Helmus Date: Thu, 30 Jul 2015 14:53:49 -0500 Subject: [PATCH 9/9] DOC: Simplified the message when a broken skimage build detected --- skimage/__init__.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/skimage/__init__.py b/skimage/__init__.py index 0552c614..2b152156 100644 --- a/skimage/__init__.py +++ b/skimage/__init__.py @@ -119,8 +119,9 @@ this, you need to have an inplace install. Maybe you are in the source directory and you need to try from another location.""" _STANDARD_MSG = """ -If you have used an installer, please check that it is suited for your -Python version, your operating system and your platform.""" +Your install of scikit-image appears to be broken. +Try re-installing the package following the instructions at: +http://scikit-image.org/docs/stable/install.html """ def _raise_build_error(e): @@ -133,10 +134,6 @@ def _raise_build_error(e): msg = _INPLACE_MSG raise ImportError("""%s It seems that scikit-image has not been built correctly. - -If you have installed scikit-image from source, please do not forget -to build the package before using it: run `python setup.py install` or -`make` in the source directory. %s""" % (e, msg)) try: