Skip to content

Commit

Permalink
Merge pull request ckan#5996 from ckan/5965-plugins-ordering
Browse files Browse the repository at this point in the history
[ckan#5965] Ensure order of plugins in PluginImplementations
  • Loading branch information
smotornyuk authored Mar 31, 2021
2 parents 18c92bd + 2884ed2 commit 713716b
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 13 deletions.
4 changes: 3 additions & 1 deletion ckan/lib/search/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import requests

from ckan.common import asbool, config
import ckan.model as model
import ckan.plugins as p
import ckan.logic as logic
Expand Down Expand Up @@ -117,7 +118,8 @@ class SynchronousSearchPlugin(p.SingletonPlugin):
p.implements(p.IDomainObjectModification, inherit=True)

def notify(self, entity, operation):
if not isinstance(entity, model.Package):
if (not isinstance(entity, model.Package) or
not asbool(config.get('ckan.search.automatic_indexing', True))):
return
if operation != model.domain_object.DomainObjectOperation.deleted:
dispatch_by_operation(
Expand Down
24 changes: 17 additions & 7 deletions ckan/plugins/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,23 @@ def __iter__(self):

iterator = super(PluginImplementations, self).__iter__()

return reversed(list(iterator))
plugin_lookup = {pf.name: pf for pf in iterator}

plugins_in_config = (
config.get('ckan.plugins', '').split() + find_system_plugins())

ordered_plugins = []
for pc in plugins_in_config:
if pc in plugin_lookup:
ordered_plugins.append(plugin_lookup[pc])
plugin_lookup.pop(pc)

if plugin_lookup:
# Any oustanding plugin not in the ini file (ie system ones),
# add to the end of the iterator
ordered_plugins.extend(plugin_lookup.values())

return iter(ordered_plugins)


class PluginNotFoundException(Exception):
Expand Down Expand Up @@ -145,12 +161,6 @@ def load_all():
unload_all()

plugins = config.get('ckan.plugins', '').split() + find_system_plugins()
# Add the synchronous search plugin, unless already loaded or
# explicitly disabled
if 'synchronous_search' not in plugins and \
asbool(config.get('ckan.search.automatic_indexing', True)):
log.debug('Loading the synchronous search plugin')
plugins.append('synchronous_search')

load(*plugins)

Expand Down
16 changes: 16 additions & 0 deletions ckan/tests/plugins/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,19 @@ def test_plugins_order_in_pluginimplementations():
u"example_idatasetform_v3"
]
)


@pytest.mark.usefixtures(u"with_plugins")
@pytest.mark.ckan_config(
u"ckan.plugins",
u"example_idatasetform_v1 example_idatasetform_v3 example_idatasetform_v2")
def test_plugins_order_in_pluginimplementations_matches_config():

assert (
[plugin.name for plugin in p.PluginImplementations(p.IDatasetForm)] ==
[
u"example_idatasetform_v1",
u"example_idatasetform_v3",
u"example_idatasetform_v2"
]
)
6 changes: 1 addition & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,11 @@
'solr = ckan.lib.search.solr_backend:SolrSearchBackend',
],
'ckan.plugins': [
'synchronous_search = ckan.lib.search:SynchronousSearchPlugin',
'stats = ckanext.stats.plugin:StatsPlugin',
'publisher_form = ckanext.publisher_form.forms:PublisherForm',
'publisher_dataset_form = ckanext.publisher_form.forms:PublisherDatasetForm',
'multilingual_dataset = ckanext.multilingual.plugin:MultilingualDataset',
'multilingual_group = ckanext.multilingual.plugin:MultilingualGroup',
'multilingual_tag = ckanext.multilingual.plugin:MultilingualTag',
'multilingual_resource = ckanext.multilingual.plugin:MultilingualResource',
'organizations = ckanext.organizations.forms:OrganizationForm',
'organizations_dataset = ckanext.organizations.forms:OrganizationDatasetForm',
'expire_api_token = ckanext.expire_api_token.plugin:ExpireApiTokenPlugin',
'chained_functions = ckanext.chained_functions.plugin:ChainedFunctionsPlugin',
'datastore = ckanext.datastore.plugin:DatastorePlugin',
Expand Down Expand Up @@ -163,6 +158,7 @@
'example_humanizer = ckanext.example_humanizer.plugin:ExampleHumanizerPlugin',
],
'ckan.system_plugins': [
'synchronous_search = ckan.lib.search:SynchronousSearchPlugin',
'domain_object_mods = ckan.model.modification:DomainObjectModificationExtension',
],
'ckan.test_plugins': [
Expand Down

0 comments on commit 713716b

Please sign in to comment.