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

trolldbois / ctypeslib / 13391439098

18 Feb 2025 01:15PM UTC coverage: 83.553% (-2.0%) from 85.503%
13391439098

push

github

trolldbois
update some doc

2032 of 2432 relevant lines covered (83.55%)

0.84 hits per line

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

81.16
/ctypeslib/codegen/config.py
1
"""
2
The configuration class that will modify the behavior of ctypeslib
3
"""
4
import os
1✔
5
import re
1✔
6
import subprocess
1✔
7
import sys
1✔
8

9
from ctypeslib.library import Library
1✔
10
from ctypeslib.codegen import typedesc
1✔
11

12

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

41
    def __init__(self):
1✔
42
        self._init_types()
1✔
43
        self.clang_opts = []
1✔
44
        if sys.platform == 'darwin':
1✔
45
            try:
×
46
                sysroot = subprocess.check_output(['xcrun', '--show-sdk-path']).decode('utf8').strip()
×
47
            except subprocess.CalledProcessError:
×
48
                raise RuntimeError("The XCode Command Line Tools must be installed to provide the C standard library headers. Set CTYPESLIB2_SKIP_MACOS_SDK=1 in the environment to skip this check.")
×
49
            self.clang_opts.extend(['-isysroot', sysroot])
×
50

51
    def parse_options(self, options):
1✔
52
        self.symbols = options.symbols
1✔
53
        self.expressions = options.expressions
1✔
54
        if options.expressions:
1✔
55
            self.expressions = list(map(re.compile, options.expressions))
×
56
        self.verbose = options.verbose
1✔
57
        self.generate_comments = options.generate_comments
1✔
58
        self.generate_docstrings = options.generate_docstrings
1✔
59
        self.generate_locations = options.generate_locations
1✔
60
        self.filter_location = not options.generate_includes
1✔
61
        self.preloaded_dlls = options.preload
1✔
62
        # List exported symbols from libraries
63
        self.searched_dlls = [Library(name, nm=options.nm) for name in options.dll]
1✔
64
        self._parse_options_clang_opts(options)
1✔
65
        self._parse_options_modules(options)
1✔
66
        self._parse_options_types(options)
1✔
67

68
    _type_table = {"a": typedesc.Alias,
1✔
69
                   "c": typedesc.Structure,
70
                   "d": typedesc.Variable,
71
                   "e": typedesc.Enumeration,  # , typedesc.EnumValue],
72
                   "f": typedesc.Function,
73
                   "m": typedesc.Macro,
74
                   "s": typedesc.Structure,
75
                   "t": typedesc.Typedef,
76
                   "u": typedesc.Union,
77
                   }
78

79
    def _init_types(self, _default="cdefstu"):
1✔
80
        types = []
1✔
81
        for char in _default:
1✔
82
            typ = self._type_table[char]
1✔
83
            types.append(typ)
1✔
84
        self.types = types
1✔
85

86
    def _parse_options_types(self, options):
1✔
87
        """ Filter objects types """
88
        self._init_types(options.kind)
1✔
89

90
    def _parse_options_modules(self, options):
1✔
91
        # preload python modules with these names
92
        for name in options.modules:
1✔
93
            mod = __import__(name)
×
94
            for submodule in name.split(".")[1:]:
×
95
                mod = getattr(mod, submodule)
×
96
            for name, item in mod.__dict__.items():
×
97
                if isinstance(item, type):
×
98
                    self.known_symbols[name] = mod.__name__
×
99

100
    def _parse_options_clang_opts(self, options):
1✔
101
        if options.target is not None:
1✔
102
            self.clang_opts = ["-target", options.target]
1✔
103
        if options.clang_args is not None:
1✔
104
            self.clang_opts.extend(re.split("\s+", options.clang_args))
×
105

106
    @property
1✔
107
    def cross_arch(self):
1✔
108
        """
109
        Is there a cross architecture option in clang_opts
110
        """
111
        return '-target' in ' '.join(self.clang_opts)
1✔
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