diff options
author | Arthur de Jong <arthur@arthurdejong.org> | 2012-09-22 17:40:03 +0200 |
---|---|---|
committer | Arthur de Jong <arthur@arthurdejong.org> | 2012-09-22 17:40:03 +0200 |
commit | 3f6d52a1aa5489484a83833dc194ad9ed380bf65 (patch) | |
tree | 5ac01c1c1017a3addb6330eacabfbc390bf3ba2a /stdnum/util.py | |
parent | af7e837890541ef2215909b57f88a5e806a4dc45 (diff) |
generate part of the stdnum docstring based on introspection of the modules
git-svn-id: http://arthurdejong.org/svn/python-stdnum/python-stdnum@176 9dea7c4f-944c-4273-ac1a-574ede026edc
Diffstat (limited to 'stdnum/util.py')
-rw-r--r-- | stdnum/util.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/stdnum/util.py b/stdnum/util.py index c4f1115..451c116 100644 --- a/stdnum/util.py +++ b/stdnum/util.py @@ -25,6 +25,11 @@ stdnum. """ import pkgutil +import pydoc +import re + + +_strip_doctest_re = re.compile('^>>> .*\Z', re.DOTALL | re.MULTILINE) def clean(number, deletechars): @@ -46,3 +51,23 @@ def get_number_modules(base='stdnum'): module = __import__(name, globals(), locals(), [name]) if hasattr(module, 'is_valid'): yield module + + +def get_module_name(module): + """Return the short description of the number.""" + return pydoc.splitdoc(pydoc.getdoc(module))[0] + + +def get_module_description(module): + """Return a description of the number.""" + doc = pydoc.splitdoc(pydoc.getdoc(module))[1] + # remove the doctests + return _strip_doctest_re.sub('', doc[1]).strip(), + + +def get_module_list(): + for module in get_number_modules(): + yield ' * %s: %s' % ( + module.__name__.replace('stdnum.', ''), + get_module_name(module), + ) |