File: foomodulegen-auto.py

package info (click to toggle)
pybindgen 0.20.0%2Bdfsg1-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,932 kB
  • sloc: python: 15,981; cpp: 1,889; ansic: 617; makefile: 86; sh: 4
file content (76 lines) | stat: -rw-r--r-- 2,275 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#! /usr/bin/env python
from __future__ import unicode_literals, print_function, absolute_import

import sys
import os
import logging

import pybindgen
from pybindgen.typehandlers import base as typehandlers
from pybindgen import (ReturnValue, Parameter, Module, Function, FileCodeSink)
from pybindgen import (CppMethod, CppConstructor, CppClass, Enum)
from pybindgen.function import CustomFunctionWrapper
from pybindgen.cppmethod import CustomCppMethodWrapper

import foomodulegen_common


def my_module_gen():
    pygccxml_mode = sys.argv[4]
    if pygccxml_mode == 'castxml':
        from pybindgen.castxmlparser import ModuleParser
    else:
        from pybindgen.gccxmlparser import ModuleParser

    out = FileCodeSink(sys.stdout)
    pygen_file = open(sys.argv[3], "wt")
    module_parser = ModuleParser('foo2', '::')
    module_parser.enable_anonymous_containers = True

    print("PYTHON_INCLUDES:", repr(sys.argv[2]), file=sys.stderr)
    kwargs = {
        "{mode}_options".format(mode=pygccxml_mode): dict(
            include_paths=eval(sys.argv[2]),
            )
    }
    module_parser.parse_init([sys.argv[1]], includes=['"foo.h"'], pygen_sink=FileCodeSink(pygen_file),
                             **kwargs)
    module = module_parser.module
    foomodulegen_common.customize_module_pre(module)

    module.add_exception('exception', foreign_cpp_namespace='std', message_rvalue='%(EXC)s.what()')
    module_parser.scan_types()
    module_parser.scan_methods()
    module_parser.scan_functions()
    module_parser.parse_finalize()

    pygen_file.close()

    foomodulegen_common.customize_module(module)

    module.generate(out)


def main():
    logging.basicConfig(level=logging.DEBUG)
    if sys.argv[1] == '-d':
        del sys.argv[1]
        import pdb
        pdb.set_trace()
        my_module_gen()
    else:
        import os
        if "PYBINDGEN_ENABLE_PROFILING" in os.environ:
            try:
                import cProfile as profile
            except ImportError:
                my_module_gen()
            else:
                print("** running under profiler", file=sys.stderr)
                profile.run('my_module_gen()', 'foomodulegen-auto.pstat')
        else:
            my_module_gen()

if __name__ == '__main__':
    main()