Skip to content

Commit

Permalink
[#4801] Selective loading in plugins toolkit
Browse files Browse the repository at this point in the history
This took a while to get right because exceptions raised during the
toolkit initialization fail silently and the sympton would be the an
import error later on when trying to import something from the toolkit:

from ckan.plugins.toolkit import get_action

ImportError: cannot import name 'get_action'

TODO: Sort out what gets exposed to extensions in terms of CLI commands
  • Loading branch information
amercader committed Nov 22, 2019
1 parent 465400c commit 472663a
Showing 1 changed file with 24 additions and 18 deletions.
42 changes: 24 additions & 18 deletions ckan/plugins/toolkit.py
Expand Up @@ -130,14 +130,14 @@ def __init__(self):
def _initialize(self):
''' get the required functions/objects, store them for later
access and check that they match the contents dict. '''

import six
import ckan
import ckan.lib.base as base
import ckan.logic as logic

import ckan.lib.base as base
import ckan.logic.validators as logic_validators
import ckan.lib.navl.dictization_functions as dictization_functions
import ckan.lib.helpers as h
import ckan.lib.cli as cli
import ckan.lib.plugins as lib_plugins
import ckan.common as common
from ckan.exceptions import (
Expand All @@ -147,8 +147,10 @@ def _initialize(self):
from ckan.lib.jobs import enqueue as enqueue_job

import ckan.common as converters
import pylons
import webhelpers.html.tags
if six.PY2:
import ckan.lib.cli as cli
import pylons
import webhelpers.html.tags

# Allow class access to these modules
self.__class__.ckan = ckan
Expand Down Expand Up @@ -213,6 +215,7 @@ def _initialize(self):
'''
t['render'] = base.render
t['abort'] = base.abort
t['asbool'] = converters.asbool
self.docstring_overrides['asbool'] = '''Convert a string (e.g. 1,
true, True) from the config file into a boolean.
Expand All @@ -234,7 +237,6 @@ def _initialize(self):
For example: ``bar = toolkit.aslist(config.get('ckan.foo.bar', []))``
'''
t['literal'] = webhelpers.html.tags.literal

t['get_action'] = logic.get_action
t['chained_action'] = logic.chained_action
Expand All @@ -251,22 +253,10 @@ def _initialize(self):
t['UnknownValidator'] = logic.UnknownValidator
t['Invalid'] = logic_validators.Invalid

t['CkanCommand'] = cli.CkanCommand
t['load_config'] = cli.load_config
t['DefaultDatasetForm'] = lib_plugins.DefaultDatasetForm
t['DefaultGroupForm'] = lib_plugins.DefaultGroupForm
t['DefaultOrganizationForm'] = lib_plugins.DefaultOrganizationForm

t['response'] = pylons.response
self.docstring_overrides['response'] = '''The Pylons response object.
Pylons uses this object to generate the HTTP response it returns to the web
browser. It has attributes like the HTTP status code, the response headers,
content type, cookies, etc.
'''
t['BaseController'] = base.BaseController
t['abort'] = base.abort
t['redirect_to'] = h.redirect_to
t['url_for'] = h.url_for
t['get_or_bust'] = logic.get_or_bust
Expand All @@ -290,6 +280,22 @@ def _initialize(self):
t['HelperError'] = HelperError
t['enqueue_job'] = enqueue_job

if six.PY2:

t['literal'] = webhelpers.html.tags.literal
t['response'] = pylons.response
self.docstring_overrides['response'] = '''The Pylons response object.
Pylons uses this object to generate the HTTP response it returns to the web
browser. It has attributes like the HTTP status code, the response headers,
content type, cookies, etc.
'''
t['BaseController'] = base.BaseController
# TODO: Sort these out
t['CkanCommand'] = cli.CkanCommand
t['load_config'] = cli.load_config

# check contents list correct
errors = set(t).symmetric_difference(set(self.contents))
if errors:
Expand Down

0 comments on commit 472663a

Please sign in to comment.