From 739a6675d79d14f1dbef30f906ac9fbdd55e432c Mon Sep 17 00:00:00 2001 From: "Gustavo J. A. M. Carneiro" Date: Mon, 21 Dec 2009 19:22:22 +0000 Subject: [PATCH] sphinx-ify more docs --- doc/conf.py | 4 +- doc/cppclass.rst | 4 +- doc/cppclass_typehandlers.rst | 4 +- doc/cppexception.rst | 6 +- pybindgen/container.py | 9 +-- pybindgen/cppattribute.py | 42 +++++++------- pybindgen/cppclass.py | 59 ++++++++++---------- pybindgen/cppclass_typehandlers.py | 16 ++++-- pybindgen/cppexception.py | 29 +++++----- pybindgen/cppmethod.py | 45 +++++++-------- pybindgen/function.py | 31 ++++++---- pybindgen/gccxmlparser.py | 65 +++++++++++---------- pybindgen/module.py | 16 +++--- pybindgen/typehandlers/base.py | 90 +++++++++++++++--------------- pybindgen/typehandlers/codesink.py | 7 +-- wscript | 2 + 16 files changed, 222 insertions(+), 207 deletions(-) diff --git a/doc/conf.py b/doc/conf.py index 02c31f1..811e719 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -198,7 +198,9 @@ latex_documents = [ # Example configuration for intersphinx: refer to the Python standard library. -intersphinx_mapping = {'http://docs.python.org/': None} +intersphinx_mapping = {'http://docs.python.org/': None, + 'http://www.language-binding.net/': None, + } autoclass_content = "both" diff --git a/doc/cppclass.rst b/doc/cppclass.rst index 4508f19..497bf67 100644 --- a/doc/cppclass.rst +++ b/doc/cppclass.rst @@ -1,7 +1,7 @@ -======================= +========================================== cppclass: wrap C++ classes or C structures -======================= +========================================== .. automodule:: pybindgen.cppclass diff --git a/doc/cppclass_typehandlers.rst b/doc/cppclass_typehandlers.rst index 11249f0..2b2ea6e 100644 --- a/doc/cppclass_typehandlers.rst +++ b/doc/cppclass_typehandlers.rst @@ -1,7 +1,7 @@ -======================= +====================================================================== cppclass_typehandlers: type handlers for C++ classes (or C structures) -======================= +====================================================================== .. automodule:: pybindgen.cppclass_typehandlers diff --git a/doc/cppexception.rst b/doc/cppexception.rst index c11a15b..9f5adf2 100644 --- a/doc/cppexception.rst +++ b/doc/cppexception.rst @@ -1,7 +1,7 @@ -============================================== -cppexceptions: translate C++ exceptions into Python -============================================== +================================================== +cppexception: translate C++ exceptions into Python +================================================== .. automodule:: pybindgen.cppexception diff --git a/pybindgen/container.py b/pybindgen/container.py index 0b37c86..013c6ce 100644 --- a/pybindgen/container.py +++ b/pybindgen/container.py @@ -98,12 +98,13 @@ class Container(object): :param name: C++ type name of the container, e.g. std::vector or MyIntList :param value_type: a ReturnValue of the element type: note, - for mapping containers, value_type is a tuple with two - ReturnValue's: (key, element). + for mapping containers, value_type is a tuple with two + ReturnValue's: (key, element). :param container_type: a string with the type of container, - one of 'list', 'deque', 'queue', 'priority_queue', 'vector', - 'stack', 'set', 'multiset', 'hash_set', 'hash_multiset', 'map' + one of 'list', 'deque', 'queue', 'priority_queue', + 'vector', 'stack', 'set', 'multiset', 'hash_set', + 'hash_multiset', 'map' :param outer_class: if the type is defined inside a class, must be a reference to the outer class :type outer_class: None or L{CppClass} diff --git a/pybindgen/cppattribute.py b/pybindgen/cppattribute.py index 1299763..56c16e4 100644 --- a/pybindgen/cppattribute.py +++ b/pybindgen/cppattribute.py @@ -34,10 +34,10 @@ class CppInstanceAttributeGetter(PyGetter): ''' def __init__(self, value_type, class_, attribute_name, getter=None): """ - value_type -- a ReturnValue object handling the value type; - class_ -- the class (CppClass object) - attribute_name -- name of attribute - getter -- None, or name of a method of the class used to get the value + :param value_type: a ReturnValue object handling the value type; + :param class_: the class (CppClass object) + :param attribute_name: name of attribute + :param getter: None, or name of a method of the class used to get the value """ super(CppInstanceAttributeGetter, self).__init__( value_type, [], "return NULL;", "return NULL;", no_c_retval=True) @@ -57,7 +57,7 @@ class CppInstanceAttributeGetter(PyGetter): def generate(self, code_sink): """ - code_sink -- a CodeSink instance that will receive the generated code + :param code_sink: a CodeSink instance that will receive the generated code """ tmp_sink = codesink.MemoryCodeSink() self.generate_body(tmp_sink) @@ -76,8 +76,8 @@ class CppStaticAttributeGetter(PyGetter): ''' def __init__(self, value_type, class_, attribute_name): """ - value_type -- a ReturnValue object handling the value type; - c_value_expression -- C value expression + :param value_type: a ReturnValue object handling the value type; + :param c_value_expression: C value expression """ super(CppStaticAttributeGetter, self).__init__( value_type, [], "return NULL;", "return NULL;", no_c_retval=True) @@ -93,7 +93,7 @@ class CppStaticAttributeGetter(PyGetter): def generate(self, code_sink): """ - code_sink -- a CodeSink instance that will receive the generated code + :param code_sink: a CodeSink instance that will receive the generated code """ tmp_sink = codesink.MemoryCodeSink() self.generate_body(tmp_sink) @@ -113,10 +113,10 @@ class CppInstanceAttributeSetter(PySetter): ''' def __init__(self, value_type, class_, attribute_name, setter=None): """ - value_type -- a ReturnValue object handling the value type; - class_ -- the class (CppClass object) - attribute_name -- name of attribute - setter -- None, or name of a method of the class used to set the value + :param value_type: a ReturnValue object handling the value type; + :param class_: the class (CppClass object) + :param attribute_name: name of attribute + :param setter: None, or name of a method of the class used to set the value """ super(CppInstanceAttributeSetter, self).__init__( value_type, [], "return -1;") @@ -128,7 +128,7 @@ class CppInstanceAttributeSetter(PySetter): def generate(self, code_sink): """ - code_sink -- a CodeSink instance that will receive the generated code + :param code_sink: a CodeSink instance that will receive the generated code """ self.declarations.declare_variable('PyObject*', 'py_retval') @@ -187,9 +187,9 @@ class CppStaticAttributeSetter(PySetter): ''' def __init__(self, value_type, class_, attribute_name): """ - value_type -- a ReturnValue object handling the value type; - class_ -- the class (CppClass object) - attribute_name -- name of attribute + :param value_type: a ReturnValue object handling the value type; + :param class_: the class (CppClass object) + :param attribute_name: name of attribute """ super(CppStaticAttributeSetter, self).__init__( value_type, [], "return -1;") @@ -202,7 +202,7 @@ class CppStaticAttributeSetter(PySetter): def generate(self, code_sink): """ - code_sink -- a CodeSink instance that will receive the generated code + :param code_sink: a CodeSink instance that will receive the generated code """ self.declarations.declare_variable('PyObject*', 'py_retval') @@ -336,7 +336,7 @@ class PyGetSetDef(object): """ def __init__(self, cname): """ - cname -- C name of the getset table + :param cname: C name of the getset table """ self.cname = cname self.attributes = [] # (name, getter, setter) @@ -347,9 +347,9 @@ class PyGetSetDef(object): def add_attribute(self, name, getter, setter): """ Add a new attribute - name -- attribute name - getter -- a PyGetter object, or None - setter -- a PySetter object, or None + :param name: attribute name + :param getter: a PyGetter object, or None + :param setter: a PySetter object, or None """ assert getter is None or isinstance(getter, PyGetter) assert setter is None or isinstance(setter, PySetter) diff --git a/pybindgen/cppclass.py b/pybindgen/cppclass.py index efa1cf9..e3e7140 100644 --- a/pybindgen/cppclass.py +++ b/pybindgen/cppclass.py @@ -1,7 +1,3 @@ -""" -Wrap C++ classes and methods -""" - import warnings import traceback @@ -84,7 +80,7 @@ class ReferenceCountingPolicy(MemoryPolicy): Write code to increase the reference code of an object of this class (the real C++ class, not the wrapper). Should only be called if the class supports reference counting, as reported - by the attribute `has_reference_counting'. + by the attribute `CppClass.has_reference_counting`. """ raise NotImplementedError @@ -93,7 +89,7 @@ class ReferenceCountingPolicy(MemoryPolicy): Write code to decrease the reference code of an object of this class (the real C++ class, not the wrapper). Should only be called if the class supports reference counting, as reported - by the attribute `has_reference_counting'. + by the attribute `CppClass.has_reference_counting`. """ raise NotImplementedError @@ -183,7 +179,7 @@ class CppHelperClass(object): def __init__(self, class_): """ - class_ -- original CppClass wrapper object + :param class_: original CppClass wrapper object """ self.class_ = class_ self.name = class_.pystruct + "__PythonHelper" @@ -464,29 +460,30 @@ class CppClass(object): :param free_function: (deprecated in favour of memory_policy) name of C function used to deallocate class instances :param incref_function: (deprecated in favour of memory_policy) same as incref_method, but as a function instead of method :param decref_function: (deprecated in favour of memory_policy) same as decref_method, but as a function instead of method + :param python_name: name of the class as it will appear from - Python side. This parameter is DEPRECATED in favour of - custom_name. + Python side. This parameter is DEPRECATED in favour of + custom_name. :param memory_policy: memory management policy; if None, it - inherits from the parent class. Only root classes can have a - memory policy defined. + inherits from the parent class. Only root classes can have a + memory policy defined. :type memory_policy: L{MemoryPolicy} :param foreign_cpp_namespace: if set, the class is assumed to - belong to the given C++ namespace, regardless of the C++ - namespace of the python module it will be added to. For - instance, this can be useful to wrap std classes, like - std::ofstream, without having to create an extra python - submodule. + belong to the given C++ namespace, regardless of the C++ + namespace of the python module it will be added to. For + instance, this can be useful to wrap std classes, like + std::ofstream, without having to create an extra python + submodule. :param docstring: None or a string containing the docstring - that will be generated for the class + that will be generated for the class :param custom_name: an alternative name to give to this class - at python-side; if omitted, the name of the class in the - python module will be the same name as the class in C++ (minus - namespace). + at python-side; if omitted, the name of the class in the + python module will be the same name as the class in C++ + (minus namespace). """ assert outer_class is None or isinstance(outer_class, CppClass) @@ -682,7 +679,7 @@ class CppClass(object): of the type of the class, either by reference or by value. :param operator: string indicating the name of the operator to - support, e.g. '==' + support, e.g. '==' """ operator = utils.ascii(operator) if not isinstance(operator, str): @@ -694,17 +691,17 @@ class CppClass(object): def add_binary_numeric_operator(self, operator, result_cppclass=None, left_cppclass=None, right=None): """ - Add support for a C++ binary numeric operator, such as +, -, *, or /. + Add support for a C++ binary numeric operator, such as +, -, \\*, or /. :param operator: string indicating the name of the operator to - support, e.g. '==' + support, e.g. '==' :param result_cppclass: the CppClass object of the result type, assumed to be this class if omitted :param left_cppclass: the CppClass object of the left operand type, assumed to be this class if omitted :param right: the type of the right parameter. Can be a - CppClass, Parameter, or param spec. Assumed to be this class - if omitted + CppClass, Parameter, or param spec. Assumed to be this class + if omitted """ operator = utils.ascii(operator) if not isinstance(operator, str): @@ -740,14 +737,14 @@ class CppClass(object): def add_inplace_numeric_operator(self, operator, right=None): """ - Add support for a C++ inplace numeric operator, such as +=, -=, *=, or /=. + Add support for a C++ inplace numeric operator, such as +=, -=, \\*=, or /=. :param operator: string indicating the name of the operator to - support, e.g. '+=' + support, e.g. '+=' :param right: the type of the right parameter. Can be a - CppClass, Parameter, or param spec. Assumed to be this class - if omitted + CppClass, Parameter, or param spec. Assumed to be this class + if omitted """ operator = utils.ascii(operator) if not isinstance(operator, str): @@ -776,7 +773,7 @@ class CppClass(object): Add support for a C++ unary numeric operators, currently only -. :param operator: string indicating the name of the operator to - support, e.g. '-' + support, e.g. '-' :param result_cppclass: the CppClass object of the result type, assumed to be this class if omitted :param left_cppclass: the CppClass object of the left operand type, assumed to be this class if omitted @@ -882,7 +879,7 @@ class CppClass(object): def is_subclass(self, other): """Return True if this CppClass instance represents a class that is a - subclass of another class represented by the CppClasss object `other'.""" + subclass of another class represented by the CppClasss object \\`other\\'.""" if not isinstance(other, CppClass): raise TypeError cls = self diff --git a/pybindgen/cppclass_typehandlers.py b/pybindgen/cppclass_typehandlers.py index ef78b2b..5f05ecb 100644 --- a/pybindgen/cppclass_typehandlers.py +++ b/pybindgen/cppclass_typehandlers.py @@ -193,8 +193,8 @@ class CppClassParameterBase(Parameter): def __init__(self, ctype, name, direction=Parameter.DIRECTION_IN, is_const=False, default_value=None): """ - ctype -- C type, normally 'MyClass*' - name -- parameter name + :param ctype: C type, normally 'MyClass*' + :param name: parameter name """ if ctype == self.cpp_class.name: ctype = self.cpp_class.full_name @@ -222,7 +222,9 @@ class CppClassReturnValueBase(ReturnValue): class CppClassParameter(CppClassParameterBase): - "Class handlers" + """ + Class parameter "by-value" handler + """ CTYPES = [] cpp_class = cppclass.CppClass('dummy') # CppClass instance DIRECTIONS = [Parameter.DIRECTION_IN] @@ -703,7 +705,9 @@ class CppClassPtrParameter(CppClassParameterBase): string); probably, the only default value that makes sense here is probably 'NULL'. - @note: only arguments which are instances of C++ classes + .. note:: + + Only arguments which are instances of C++ classes wrapped by PyBindGen can be used as custodians. """ if ctype == self.cpp_class.name: @@ -991,7 +995,9 @@ class CppClassPtrReturnValue(CppClassReturnValueBase): (instance the method is bound to) to the lifetime of the return value. - @note: only arguments which are instances of C++ classes + .. note:: + + Only arguments which are instances of C++ classes wrapped by PyBindGen can be used as custodians. """ if ctype == self.cpp_class.name: diff --git a/pybindgen/cppexception.py b/pybindgen/cppexception.py index 7554648..ab6f73d 100644 --- a/pybindgen/cppexception.py +++ b/pybindgen/cppexception.py @@ -11,24 +11,25 @@ class CppException(object): :param name: exception class name :param parent: optional parent class wrapper - :param custom_name: an alternative name to give to this exception class - at python-side; if omitted, the name of the class in the - python module will be the same name as the class in C++ (minus - namespace). + :param custom_name: an alternative name to give to this + exception class at python-side; if omitted, the name of + the class in the python module will be the same name as + the class in C++ (minus namespace). :param foreign_cpp_namespace: if set, the class is assumed to - belong to the given C++ namespace, regardless of the C++ - namespace of the python module it will be added to. For - instance, this can be useful to wrap std classes, like - std::ofstream, without having to create an extra python - submodule. + belong to the given C++ namespace, regardless of the + C++ namespace of the python module it will be added to. + For instance, this can be useful to wrap std classes, + like std::ofstream, without having to create an extra + python submodule. :param message_rvalue: if not None, this parameter is a string - that contains an rvalue C expression that evaluates to the - exception message. The Python % operator will be used to - substitute %(EXC)s for the caught exception variable name. The - rvalue expression must return a string of type "char const*", - a pointer owned by the exception instance. + that contains an rvalue C expression that evaluates to + the exception message. The Python % operator will be + used to substitute %(EXC)s for the caught exception + variable name. The rvalue expression must return a + string of type "char const*", a pointer owned by the + exception instance. """ self.name = name self.full_name = None diff --git a/pybindgen/cppmethod.py b/pybindgen/cppmethod.py index 64d9e10..896d5ac 100644 --- a/pybindgen/cppmethod.py +++ b/pybindgen/cppmethod.py @@ -35,7 +35,7 @@ class CppMethod(ForwardWrapperBase): :param method_name: name of the method :param parameters: the method parameters - :type parameters: list of L{Parameter} + :type parameters: list of :class:`pybindgen.typehandlers.base.Parameter` :param is_static: whether it is a static method @@ -47,15 +47,16 @@ class CppMethod(ForwardWrapperBase): :param is_const: whether the method has a const modifier on it :param unblock_threads: whether to release the Python GIL - around the method call or not. If None or omitted, use global - settings. Releasing the GIL has a small performance penalty, - but is recommended if the method is expected to take - considerable time to complete, because otherwise no other - Python thread is allowed to run until the method completes. + around the method call or not. If None or omitted, use + global settings. Releasing the GIL has a small + performance penalty, but is recommended if the method is + expected to take considerable time to complete, because + otherwise no other Python thread is allowed to run until + the method completes. :param is_pure_virtual: whether the method is defined as "pure - virtual", i.e. virtual method with no default implementation - in the class being wrapped. + virtual", i.e. virtual method with no default implementation + in the class being wrapped. :param custom_name: alternate name to give to the method, in python side. @@ -419,7 +420,7 @@ class DummyReturnValue(ReturnValue): """ Accepts either a ReturnValue object or a tuple as sole parameter. In case it's a tuple, it is assumed to be a retval - spec (*args, **kwargs). + spec (\\*args, \\*\\*kwargs). """ if isinstance(arg, ReturnValue): super(DummyReturnValue, self).__init__(arg.ctype) @@ -445,7 +446,7 @@ class DummyParameter(Parameter): """ Accepts either a Parameter object or a tuple as sole parameter. In case it's a tuple, it is assumed to be a retval - spec (*args, **kwargs). + spec (\\*args, \\*\\*kwargs). """ if isinstance(arg, ReturnValue): super(DummyParameter, self).__init__(arg.ctype) @@ -642,10 +643,9 @@ class CppConstructor(ForwardWrapperBase): def generate(self, code_sink, wrapper_name=None, extra_wrapper_params=()): """ Generates the wrapper code - code_sink -- a CodeSink instance that will receive the generated code - class_ -- the c++ class wrapper the method belongs to + :param code_sink: a CodeSink instance that will receive the generated code + :returns: the wrapper function name. - Returns the wrapper function name. """ if self.visibility == 'private': raise utils.SkipWrapper("Class %r has a private constructor ->" @@ -690,9 +690,10 @@ class CppFunctionAsConstructor(CppConstructor): """ def __init__(self, c_function_name, return_value, parameters, unblock_threads=None): """ - :param c_function_name: name of the C/C++ function; FIXME: for now it is - implied that this function returns a pointer to the a class - instance with caller_owns_return=True semantics. + :param c_function_name: name of the C/C++ function; FIXME: for + now it is implied that this function returns a pointer to + the a class instance with caller_owns_return=True + semantics. :param return_value: function return value type :type return_value: L{ReturnValue} @@ -739,7 +740,7 @@ class CppNoConstructor(ForwardWrapperBase): def __init__(self, reason): """ - reason -- string indicating reason why the class cannot be constructed. + :param reason: string indicating reason why the class cannot be constructed. """ self.stack_where_defined = traceback.extract_stack() super(CppNoConstructor, self).__init__( @@ -754,6 +755,7 @@ class CppNoConstructor(ForwardWrapperBase): def generate(self, code_sink, class_): """ Generates the wrapper code + :param code_sink: a CodeSink instance that will receive the generated code :param class_: the c++ class wrapper the method belongs to @@ -782,8 +784,6 @@ class CppVirtualMethodParentCaller(CppMethod): """ def __init__(self, method, unblock_threads=None): - """ - """ super(CppVirtualMethodParentCaller, self).__init__( method.method_name, method.return_value, method.parameters, unblock_threads=unblock_threads) #self.static_decl = False @@ -896,9 +896,6 @@ class CppVirtualMethodProxy(ReverseWrapperBase): """ def __init__(self, method): - """ - xxx - """ self.stack_where_defined = traceback.extract_stack() super(CppVirtualMethodProxy, self).__init__(method.return_value, method.parameters) self.method_name = method.method_name @@ -1016,7 +1013,7 @@ class CustomCppMethodWrapper(CppMethod): """ Adds a custom method wrapper. The custom wrapper must be prepared to support overloading, i.e. it must have an additional - "PyObject **return_exception" parameter, and raised exceptions + "PyObject \\*\\*return_exception" parameter, and raised exceptions must be returned by this parameter. """ @@ -1056,7 +1053,7 @@ class CustomCppConstructorWrapper(CppConstructor): """ Adds a custom constructor wrapper. The custom wrapper must be prepared to support overloading, i.e. it must have an additional - "PyObject **return_exception" parameter, and raised exceptions + \\"PyObject \\*\\*return_exception\\" parameter, and raised exceptions must be returned by this parameter. """ diff --git a/pybindgen/function.py b/pybindgen/function.py index 09d9147..401f06c 100644 --- a/pybindgen/function.py +++ b/pybindgen/function.py @@ -25,25 +25,26 @@ class Function(ForwardWrapperBase): """ :param function_name: name of the C function :param return_value: the function return value - @type return_value: L{ReturnValue} + :type return_value: L{ReturnValue} :param parameters: the function parameters - @type parameters: list of L{Parameter} + :type parameters: list of L{Parameter} :param custom_name: an alternative name to give to this - function at python-side; if omitted, the name of the function - in the python module will be the same name as the function in - C++ (minus namespace). + function at python-side; if omitted, the name of the + function in the python module will be the same name as the + function in C++ (minus namespace). :param deprecated: deprecation state for this API: - False: Not deprecated - True: Deprecated - "message": Deprecated, and deprecation warning contains the given message - :param foreign_cpp_namespace: if set, the function is assumed to - belong to the given C++ namespace, regardless of the C++ - namespace of the python module it will be added to. + + :param foreign_cpp_namespace: if set, the function is assumed + to belong to the given C++ namespace, regardless of the C++ + namespace of the python module it will be added to. :param throw: list of C++ exceptions that the function may throw - @type throw: list of L{CppException} + :type throw: list of L{CppException} """ self.stack_where_defined = traceback.extract_stack() @@ -207,8 +208,9 @@ class Function(ForwardWrapperBase): def generate(self, code_sink, wrapper_name=None, extra_wrapper_params=()): """ Generates the wrapper code - code_sink -- a CodeSink instance that will receive the generated code - wrapper_name -- name of wrapper function + + :param code_sink: a CodeSink instance that will receive the generated code + :param wrapper_name: name of wrapper function """ if wrapper_name is None: self.wrapper_actual_name = self.wrapper_base_name @@ -266,7 +268,7 @@ class CustomFunctionWrapper(Function): """ Adds a custom function wrapper. The custom wrapper must be prepared to support overloading, i.e. it must have an additional - "PyObject **return_exception" parameter, and raised exceptions + "PyObject \\*\\*return_exception" parameter, and raised exceptions must be returned by this parameter. """ @@ -274,6 +276,11 @@ class CustomFunctionWrapper(Function): def __init__(self, function_name, wrapper_name, wrapper_body=None, flags=('METH_VARARGS', 'METH_KEYWORDS')): + """ + :param function_name: name for function, Python side + :param wrapper_name: name of the C wrapper function + :param wrapper_body: if not None, the function wrapper is generated containing this parameter value as function body + """ super(CustomFunctionWrapper, self).__init__(function_name, ReturnValue.new('void'), []) self.wrapper_base_name = wrapper_name self.wrapper_actual_name = wrapper_name diff --git a/pybindgen/gccxmlparser.py b/pybindgen/gccxmlparser.py index 3e4737d..6506ec8 100644 --- a/pybindgen/gccxmlparser.py +++ b/pybindgen/gccxmlparser.py @@ -414,21 +414,21 @@ class PygenSection(object): def __init__(self, name, code_sink, local_customizations_module=None): """ :param name: section name; this name should be a valid python - module name; the special name '__main__' is used to denote the - main section, which comprises the main script itself + module name; the special name '__main__' is used to denote the + main section, which comprises the main script itself :type name: str :param code_sink: code sink that will receive the generated - code for the section. Normally the code sink should write to - a file with the name of the section and a .py extension, to - allow importing it as module. + code for the section. Normally the code sink should write to + a file with the name of the section and a .py extension, to + allow importing it as module. :type code_sink: L{CodeSink} :param local_customizations_module: name of the python module - that may contain local customizations for the section, or - None. If not None, PyBindGen will generate code that tries to - import that module in the respective section and call - functions on it, or ignore it if the module does not exist. + that may contain local customizations for the section, or + None. If not None, PyBindGen will generate code that tries to + import that module in the respective section and call + functions on it, or ignore it if the module does not exist. :type local_customizations_module: str """ assert isinstance(name, str) @@ -462,14 +462,14 @@ class PygenClassifier(object): :param section_name: the name of the section :returns: order of precedence of the section. The lower the - number, the sooner the section is to be registered. + number, the sooner the section is to be registered. """ raise NotImplementedError class ModuleParser(object): """ - @ivar enable_anonymous_containers: if True, pybindgen will attempt + :attr enable_anonymous_containers: if True, pybindgen will attempt to scan for all std containers, even the ones that have no typedef'ed name. Enabled by default. @@ -595,27 +595,28 @@ class ModuleParser(object): Prepares to parse a set of header files. The following methods should then be called in order to finish the rest of scanning process: - 1. scan_types() - 2. scan_methods() - 2. scan_functions() - 3. parse_finalize() - :param header_files: header files to parse - :type header_files: list of string + #. scan_types() + #. scan_methods() + #. scan_functions() + #. parse_finalize() - :param include_paths: (deprecated, use the parameter gccxml_options) list of include paths - :type include_paths: list of string + :param header_files: header files to parse + :type header_files: list of string - :param whitelist_paths: additional directories for definitions to be included + :param include_paths: (deprecated, use the parameter gccxml_options) list of include paths + :type include_paths: list of string + + :param whitelist_paths: additional directories for definitions to be included Normally the module parser filters out API definitions that have been defined outside one of the header files indicated for parsing. The parameter whitelist_paths instructs the module parser to accept definitions defined in another header file if such header file is inside one of the directories listed by whitelist_paths. - :type whitelist_paths: list of string + :type whitelist_paths: list of string - :param pygen_sink: code sink for python script generation. + :param pygen_sink: code sink for python script generation. This parameter activates a mode wherein ModuleParser, in addition to building in memory API definitions, creates a @@ -625,21 +626,19 @@ class ModuleParser(object): installed. The pygen parameter can be either: - 1. A single code sink: this will become the main and only script file to be generated - 2. A list of L{PygenSection} objects. This option - requires the pygen_classifier to be given. + #. A single code sink: this will become the main and only script file to be generated + #. A list of L{PygenSection} objects. This option + requires the pygen_classifier to be given. - :type pygen_sink: L{CodeSink} or list of L{PygenSection} objects + :type pygen_sink: L{CodeSink} or list of L{PygenSection} objects - :param pygen_classifier: the classifier to use when pygen is given and is a dict + :param pygen_classifier: the classifier to use when pygen is given and is a dict + :param gccxml_options: extra options to pass into the + :class:`pygccxml.parser.config.gccxml_configuration_t` object as keyword + arguments for more information). - :param gccxml_options: extra options to pass into - the gccxml_configuration_t object as keyword arguments (see - U{pygccxml API documentation} - for more information). - - :type gccxml_options: dict + :type gccxml_options: dict """ assert isinstance(header_files, list) diff --git a/pybindgen/module.py b/pybindgen/module.py index 2150ae0..5a2eec8 100644 --- a/pybindgen/module.py +++ b/pybindgen/module.py @@ -276,9 +276,11 @@ class ModuleBase(dict): the future belong to the section given by that section_name parameter, until a matching end_section() is called. - @note: L{begin_section}/L{end_section} are silently ignored - unless a L{MultiSectionFactory} object is used as code - generation output. + .. note:: + + :meth:`begin_section`/:meth:`end_section` are silently ignored + unless a :class:`MultiSectionFactory` object is used as code + generation output. """ if self.current_section != '__main__': raise ValueError("begin_section called while current section not ended") @@ -293,7 +295,7 @@ class ModuleBase(dict): will belong to the main module. :param section_name: name of section; must match the one in - the previous L{begin_section} call. + the previous :meth:`begin_section` call. """ assert self.parent is None if self._current_section != section_name: @@ -325,7 +327,7 @@ class ModuleBase(dict): raise ValueError("submodule %s not found" % submodule_name) def get_root(self): - ":return: the root L{Module} (even if it is self)" + ":return: the root :class:`Module` (even if it is self)" root = self while root.parent is not None: root = root.parent @@ -385,7 +387,7 @@ class ModuleBase(dict): def add_function(self, *args, **kwargs): """ Add a function to the module/namespace. See the documentation for - L{Function.__init__} for information on accepted parameters. + :meth:`Function.__init__` for information on accepted parameters. """ if len(args) >= 1 and isinstance(args[0], Function): func = args[0] @@ -410,7 +412,7 @@ class ModuleBase(dict): def add_custom_function_wrapper(self, *args, **kwargs): """ Add a function, using custom wrapper code, to the module/namespace. See the documentation for - L{CustomFunctionWrapper.__init__} for information on accepted parameters. + :class:`pybindgen.function.CustomFunctionWrapper` for information on accepted parameters. """ try: func = CustomFunctionWrapper(*args, **kwargs) diff --git a/pybindgen/typehandlers/base.py b/pybindgen/typehandlers/base.py index 4d15b59..1706a8d 100644 --- a/pybindgen/typehandlers/base.py +++ b/pybindgen/typehandlers/base.py @@ -387,8 +387,8 @@ class BuildValueParameters(object): the list being the template string. :param force_tuple_creation: if True, Py_BuildValue is - instructed to always create a tuple, even for zero or 1 - values. + instructed to always create a tuple, even for zero or 1 + values. """ template = ['"'] if force_tuple_creation: @@ -508,27 +508,27 @@ class ReverseWrapperBase(object): Reverse wrappers all have the following general structure in common: 1. 'declarations' -- variable declarations; for compatibility with - older C compilers it is very important that all declarations - come before any simple statement. Declarations can be added - with the add_declaration() method on the 'declarations' - attribute. Two standard declarations are always predeclared: - ' retval', unless return-type is void, and 'PyObject - *py_retval'; + older C compilers it is very important that all declarations + come before any simple statement. Declarations can be added + with the add_declaration() method on the 'declarations' + attribute. Two standard declarations are always predeclared: + ' retval', unless return-type is void, and 'PyObject + \\*py_retval'; 2. 'code before call' -- this is a code block dedicated to contain - all code that is needed before calling into Python; code can be - freely added to it by accessing the 'before_call' (a CodeBlock - instance) attribute; + all code that is needed before calling into Python; code can be + freely added to it by accessing the 'before_call' (a CodeBlock + instance) attribute; 3. 'call into python' -- this is realized by a - PyObject_CallMethod(...) or similar Python API call; the list - of parameters used in this call can be customized by accessing - the 'build_params' (a BuildValueParameters instance) attribute; + PyObject_CallMethod(...) or similar Python API call; the list + of parameters used in this call can be customized by accessing + the 'build_params' (a BuildValueParameters instance) attribute; 4. 'code after call' -- this is a code block dedicated to contain - all code that must come after calling into Python; code can be - freely added to it by accessing the 'after_call' (a CodeBlock - instance) attribute; + all code that must come after calling into Python; code can be + freely added to it by accessing the 'after_call' (a CodeBlock + instance) attribute; 5. A 'return retval' statement (or just 'return' if return_value is void) @@ -676,40 +676,41 @@ class ForwardWrapperBase(object): Forward wrappers all have the following general structure in common: - 1. 'declarations' -- variable declarations; for compatibility with - older C compilers it is very important that all declarations - come before any simple statement. Declarations can be added - with the add_declaration() method on the 'declarations' - attribute. Two standard declarations are always predeclared: - ' retval', unless return-type is void, and 'PyObject - *py_retval'; + 1. 'declarations' -- variable declarations; for compatibility + with older C compilers it is very important that all + declarations come before any simple statement. + Declarations can be added with the add_declaration() + method on the 'declarations' attribute. Two standard + declarations are always predeclared: ' + retval', unless return-type is void, and 'PyObject + \\*py_retval'; 2. 'code before parse' -- code before the - PyArg_ParseTupleAndKeywords call; code can be freely added to - it by accessing the 'before_parse' (a CodeBlock instance) - attribute; + PyArg_ParseTupleAndKeywords call; code can be freely added to + it by accessing the 'before_parse' (a CodeBlock instance) + attribute; 3. A PyArg_ParseTupleAndKeywords call; uses items from the - parse_params object; + parse_params object; 4. 'code before call' -- this is a code block dedicated to contain - all code that is needed before calling the C function; code can be - freely added to it by accessing the 'before_call' (a CodeBlock - instance) attribute; + all code that is needed before calling the C function; code can be + freely added to it by accessing the 'before_call' (a CodeBlock + instance) attribute; 5. 'call into C' -- this is realized by a C/C++ call; the list of - parameters that should be used is in the 'call_params' wrapper - attribute; + parameters that should be used is in the 'call_params' wrapper + attribute; 6. 'code after call' -- this is a code block dedicated to contain - all code that must come after calling into Python; code can be - freely added to it by accessing the 'after_call' (a CodeBlock - instance) attribute; + all code that must come after calling into Python; code can be + freely added to it by accessing the 'after_call' (a CodeBlock + instance) attribute; 7. A py_retval = Py_BuildValue(...) call; this call can be - customized, so that out/inout parameters can add additional - return values, by accessing the 'build_params' (a - BuildValueParameters instance) attribute; + customized, so that out/inout parameters can add additional + return values, by accessing the 'build_params' (a + BuildValueParameters instance) attribute; 8. Cleanup and return. @@ -986,7 +987,7 @@ class TypeTransformation(object): Given a transformed named, get the original C type name. E.g., given a smart pointer transformation, MySmartPointer:: - get_untransformed_name('MySmartPointer') -> 'Foo*' + get_untransformed_name('MySmartPointer') -> 'Foo\\*' """ raise NotImplementedError @@ -1006,7 +1007,7 @@ class TypeTransformation(object): equivalent value expression in the transformed type. Example, with the transformation:: - 'T*' -> 'boost::shared_ptr' + 'T\\*' -> 'boost::shared_ptr' Then:: transform(wrapper, 'foo') -> 'boost::shared_ptr<%s>(foo)' % type_handler.untransformed_ctype """ @@ -1018,7 +1019,7 @@ class TypeTransformation(object): equivalent value expression in the original type. Example, with the transformation:: - 'T*' -> 'boost::shared_ptr' + 'T\\*' -> 'boost::shared_ptr' Then:: untransform(wrapper, 'foo') -> 'foo->get_pointer()' """ @@ -1259,8 +1260,6 @@ class Parameter(TypeHandler): ''' Creates a parameter object - Keywork Arguments: - :param ctype: actual C/C++ type being used :param name: parameter name :param direction: direction of the parameter transfer, valid values @@ -1325,7 +1324,9 @@ class TypeMatcher(object): def register(self, name, type_handler): """Register a new handler class for a given C type + :param name: C type name + :param type_handler: class to handle this C type """ name = ctypeparser.normalize_type_string(name) @@ -1366,6 +1367,7 @@ class TypeMatcher(object): :param name: C type name, possibly transformed (e.g. MySmartPointer looks up Foo*) :returns: a handler with the given ctype name, or raises KeyError. + Supports type transformations. """ diff --git a/pybindgen/typehandlers/codesink.py b/pybindgen/typehandlers/codesink.py index 39d3336..9835eb9 100644 --- a/pybindgen/typehandlers/codesink.py +++ b/pybindgen/typehandlers/codesink.py @@ -77,8 +77,7 @@ class FileCodeSink(CodeSink): """A code sink that writes to a file-like object""" def __init__(self, file_): """ - Keyword Arguments: - file_ -- a file like object + :param file_: a file like object """ CodeSink.__init__(self) self.file = file_ @@ -105,7 +104,7 @@ class MemoryCodeSink(CodeSink): def flush_to(self, sink): """Flushes code to another code sink - sink -- another CodeSink instance + :param sink: another CodeSink instance """ assert isinstance(sink, CodeSink) for line in self.lines: @@ -135,7 +134,7 @@ class NullCodeSink(CodeSink): def flush_to(self, sink): """Flushes code to another code sink - sink -- another CodeSink instance + :param sink: another CodeSink instance """ raise TypeError("Cannot flush a NullCodeSink; it has no content!") diff --git a/wscript b/wscript index 944a1ab..8d5b8f5 100644 --- a/wscript +++ b/wscript @@ -3,12 +3,14 @@ import Options import Build + import Scripting Scripting.excludes.remove('Makefile') Scripting.dist_format = 'zip' import Configure Configure.autoconfig = True + import Logs #from Params import fatal