Git commit d37c51dcb6a66920e797b712542eb29b6f03e9a8 by Sven Brauch. Committed on 30/09/2011 at 23:39. Pushed by brauch into branch 'master'. more numpy documentation M +0 -1 CMakeLists.txt M +39 -7 documentation_src/numpy/generate_numpy_doc.py http://commits.kde.org/kdev-python/d37c51dcb6a66920e797b712542eb29b6f03e9a8 diff --git a/CMakeLists.txt b/CMakeLists.txt index 08be6a3..cc6f95e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -65,4 +65,3 @@ install(DIRECTORY documentation_files DESTINATION ${DATA_INSTALL_DIR}/kdevpython install(DIRECTORY python-src/Lib/encodings DESTINATION ${DATA_INSTALL_DIR}/kdevpythonsupport/encodings) -add_subdirectory(documentation_src/numpy) \ No newline at end of file diff --git a/documentation_src/numpy/generate_numpy_doc.py b/documentation_src/numpy/generate_numpy_doc.py index 5dd43df..45e06fa 100644 --- a/documentation_src/numpy/generate_numpy_doc.py +++ b/documentation_src/numpy/generate_numpy_doc.py @@ -34,7 +34,18 @@ def remove_indent(string): else: return string +def escape_docstring(string): + if string: + return string.replace('"""', '\\"\\"\\"') + else: + return string + + +global in_class +in_class = 0 + def make_documentation(class_or_module): + global in_class result = "" for item_name in dir(class_or_module): if item_name in ['__abstractmethods__', '__class__']: @@ -43,18 +54,28 @@ def make_documentation(class_or_module): # skip private properties continue item = getattr(class_or_module, item_name) - if type(item) in [types.FunctionType, types.BuiltinFunctionType, types.UnboundMethodType]: + if type(item) in [types.FunctionType, types.BuiltinFunctionType, types.UnboundMethodType] \ + or str(type(item)) in ['', '', '']: parameters = try_parse_func_docstring(item.__doc__) + if in_class > 0: + parameters = ['self'].extend(parameters) result += "def %s(%s):\n" % ( item_name, ','.join(parameters) ) - result += indent('"""%s"""\n\n' % remove_indent(item.__doc__)) + result += indent('"""%s"""\n\n' % remove_indent(escape_docstring(item.__doc__))) elif type(item) == types.TypeType: result += "class %s:\n" % item_name + in_class += 1 result += indent(make_documentation(item)) + "\n" + in_class -= 1 else: - #if item.__doc__ is not None: - #result += '"""%s"""\n' % item.__doc__ try: - default_value = str(type(item)()) + if type(item) in [types.TypeType, types.ClassType]: + default_value = str(item.__name__ + "()") + else: + default_value = str(type(item)()) + if default_value == "": + raise TypeError() + if default_value.find('<') != -1: + raise TypeError() except TypeError: default_value = "None" result += "%s = %s\n" % (item_name, default_value) @@ -74,7 +95,7 @@ def try_parse_func_docstring(docstring): atLineBeginning = False if docstring[offset:offset+len("Parameters")] == "Parameters": paramListBegin = offset - if docstring[offset:offset+len("Returns")] == "Returns": + if docstring[offset:offset+len("---")] == "---": paramListEnd = offset relevantPart = docstring[paramListBegin:paramListEnd].split("\n")[2:] if len(relevantPart): @@ -87,7 +108,18 @@ def try_parse_func_docstring(docstring): name = s[0] type_string = s[1] doc_for_param = None # TODO extract this, and display it in some way... or not - parameter_name_list.append(name.replace(' ', '').replace('\t', '')) + parameter_name = name.replace(' ', '').replace('\t', '').replace('\\', '') \ + .replace('.', '_').replace('[', '').replace(']', '') \ + .replace('*', '').replace('-', '_') + try: + t = int(parameter_name[0]) + parameter_name = '_' + parameter_name + except: + pass + if parameter_name.find('...') != -1: + parameter_name = 'more' + parameter_name = parameter_name.replace('`', '') + parameter_name_list.append(parameter_name) return parameter_name_list else: return []