Skip to content

Commit

Permalink
Revert "[#547] Attempt to fix test via simplified plugins"
Browse files Browse the repository at this point in the history
This reverts commit c3cae23.

a commit too far
  • Loading branch information
tobes committed Mar 25, 2013
1 parent c3cae23 commit e9f4df5
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 57 deletions.
97 changes: 41 additions & 56 deletions ckan/plugins/core.py
Expand Up @@ -19,7 +19,7 @@
'PluginImplementations', 'implements',
'PluginNotFoundException', 'Plugin', 'SingletonPlugin',
'load', 'load_all', 'unload', 'unload_all',
'reset', 'get_pugin',
'reset'
]

log = logging.getLogger(__name__)
Expand All @@ -31,7 +31,6 @@
# not need to be explicitly enabled by the user)
SYSTEM_PLUGINS_ENTRY_POINT_GROUP = "ckan.system_plugins"

_plugins = {}

class PluginNotFoundException(Exception):
"""
Expand Down Expand Up @@ -79,37 +78,31 @@ def _get_service(plugin):

return plugin.load()(name=name)

## elif isinstance(plugin, _pca_Plugin):
## return plugin
##
## elif isclass(plugin) and issubclass(plugin, _pca_Plugin):
## return plugin()
elif isinstance(plugin, _pca_Plugin):
return plugin

elif isclass(plugin) and issubclass(plugin, _pca_Plugin):
return plugin()

else:
raise TypeError("Expected a plugin name, class or instance", plugin)


def get_pugin(plugin):
return _plugins[plugin]


def load_all(config):
"""
Load all plugins listed in the 'ckan.plugins' config directive.
"""
## plugins = chain(
## find_system_plugins(),
## find_user_plugins(config)
## )

plugins = chain(
find_system_plugins(),
find_user_plugins(config)
)

# PCA default behaviour is to activate SingletonPlugins at import time. We
# only want to activate those listed in the config, so clear
# everything then activate only those we want.
unload_all(update=False)

## for plugin in plugins:
for plugin in config.get('ckan.plugins', '').split():
for plugin in plugins:
load(plugin, update=False)

# Load the synchronous search plugin, unless already loaded or
Expand Down Expand Up @@ -157,23 +150,16 @@ def load(plugin, update=True):
if update:
plugins_update()

_plugins[plugin] = service

return service


def unload_all(update=True):
"""
Unload (deactivate) all loaded plugins
"""
## for env in PluginGlobals.env_registry.values():
## for service in env.services.copy():
## unload(service, update=False)

# We copy the _plugins dict so we can delete entries
for plugin in _plugins.copy():
unload(plugin, update=False)

for env in PluginGlobals.env_registry.values():
for service in env.services.copy():
unload(service, update=False)
if update:
plugins_update()

Expand All @@ -192,37 +178,36 @@ def unload(plugin, update=True):
for observer_plugin in observers:
observer_plugin.after_unload(service)

del _plugins[plugin]
if update:
plugins_update()

return service


##def find_user_plugins(config):
## """
## Return all plugins specified by the user in the 'ckan.plugins' config
## directive.
## """
## plugins = []
## for name in config.get('ckan.plugins', '').split():
## entry_points = list(
## iter_entry_points(group=PLUGINS_ENTRY_POINT_GROUP, name=name)
## )
## if not entry_points:
## raise PluginNotFoundException(name)
## plugins.extend(ep.load() for ep in entry_points)
## return plugins
##
##
##def find_system_plugins():
## """
## Return all plugins in the ckan.system_plugins entry point group.
##
## These are essential for operation and therefore cannot be enabled/disabled
## through the configuration file.
## """
## return (
## ep.load()
## for ep in iter_entry_points(group=SYSTEM_PLUGINS_ENTRY_POINT_GROUP)
## )
def find_user_plugins(config):
"""
Return all plugins specified by the user in the 'ckan.plugins' config
directive.
"""
plugins = []
for name in config.get('ckan.plugins', '').split():
entry_points = list(
iter_entry_points(group=PLUGINS_ENTRY_POINT_GROUP, name=name)
)
if not entry_points:
raise PluginNotFoundException(name)
plugins.extend(ep.load() for ep in entry_points)
return plugins


def find_system_plugins():
"""
Return all plugins in the ckan.system_plugins entry point group.
These are essential for operation and therefore cannot be enabled/disabled
through the configuration file.
"""
return (
ep.load()
for ep in iter_entry_points(group=SYSTEM_PLUGINS_ENTRY_POINT_GROUP)
)
3 changes: 2 additions & 1 deletion ckanext/pdfpreview/tests/test_preview.py
Expand Up @@ -8,6 +8,7 @@
import ckan.tests as tests
import ckan.plugins as plugins
import ckan.lib.helpers as h
import ckanext.pdfpreview.plugin as previewplugin
from ckan.lib.create_test_data import CreateTestData
from ckan.config.middleware import make_app

Expand All @@ -20,7 +21,7 @@ def setup_class(cls):
plugins.load('pdf_preview')
cls.app = paste.fixture.TestApp(wsgiapp)

cls.p = plugins.get_pugin('pdf_preview')
cls.p = previewplugin.PdfPreview()

# create test resource
CreateTestData.create()
Expand Down

0 comments on commit e9f4df5

Please sign in to comment.