Skip to content

Loaders

create_actions(*modules)

Finds action functions in the given modules and returns a name -> function dict. Actions are found by finding all functions in each module that meet the is_action function criteria (see the is_action function in this module).

Parameters:

Name Type Description Default
modules

the modules to search through

()

Returns:

Type Description

an actions dict

Source code in ckantools/loaders.py
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
def create_actions(*modules):
    """
    Finds action functions in the given modules and returns a name -> function dict.
    Actions are found by finding all functions in each module that meet the is_action
    function criteria (see the is_action function in this module).

    :param modules: the modules to search through
    :return: an actions dict
    """
    actions = {}

    for module in modules:
        # actions must be functions and pass the is_action function's tests
        functions = inspect.getmembers(
            module, lambda f: inspect.isfunction(f) and is_action(f)
        )
        for function_name, function in functions:
            if getattr(function, 'load_action_schema', False):
                actions[function_name] = wrap_action_function(function_name, function)
            else:
                actions[function_name] = function

    return actions

create_auth(*modules)

Finds auth functions in the given modules and returns a name -> function dict. Auths are found by finding all functions in each module that meet the is_auth function criteria (see the is_auth function in this module).

Parameters:

Name Type Description Default
modules

the modules to search through

()

Returns:

Type Description

an auths dict

Source code in ckantools/loaders.py
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
def create_auth(*modules):
    """
    Finds auth functions in the given modules and returns a name -> function dict. Auths
    are found by finding all functions in each module that meet the is_auth function
    criteria (see the is_auth function in this module).

    :param modules: the modules to search through
    :return: an auths dict
    """
    auth = {}

    for module in modules:
        # auths must be functions and pass the is_auth function's tests
        functions = inspect.getmembers(
            module, lambda f: inspect.isfunction(f) and is_auth(f)
        )
        for function_name, function in functions:
            auth[function_name] = function

    return auth

create_validators(*modules)

Finds validator functions in the given modules and returns a name -> function dict. Validators are found by finding all functions in each module that meet the is_validator function criteria (see the is_validator function).

Parameters:

Name Type Description Default
modules

the modules to search through

()

Returns:

Type Description

a validators dict

Source code in ckantools/loaders.py
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
def create_validators(*modules):
    """
    Finds validator functions in the given modules and returns a name -> function dict.
    Validators are found by finding all functions in each module that meet the
    is_validator function criteria (see the is_validator function).

    :param modules: the modules to search through
    :return: a validators dict
    """
    validators = {}

    for module in modules:
        functions = inspect.getmembers(
            module, lambda f: inspect.isfunction(f) and is_validator(f)
        )
        for function_name, function in functions:
            validators[function_name] = function

    return validators