def test_register_config(): nok_(has_config('datalad.testdummies.invalid')) assert_raises( ValueError, register_config, 'datalad.testdummies.invalid', title=None, dialog='yesno') nok_(has_config('datalad.testdummies.invalid')) cfgkey = 'datalad.testdummies.try1' nok_(has_config(cfgkey)) register_config( cfgkey, 'This is what happens, when you do not listen to mama!', default_fn=lambda: 5, description='Try on-access default "computation"', type=int, dialog='question', scope='global', ) from datalad.interface.common_cfg import definitions assert_in(cfgkey, definitions) # same thing, other part of the API assert_in(cfgkey, definitions.keys()) # and yet another assert_in(cfgkey, [k for k, v in definitions.items()]) # one more still assert_in(cfgkey, [k for k in definitions]) # more smoke testing, we must have at least this one ok_(len(definitions)) df = definitions[cfgkey] # on access default computation eq_(df['default'], 5) # we could set any novel property df['novel'] = 'unexpected' eq_(df.get('novel'), 'unexpected') eq_(df.get('toonovel'), None) # smoke test str/repr assert_in('mama', str(df)) assert_in('mama', repr(df)) # internal data structure for UI was assembled assert_in('ui', df) # more smoke assert_in('ui', df.keys()) assert_in('ui', [k for k in df]) nkeys = len(df) df.update(funky='seven') eq_(len(df), nkeys + 1)
def run(self): opath = self.rstpath if not os.path.exists(opath): os.makedirs(opath) from datalad.dochelpers import _indent from datalad.interface.common_cfg import definitions as cfgdefs categories = { 'global': {}, 'local': {}, 'dataset': {}, 'misc': {} } for term, v in cfgdefs.items(): categories[v.get('destination', 'misc')][term] = v for cat in categories: with open(opj(opath, '{}.rst.in'.format(cat)), 'w') as rst: rst.write('.. glossary::\n') for term, v in sorted(categories[cat].items(), key=lambda x: x[0]): rst.write(_indent(term, '\n ')) qtype, docs = v.get('ui', (None, {})) desc_tmpl = '\n' if 'title' in docs: desc_tmpl += '{title}:\n' if 'text' in docs: desc_tmpl += '{text}\n' if 'default' in v: default = v['default'] if hasattr(default, 'replace'): # protect against leaking specific home dirs v['default'] = default.replace(os.path.expanduser('~'), '~') desc_tmpl += 'Default: {default}\n' if 'type' in v: type_ = v['type'] if hasattr(type_, 'long_description'): type_ = type_.long_description() else: type_ = type_.__name__ desc_tmpl += '\n[{type}]\n' v['type'] = type_ if desc_tmpl == '\n': # we need something to avoid joining terms desc_tmpl += 'undocumented\n' v.update(docs) rst.write(_indent(desc_tmpl.format(**v), ' '))
def run(self): opath = self.rstpath if not os.path.exists(opath): os.makedirs(opath) from datalad.interface.common_cfg import definitions as cfgdefs from datalad.dochelpers import _indent categories = { 'global': {}, 'local': {}, 'dataset': {}, 'misc': {} } for term, v in cfgdefs.items(): categories[v.get('destination', 'misc')][term] = v for cat in categories: with open(opj(opath, '{}.rst'.format(cat)), 'w') as rst: rst.write('.. glossary::\n') for term, v in sorted(categories[cat].items(), key=lambda x: x[0]): rst.write(_indent(term, '\n ')) qtype, docs = v.get('ui', (None, {})) desc_tmpl = '\n' if 'title' in docs: desc_tmpl += '{title}:\n' if 'text' in docs: desc_tmpl += '{text}\n' if 'default' in v: default = v['default'] if hasattr(default, 'replace'): # protect against leaking specific home dirs v['default'] = default.replace(os.path.expanduser('~'), '~') desc_tmpl += 'Default: {default}\n' if 'type' in v: type_ = v['type'] if hasattr(type_, 'long_description'): type_ = type_.long_description() else: type_ = type_.__name__ desc_tmpl += '\n[{type}]\n' v['type'] = type_ if desc_tmpl == '\n': # we need something to avoid joining terms desc_tmpl += 'undocumented\n' v.update(docs) rst.write(_indent(desc_tmpl.format(**v), ' '))