From 3f6d52a1aa5489484a83833dc194ad9ed380bf65 Mon Sep 17 00:00:00 2001 From: Arthur de Jong Date: Sat, 22 Sep 2012 15:40:03 +0000 Subject: 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 --- stdnum/util.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'stdnum/util.py') 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), + ) -- cgit v1.2.3