• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

trolldbois / ctypeslib / 4773580042

pending completion
4773580042

push

github

Loic Jaquemet
Merge branch 'pull-98'

1617 of 1929 relevant lines covered (83.83%)

50.05 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.73
/ctypeslib/codegen/config.py
1
import re
60✔
2

3
from ctypeslib.library import Library
60✔
4
from ctypeslib.codegen import typedesc
60✔
5

6

7
class CodegenConfig:
60✔
8
    # symbol to include, if empty, everything will be included
9
    symbols: list = []
60✔
10
    # regular expression for symbols to include
11
    expressions: list = []
60✔
12
    # verbose output
13
    verbose: bool = False
60✔
14
    # include source doxygen-style comments
15
    generate_comments: bool = False
60✔
16
    # include docstrings containing C prototype and source file location
17
    generate_docstrings: bool = False
60✔
18
    # include source file location in comments
19
    generate_locations: bool = False
60✔
20
    # do not include declaration defined outside of the source files
21
    filter_location: bool = True
60✔
22
    # dll to be loaded before all others (to resolve symbols)
23
    preloaded_dlls: list = []
60✔
24
    # kind of type descriptions to include
25
    types: list = []
60✔
26
    # the host's triplet
27
    local_platform_triple: str = None
60✔
28
    #
29
    known_symbols: dict = {}
60✔
30
    #
31
    searched_dlls: list = []
60✔
32
    # clang preprocessor options
33
    clang_opts: list = []
60✔
34

35
    def __init__(self):
60✔
36
        self._init_types()
60✔
37
        pass
60✔
38

39
    def parse_options(self, options):
60✔
40
        self.symbols = options.symbols
60✔
41
        self.expressions = options.expressions
60✔
42
        if options.expressions:
60✔
43
            self.expressions = list(map(re.compile, options.expressions))
×
44
        self.verbose = options.verbose
60✔
45
        self.generate_comments = options.generate_comments
60✔
46
        self.generate_docstrings = options.generate_docstrings
60✔
47
        self.generate_locations = options.generate_locations
60✔
48
        self.filter_location = not options.generate_includes
60✔
49
        self.preloaded_dlls = options.preload
60✔
50
        # List exported symbols from libraries
51
        self.searched_dlls = [Library(name, nm=options.nm) for name in options.dll]
60✔
52
        self._parse_options_clang_opts(options)
60✔
53
        self._parse_options_modules(options)
60✔
54
        self._parse_options_types(options)
60✔
55

56
    _type_table = {"a": typedesc.Alias,
60✔
57
                   "c": typedesc.Structure,
60✔
58
                   "d": typedesc.Variable,
60✔
59
                   "e": typedesc.Enumeration,  # , typedesc.EnumValue],
60✔
60
                   "f": typedesc.Function,
60✔
61
                   "m": typedesc.Macro,
60✔
62
                   "s": typedesc.Structure,
60✔
63
                   "t": typedesc.Typedef,
60✔
64
                   "u": typedesc.Union,
60✔
65
                   }
×
66

67
    def _init_types(self, _default="cdefstu"):
60✔
68
        types = []
60✔
69
        for char in _default:
60✔
70
            typ = self._type_table[char]
60✔
71
            types.append(typ)
60✔
72
        self.types = types
60✔
73

74
    def _parse_options_types(self, options):
60✔
75
        """ Filter objects types """
76
        self._init_types(options.kind)
77

78
    def _parse_options_modules(self, options):
79
        # preload python modules with these names
80
        for name in options.modules:
81
            mod = __import__(name)
82
            for submodule in name.split(".")[1:]:
83
                mod = getattr(mod, submodule)
84
            for name, item in mod.__dict__.items():
85
                if isinstance(item, type):
86
                    self.known_symbols[name] = mod.__name__
87

88
    def _parse_options_clang_opts(self, options):
89
        if options.target is not None:
90
            self.clang_opts = ["-target", options.target]
91
        if options.clang_args is not None:
92
            self.clang_opts.extend(re.split("\s+", options.clang_args))
93

94
    @property
95
    def cross_arch(self):
96
        """
97
        Is there a cross architecture option in clang_opts
×
98
        """
×
99
        return '-target' in ' '.join(self.clang_opts)
60✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc