From 380e27e60d59144552baad3d602a2136346595fb Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Fri, 14 Dec 2012 16:38:48 -0600 Subject: [PATCH 1/6] Lazily import nose for testing, makes skimge load in 1/3 time. --- skimage/__init__.py | 43 ++++++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/skimage/__init__.py b/skimage/__init__.py index 1ac121b3..e962b558 100644 --- a/skimage/__init__.py +++ b/skimage/__init__.py @@ -52,6 +52,8 @@ img_as_ubyte """ import os.path as _osp +import imp +import functools pkg_dir = _osp.abspath(_osp.dirname(__file__)) data_dir = _osp.join(pkg_dir, 'data') @@ -62,30 +64,25 @@ except ImportError: __version__ = "unbuilt-dev" -def _setup_test(verbose=False): - import functools +try: + imp.find_module('nose') +except ImportError: + def test(verbose=False): + """This would invoke the skimage test suite, but nose couldn't be + imported so the test suite can not run. + """ + raise ImportError("Could not load nose. Unit tests not available.") +else: + def test(verbose=False): + """Invoke the skimage test suite.""" + import nose + args = ['', pkg_dir, '--exe'] + if verbose: + args.extend(['-v', '-s']) + nose.run('skimage', argv=args) - args = ['', pkg_dir, '--exe'] - if verbose: - args.extend(['-v', '-s']) - - try: - import nose as _nose - except ImportError: - def broken_test_func(): - """This would invoke the skimage test suite, but nose couldn't be - imported so the test suite can not run. - """ - raise ImportError("Could not load nose. Unit tests not available.") - return broken_test_func - else: - f = functools.partial(_nose.run, 'skimage', argv=args) - f.__doc__ = 'Invoke the skimage test suite.' - return f - - -test = _setup_test() -test_verbose = _setup_test(verbose=True) +test_verbose = functools.partial(test, verbose=True) +test_verbose.__doc__ = test.__doc__ def get_log(name=None): From cb1527bbe8dffc16abab2eb45bdf8263be977e81 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Sat, 15 Dec 2012 07:24:31 -0600 Subject: [PATCH 2/6] STY: Fixed indent on docstring. --- skimage/__init__.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/skimage/__init__.py b/skimage/__init__.py index e962b558..3a4f60b1 100644 --- a/skimage/__init__.py +++ b/skimage/__init__.py @@ -68,18 +68,18 @@ try: imp.find_module('nose') except ImportError: def test(verbose=False): - """This would invoke the skimage test suite, but nose couldn't be - imported so the test suite can not run. - """ - raise ImportError("Could not load nose. Unit tests not available.") + """This would invoke the skimage test suite, but nose couldn't be + imported so the test suite can not run. + """ + raise ImportError("Could not load nose. Unit tests not available.") else: def test(verbose=False): - """Invoke the skimage test suite.""" - import nose - args = ['', pkg_dir, '--exe'] - if verbose: - args.extend(['-v', '-s']) - nose.run('skimage', argv=args) + """Invoke the skimage test suite.""" + import nose + args = ['', pkg_dir, '--exe'] + if verbose: + args.extend(['-v', '-s']) + nose.run('skimage', argv=args) test_verbose = functools.partial(test, verbose=True) test_verbose.__doc__ = test.__doc__ @@ -122,7 +122,7 @@ def _setup_log(): formatter = logging.Formatter( '%(name)s: %(levelname)s: %(message)s' - ) + ) try: handler = logging.StreamHandler(stream=sys.stdout) @@ -137,4 +137,4 @@ def _setup_log(): _setup_log() -from .util.dtype import * +from .util.dtype import * \ No newline at end of file From b620c0ade667a174d5070680c8c263d1c0757ea4 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Sat, 15 Dec 2012 07:40:04 -0600 Subject: [PATCH 3/6] STY: Added newline at the end of file --- skimage/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/skimage/__init__.py b/skimage/__init__.py index 3a4f60b1..1cd17744 100644 --- a/skimage/__init__.py +++ b/skimage/__init__.py @@ -137,4 +137,4 @@ def _setup_log(): _setup_log() -from .util.dtype import * \ No newline at end of file +from .util.dtype import * From 73d9ee9b614dff630c7099fc83ed4e778cf2f90d Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Fri, 14 Dec 2012 16:38:48 -0600 Subject: [PATCH 4/6] Lazily import nose for testing, makes skimge load in 1/3 time. STY: Fixed indent on docstring. STY: Added newline at the end of file STY: Use original indention --- skimage/__init__.py | 43 ++++++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/skimage/__init__.py b/skimage/__init__.py index 1ac121b3..56ab6de0 100644 --- a/skimage/__init__.py +++ b/skimage/__init__.py @@ -52,6 +52,8 @@ img_as_ubyte """ import os.path as _osp +import imp +import functools pkg_dir = _osp.abspath(_osp.dirname(__file__)) data_dir = _osp.join(pkg_dir, 'data') @@ -62,30 +64,25 @@ except ImportError: __version__ = "unbuilt-dev" -def _setup_test(verbose=False): - import functools +try: + imp.find_module('nose') +except ImportError: + def test(verbose=False): + """This would invoke the skimage test suite, but nose couldn't be + imported so the test suite can not run. + """ + raise ImportError("Could not load nose. Unit tests not available.") +else: + def test(verbose=False): + """Invoke the skimage test suite.""" + import nose + args = ['', pkg_dir, '--exe'] + if verbose: + args.extend(['-v', '-s']) + nose.run('skimage', argv=args) - args = ['', pkg_dir, '--exe'] - if verbose: - args.extend(['-v', '-s']) - - try: - import nose as _nose - except ImportError: - def broken_test_func(): - """This would invoke the skimage test suite, but nose couldn't be - imported so the test suite can not run. - """ - raise ImportError("Could not load nose. Unit tests not available.") - return broken_test_func - else: - f = functools.partial(_nose.run, 'skimage', argv=args) - f.__doc__ = 'Invoke the skimage test suite.' - return f - - -test = _setup_test() -test_verbose = _setup_test(verbose=True) +test_verbose = functools.partial(test, verbose=True) +test_verbose.__doc__ = test.__doc__ def get_log(name=None): From 49119524e343fdad3d3a93f2961af6ca6413158e Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Sat, 15 Dec 2012 09:17:39 -0600 Subject: [PATCH 5/6] Fixed indent on nose.run, so it will run when verbose is False --- skimage/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/skimage/__init__.py b/skimage/__init__.py index 1cd17744..b8d97dc4 100644 --- a/skimage/__init__.py +++ b/skimage/__init__.py @@ -79,7 +79,7 @@ else: args = ['', pkg_dir, '--exe'] if verbose: args.extend(['-v', '-s']) - nose.run('skimage', argv=args) + nose.run('skimage', argv=args) test_verbose = functools.partial(test, verbose=True) test_verbose.__doc__ = test.__doc__ From a8dcb32b60a7b4d9ac7c03768c78d226d83a296e Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Sat, 15 Dec 2012 09:19:26 -0600 Subject: [PATCH 6/6] STY: Replaced indent with original formatting, no need to change. --- skimage/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/skimage/__init__.py b/skimage/__init__.py index b8d97dc4..3277919e 100644 --- a/skimage/__init__.py +++ b/skimage/__init__.py @@ -122,7 +122,7 @@ def _setup_log(): formatter = logging.Formatter( '%(name)s: %(levelname)s: %(message)s' - ) + ) try: handler = logging.StreamHandler(stream=sys.stdout)