nems.registry module

nems.registry.is_keyword(name, obj)[source]

Determine whether named object is a keyword

Parameters
  • name (string) – Name of object

  • obj (object) – Object

  • function (False if private) –

  • True (all-caps global variable or not callable.) –

  • otherwise.

exception nems.registry.KeywordMissingError(value)[source]

Bases: Exception

Raised when a keyword lookup fails

__init__(value)[source]
class nems.registry.KeywordRegistry(name='registry', **kwargs)[source]

Bases: object

Behaves similar to a dictionary, except that registry[key_string] will trigger a function call based on the leading portion of the key (either before the first period or until the first non-alpha character).

The function call is determined by the Keyword instance referenced by the leading portion of the key, and it will receive the keyword string itself as the first argument followed by **kwargs.

For example:
def add_kwargs(kw, myarg1=’’, myarg2=’’):

return kw + myarg1 + myarg2

kws = KeywordRegistry(myarg1=’ first’, myarg2=’ second’) kws[‘mykey’] = add_kwargs

In[0]: kws[‘mykey.test’] Out[0]: ‘mykey.test first second’

See register_plugin and register_modules for how to add entire directories or modules of keyword definitions.

__init__(name='registry', **kwargs)[source]
__getitem__(kw_string)[source]
__setitem__(kw_head, parse)[source]
kw_head(kw_string)[source]
lookup(kw_string)[source]
source(kw_string)[source]
register_plugin(location)[source]

Registers a plugin

Parameters

location (string) – Can be one of: * module name (e.g., my_code.plugins.keywords) * file name (e.g., `/path/my_code/plugins/keywords.py’) * path name (e.g., ‘/path/my_code/plugins’)

_register_plugin_by_module_name(module_name)[source]
_register_plugin_by_path(pathname)[source]
_register_plugin_by_file(filename)[source]

Adds all callable() names defined inside the Python file as keywords

Parameters

filename (str) – Path to a file containing one or more modules that define keyword functions.

register_plugins(locations)[source]

Invokes self.register_plugin for each package listed in pkgs.

register_function(obj, name=None)[source]

add function obj to registry

register_module(module)[source]

As register_plugin, but module should be a single module object instead of a path for a directory. Default nems keywords are added via this method.

register_modules(modules)[source]

Invokes self.register_module for each module listed in modules.

__iter__()[source]
__next__()[source]
to_json()[source]
classmethod from_json(d)[source]

refresh keyword_lib with registry stored in xfspec. Currently merges with any keywords already registered elsewhere. Possibility: wipe kw and only return what’s specified here? :param d: :return: keyword_lib

info(kw=None)[source]
Parameters

kw

Returns

dictionary with source info for keywords containing string kw or (if kw is None) all keywords

class nems.registry.Keyword(key, parse, source_string)[source]

Bases: object

Parameters
  • key (string) – Keyword (just the base, excluding parameters). e.g., ‘ozgf’

  • parse (callable) – Function that parses full keyword string

  • source_string (string) – Location (i.e., module or file) that keyword was defined in

__init__(key, parse, source_string)[source]
nems.registry.scan_for_kw_defs(module_list)[source]
nems.registry.xforms_kw_info(kw_string, **xforms_kwargs)[source]

report info on an xforms keyword string

nems.registry.test_xforms_kw(kw_string, **xforms_kwargs)[source]

generate the xfspec entry for a keyword string **xforms_kwargs not used???

nems.registry.test_modelspec_kw(kw_string)[source]

generate module keyword output

nems.registry.xform(name=None)[source]
nems.registry.xmodule(name=None)[source]