From 4d522fa55132807a7edaa5c090c1e8c7f4019ec8 Mon Sep 17 00:00:00 2001 From: Anderson Mesquita Date: Thu, 18 Dec 2014 08:45:51 -0500 Subject: [PATCH] Fix doc generation for contrib resources Since we shouldn't require contrib resources to be installed in order to generate documentation, this adds an exception to the plugin loader so that it doesn't try to load the setup.py files that can be found inside each plugin directory inside contrib/ Closes-Bug: 1403897 Change-Id: Id6ece4379599925dd17d22cef401c8d667a0ac51 --- heat/common/plugin_loader.py | 6 +++--- heat/tests/test_plugin_loader.py | 11 +++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/heat/common/plugin_loader.py b/heat/common/plugin_loader.py index fedde3037..616fcd3f3 100644 --- a/heat/common/plugin_loader.py +++ b/heat/common/plugin_loader.py @@ -88,9 +88,9 @@ def load_modules(package, ignore_error=False): for importer, module_name, is_package in pkgutil.walk_packages(path, pkg_prefix): - # NOTE(chmouel): Skips tests package or this will try to load - # them when loading plugins. - if '.tests.' in module_name: + # Skips tests or setup packages so as not to load tests in general + # or setup.py during doc generation. + if '.tests.' in module_name or module_name.endswith('.setup'): continue try: diff --git a/heat/tests/test_plugin_loader.py b/heat/tests/test_plugin_loader.py index 74383e651..4a874d336 100644 --- a/heat/tests/test_plugin_loader.py +++ b/heat/tests/test_plugin_loader.py @@ -76,3 +76,14 @@ class PluginLoaderTest(testtools.TestCase): loaded = plugin_loader.load_modules( heat.engine, ignore_error=True) self.assertEqual(1, len(list(loaded))) + + @mock.patch.object(plugin_loader, "_import_module", mock.MagicMock()) + @mock.patch('pkgutil.walk_packages') + def test_load_modules_skip_setup(self, mp): + importer = pkgutil.ImpImporter(heat.engine.__path__[0]) + + mp.return_value = ((importer, "hola.foo", None), + (importer, "hola.setup", None)) + loaded = plugin_loader.load_modules( + heat.engine, ignore_error=True) + self.assertEqual(1, len(list(loaded)))