commit/galaxy-central: 5 new changesets
5 new commits in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/2f655d7df4de/ Changeset: 2f655d7df4de User: jmchilton Date: 2013-08-13 21:38:00 Summary: Add some overly simple baseline unit tests for visualizations plugin behavior. Affected #: 1 file diff -r 009088d5e76fb00794da78dc0ee3cdaa8524b7d8 -r 2f655d7df4de9731adf45ec1487a9e85c5671aaf test/unit/test_plugins.py --- /dev/null +++ b/test/unit/test_plugins.py @@ -0,0 +1,14 @@ +from os.path import join, dirname, basename +from galaxy.visualization.registry import VisualizationsRegistry + + +def test_visualization_loading(): + galaxy_root = join(dirname(__file__), '..', '..') + visualizations = join(galaxy_root, 'config', 'plugins', 'visualizations') + registry = VisualizationsRegistry(visualizations, 'foo') + assert "VisualizationsRegistry" in str(registry) + assert visualizations in str(registry) + assert registry.name == "visualizations" + assert 'scatterplot' in \ + [basename(path) for path in registry.get_plugin_directories()] + assert registry._get_template_paths() == [visualizations] https://bitbucket.org/galaxy/galaxy-central/commits/83139f9fed93/ Changeset: 83139f9fed93 User: jmchilton Date: 2013-08-13 21:38:00 Summary: Planning on refactoring out self.plugin_directory, is this simplified logic sufficient or was it the way it was for a good reason? Affected #: 1 file diff -r 2f655d7df4de9731adf45ec1487a9e85c5671aaf -r 83139f9fed93f4a3759ed1b5c2019c24fb8037c5 lib/galaxy/web/base/pluginframework.py --- a/lib/galaxy/web/base/pluginframework.py +++ b/lib/galaxy/web/base/pluginframework.py @@ -220,8 +220,7 @@ this version of `fill_template` allows `bler.mako` to call `import my_script`. """ try: - plugin_base_path = os.path.split( os.path.dirname( template_filename ) )[0] - plugin_path = os.path.join( self.plugin_directory, plugin_base_path ) + plugin_path = os.path.dirname( os.path.dirname( template_filename ) ) sys.path.append( plugin_path ) filled_template = self.fill_template( trans, template_filename, **kwargs ) https://bitbucket.org/galaxy/galaxy-central/commits/82b20714be81/ Changeset: 82b20714be81 User: jmchilton Date: 2013-08-13 21:38:00 Summary: Refactor plugin framework to allow multiple plugin directories (like tools framework allows multiple tool roots). Idea here is to allow some plugins to be managed by Galaxy team inside root and some plugins to be managed outside of Galaxy root by deployers, etc.... This will help keep merges unnecessary or as minimal as possible and should ease efforts like Debian packaging of Galaxy. The need to actually modify the Galaxy code base is an unfortunate aspect of the way dynamic job destinations and dynamic toolbox filters have been implemented. Bringing these under a generic plugin framework and allowing them to be tweaked outside of the Galaxy code base would be wins. Affected #: 2 files diff -r 83139f9fed93f4a3759ed1b5c2019c24fb8037c5 -r 82b20714be81946be9d6fa8ff0848fc6bd02b567 lib/galaxy/visualization/registry.py --- a/lib/galaxy/visualization/registry.py +++ b/lib/galaxy/visualization/registry.py @@ -61,9 +61,6 @@ #: directories under plugin_directory that aren't plugins non_plugin_directories = [] - def __str__( self ): - return 'VisualizationsRegistry(%s)' %( self.plugin_directory ) - def __init__( self, registry_filepath, template_cache_dir ): super( VisualizationsRegistry, self ).__init__( registry_filepath, 'visualizations', template_cache_dir ) @@ -84,7 +81,7 @@ self.listings = VisualizationsConfigParser.parse( self.get_plugin_directories() ) except Exception, exc: - log.exception( 'Error parsing visualizations plugins %s', self.plugin_directory ) + log.exception( 'Error parsing visualizations plugins %s', self.plugin_directories ) raise def get_visualization( self, trans, visualization_name, target_object ): diff -r 83139f9fed93f4a3759ed1b5c2019c24fb8037c5 -r 82b20714be81946be9d6fa8ff0848fc6bd02b567 lib/galaxy/web/base/pluginframework.py --- a/lib/galaxy/web/base/pluginframework.py +++ b/lib/galaxy/web/base/pluginframework.py @@ -14,6 +14,8 @@ pkg_resources.require( 'Mako' ) import mako +from galaxy.util import listify + import logging log = logging.getLogger( __name__ ) @@ -94,24 +96,29 @@ return None def __str__( self ): - return '%s(%s)' %( self.__class__.__name__, self.plugin_directory ) + return '%s(%s)' %( self.__class__.__name__, self.plugin_directories ) - def __init__( self, plugin_directory, name=None, template_cache_dir=None, debug=False ): + def __init__( self, plugin_directories, name=None, template_cache_dir=None, debug=False, assert_exists=True ): """ - :type plugin_directory: string - :param plugin_directory: the base directory where plugin code is kept - :type name: (optional) string (default: None) - :param name: the name of this plugin + :type plugin_directories: string or list + :param plugin_directories: the base directory where plugin code is kept + :type name: (optional) string (default: None) + :param name: the name of this plugin (that will appear in url pathing, etc.) - :type template_cache_dir: (optional) string (default: None) - :param template_cache_dir: the cache directory to store compiled mako + :type template_cache_dir: (optional) string (default: None) + :param template_cache_dir: the cache directory to store compiled mako + :type assert_exists: (optional) bool (default: False) + :param assert_exists: If True, each configured plugin directory must exist. """ - if not os.path.isdir( plugin_directory ): - raise PluginFrameworkException( 'Framework plugin directory not found: %s, %s' - %( self.__class__.__name__, plugin_directory ) ) - self.plugin_directory = plugin_directory + self.plugin_directories = listify( plugin_directories ) + if assert_exists: + for plugin_directory in self.plugin_directories: + if not os.path.isdir( plugin_directory ): + raise PluginFrameworkException( 'Framework plugin directory not found: %s, %s' + % ( self.__class__.__name__, plugin_directory ) ) + #TODO: or pass in from config - self.name = name or os.path.basename( self.plugin_directory ) + self.name = name or os.path.basename( self.plugin_directories[0] ) if self.has_config: self.load_configuration() @@ -127,14 +134,15 @@ themselves and whose ``basename`` is not in ``plugin_directory``. """ # could instead explicitly list on/off in master config file - for plugin_path in glob.glob( os.path.join( self.plugin_directory, '*' ) ): - if not os.path.isdir( plugin_path ): - continue + for plugin_directory in self.plugin_directories: + for plugin_path in glob.glob( os.path.join( plugin_directory, '*' ) ): + if not os.path.isdir( plugin_path ): + continue - if os.path.basename( plugin_path ) in self.non_plugin_directories: - continue + if os.path.basename( plugin_path ) in self.non_plugin_directories: + continue - yield plugin_path + yield plugin_path # ------------------------------------------------------------------------- config def load_configuration( self ): @@ -185,7 +193,7 @@ """ Get the paths that will be searched for templates. """ - return [ self.plugin_directory ] + return self.plugin_directories def _create_mako_template_lookup( self, cache_dir, paths, collection_size=500, output_encoding='utf-8' ): """ https://bitbucket.org/galaxy/galaxy-central/commits/b5f765e074f8/ Changeset: b5f765e074f8 User: jmchilton Date: 2013-08-13 21:38:00 Summary: Add some test cases for plugins configured from multiple directories. Affected #: 1 file diff -r 82b20714be81946be9d6fa8ff0848fc6bd02b567 -r b5f765e074f8ff5ba02dad1d841b92c15b3fb224 test/unit/test_plugins.py --- a/test/unit/test_plugins.py +++ b/test/unit/test_plugins.py @@ -1,14 +1,42 @@ +from os import makedirs from os.path import join, dirname, basename +from tempfile import mkdtemp +from shutil import rmtree + from galaxy.visualization.registry import VisualizationsRegistry def test_visualization_loading(): - galaxy_root = join(dirname(__file__), '..', '..') - visualizations = join(galaxy_root, 'config', 'plugins', 'visualizations') + visualizations = __default_viz_root() registry = VisualizationsRegistry(visualizations, 'foo') assert "VisualizationsRegistry" in str(registry) assert visualizations in str(registry) assert registry.name == "visualizations" + __assert_scatterplot_registered(registry) + assert registry._get_template_paths() == [visualizations] + + +def test_multiple_visualization_roots(): + temp_dir = mkdtemp() + try: + makedirs(join(temp_dir, "coolplugin5")) + visualization_dirs = "%s,%s" % (__default_viz_root(), temp_dir) + registry = VisualizationsRegistry(visualization_dirs, 'foo') + __assert_scatterplot_registered(registry) + assert "coolplugin5" in \ + [basename(path) for path in registry.get_plugin_directories()] + assert registry._get_template_paths() == \ + [__default_viz_root(), temp_dir] + finally: + rmtree(temp_dir) + + +def __assert_scatterplot_registered(registry): assert 'scatterplot' in \ [basename(path) for path in registry.get_plugin_directories()] - assert registry._get_template_paths() == [visualizations] + + +def __default_viz_root(): + galaxy_root = join(dirname(__file__), '..', '..') + visualizations = join(galaxy_root, 'config', 'plugins', 'visualizations') + return visualizations https://bitbucket.org/galaxy/galaxy-central/commits/315ee3999082/ Changeset: 315ee3999082 User: carlfeberhard Date: 2013-08-22 00:24:53 Summary: Merge John Chilton's pull request #204 Affected #: 3 files diff -r ee60297266b09d81a7906c32a7ec03199e50a0c7 -r 315ee3999082396e751e7478f0ac2a4247ba5e70 lib/galaxy/visualization/registry.py --- a/lib/galaxy/visualization/registry.py +++ b/lib/galaxy/visualization/registry.py @@ -61,9 +61,6 @@ #: directories under plugin_directory that aren't plugins non_plugin_directories = [] - def __str__( self ): - return 'VisualizationsRegistry(%s)' %( self.plugin_directory ) - def __init__( self, registry_filepath, template_cache_dir ): super( VisualizationsRegistry, self ).__init__( registry_filepath, 'visualizations', template_cache_dir ) @@ -84,7 +81,7 @@ self.listings = VisualizationsConfigParser.parse( self.get_plugin_directories() ) except Exception, exc: - log.exception( 'Error parsing visualizations plugins %s', self.plugin_directory ) + log.exception( 'Error parsing visualizations plugins %s', self.plugin_directories ) raise def get_visualization( self, trans, visualization_name, target_object ): diff -r ee60297266b09d81a7906c32a7ec03199e50a0c7 -r 315ee3999082396e751e7478f0ac2a4247ba5e70 lib/galaxy/web/base/pluginframework.py --- a/lib/galaxy/web/base/pluginframework.py +++ b/lib/galaxy/web/base/pluginframework.py @@ -14,6 +14,8 @@ pkg_resources.require( 'Mako' ) import mako +from galaxy.util import listify + import logging log = logging.getLogger( __name__ ) @@ -94,24 +96,29 @@ return None def __str__( self ): - return '%s(%s)' %( self.__class__.__name__, self.plugin_directory ) + return '%s(%s)' %( self.__class__.__name__, self.plugin_directories ) - def __init__( self, plugin_directory, name=None, template_cache_dir=None, debug=False ): + def __init__( self, plugin_directories, name=None, template_cache_dir=None, debug=False, assert_exists=True ): """ - :type plugin_directory: string - :param plugin_directory: the base directory where plugin code is kept - :type name: (optional) string (default: None) - :param name: the name of this plugin + :type plugin_directories: string or list + :param plugin_directories: the base directory where plugin code is kept + :type name: (optional) string (default: None) + :param name: the name of this plugin (that will appear in url pathing, etc.) - :type template_cache_dir: (optional) string (default: None) - :param template_cache_dir: the cache directory to store compiled mako + :type template_cache_dir: (optional) string (default: None) + :param template_cache_dir: the cache directory to store compiled mako + :type assert_exists: (optional) bool (default: False) + :param assert_exists: If True, each configured plugin directory must exist. """ - if not os.path.isdir( plugin_directory ): - raise PluginFrameworkException( 'Framework plugin directory not found: %s, %s' - %( self.__class__.__name__, plugin_directory ) ) - self.plugin_directory = plugin_directory + self.plugin_directories = listify( plugin_directories ) + if assert_exists: + for plugin_directory in self.plugin_directories: + if not os.path.isdir( plugin_directory ): + raise PluginFrameworkException( 'Framework plugin directory not found: %s, %s' + % ( self.__class__.__name__, plugin_directory ) ) + #TODO: or pass in from config - self.name = name or os.path.basename( self.plugin_directory ) + self.name = name or os.path.basename( self.plugin_directories[0] ) if self.has_config: self.load_configuration() @@ -127,14 +134,15 @@ themselves and whose ``basename`` is not in ``plugin_directory``. """ # could instead explicitly list on/off in master config file - for plugin_path in glob.glob( os.path.join( self.plugin_directory, '*' ) ): - if not os.path.isdir( plugin_path ): - continue + for plugin_directory in self.plugin_directories: + for plugin_path in glob.glob( os.path.join( plugin_directory, '*' ) ): + if not os.path.isdir( plugin_path ): + continue - if os.path.basename( plugin_path ) in self.non_plugin_directories: - continue + if os.path.basename( plugin_path ) in self.non_plugin_directories: + continue - yield plugin_path + yield plugin_path # ------------------------------------------------------------------------- config def load_configuration( self ): @@ -185,7 +193,7 @@ """ Get the paths that will be searched for templates. """ - return [ self.plugin_directory ] + return self.plugin_directories def _create_mako_template_lookup( self, cache_dir, paths, collection_size=500, output_encoding='utf-8' ): """ @@ -220,8 +228,7 @@ this version of `fill_template` allows `bler.mako` to call `import my_script`. """ try: - plugin_base_path = os.path.split( os.path.dirname( template_filename ) )[0] - plugin_path = os.path.join( self.plugin_directory, plugin_base_path ) + plugin_path = os.path.dirname( os.path.dirname( template_filename ) ) sys.path.append( plugin_path ) filled_template = self.fill_template( trans, template_filename, **kwargs ) diff -r ee60297266b09d81a7906c32a7ec03199e50a0c7 -r 315ee3999082396e751e7478f0ac2a4247ba5e70 test/unit/test_plugins.py --- /dev/null +++ b/test/unit/test_plugins.py @@ -0,0 +1,42 @@ +from os import makedirs +from os.path import join, dirname, basename +from tempfile import mkdtemp +from shutil import rmtree + +from galaxy.visualization.registry import VisualizationsRegistry + + +def test_visualization_loading(): + visualizations = __default_viz_root() + registry = VisualizationsRegistry(visualizations, 'foo') + assert "VisualizationsRegistry" in str(registry) + assert visualizations in str(registry) + assert registry.name == "visualizations" + __assert_scatterplot_registered(registry) + assert registry._get_template_paths() == [visualizations] + + +def test_multiple_visualization_roots(): + temp_dir = mkdtemp() + try: + makedirs(join(temp_dir, "coolplugin5")) + visualization_dirs = "%s,%s" % (__default_viz_root(), temp_dir) + registry = VisualizationsRegistry(visualization_dirs, 'foo') + __assert_scatterplot_registered(registry) + assert "coolplugin5" in \ + [basename(path) for path in registry.get_plugin_directories()] + assert registry._get_template_paths() == \ + [__default_viz_root(), temp_dir] + finally: + rmtree(temp_dir) + + +def __assert_scatterplot_registered(registry): + assert 'scatterplot' in \ + [basename(path) for path in registry.get_plugin_directories()] + + +def __default_viz_root(): + galaxy_root = join(dirname(__file__), '..', '..') + visualizations = join(galaxy_root, 'config', 'plugins', 'visualizations') + return visualizations Repository URL: https://bitbucket.org/galaxy/galaxy-central/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email.
participants (1)
-
commits-noreply@bitbucket.org