ยปCore Development>Code coverage>Lib/packaging/compiler/extension.py

Python code coverage for Lib/packaging/compiler/extension.py

#countcontent
1n/a"""Class representing C/C++ extension modules."""
2n/a
3n/afrom packaging import logger
4n/a
5n/a# This class is really only used by the "build_ext" command, so it might
6n/a# make sense to put it in distutils.command.build_ext. However, that
7n/a# module is already big enough, and I want to make this class a bit more
8n/a# complex to simplify some common cases ("foo" module in "foo.c") and do
9n/a# better error-checking ("foo.c" actually exists).
10n/a#
11n/a# Also, putting this in build_ext.py means every setup script would have to
12n/a# import that large-ish module (indirectly, through distutils.core) in
13n/a# order to do anything.
14n/a
15n/a
16n/aclass Extension:
17n/a """Just a collection of attributes that describes an extension
18n/a module and everything needed to build it (hopefully in a portable
19n/a way, but there are hooks that let you be as unportable as you need).
20n/a
21n/a Instance attributes:
22n/a name : string
23n/a the full name of the extension, including any packages -- ie.
24n/a *not* a filename or pathname, but Python dotted name
25n/a sources : [string]
26n/a list of source filenames, relative to the distribution root
27n/a (where the setup script lives), in Unix form (slash-separated)
28n/a for portability. Source files may be C, C++, SWIG (.i),
29n/a platform-specific resource files, or whatever else is recognized
30n/a by the "build_ext" command as source for a Python extension.
31n/a include_dirs : [string]
32n/a list of directories to search for C/C++ header files (in Unix
33n/a form for portability)
34n/a define_macros : [(name : string, value : string|None)]
35n/a list of macros to define; each macro is defined using a 2-tuple,
36n/a where 'value' is either the string to define it to or None to
37n/a define it without a particular value (equivalent of "#define
38n/a FOO" in source or -DFOO on Unix C compiler command line)
39n/a undef_macros : [string]
40n/a list of macros to undefine explicitly
41n/a library_dirs : [string]
42n/a list of directories to search for C/C++ libraries at link time
43n/a libraries : [string]
44n/a list of library names (not filenames or paths) to link against
45n/a runtime_library_dirs : [string]
46n/a list of directories to search for C/C++ libraries at run time
47n/a (for shared extensions, this is when the extension is loaded)
48n/a extra_objects : [string]
49n/a list of extra files to link with (eg. object files not implied
50n/a by 'sources', static library that must be explicitly specified,
51n/a binary resource files, etc.)
52n/a extra_compile_args : [string]
53n/a any extra platform- and compiler-specific information to use
54n/a when compiling the source files in 'sources'. For platforms and
55n/a compilers where "command line" makes sense, this is typically a
56n/a list of command-line arguments, but for other platforms it could
57n/a be anything.
58n/a extra_link_args : [string]
59n/a any extra platform- and compiler-specific information to use
60n/a when linking object files together to create the extension (or
61n/a to create a new static Python interpreter). Similar
62n/a interpretation as for 'extra_compile_args'.
63n/a export_symbols : [string]
64n/a list of symbols to be exported from a shared extension. Not
65n/a used on all platforms, and not generally necessary for Python
66n/a extensions, which typically export exactly one symbol: "init" +
67n/a extension_name.
68n/a swig_opts : [string]
69n/a any extra options to pass to SWIG if a source file has the .i
70n/a extension.
71n/a depends : [string]
72n/a list of files that the extension depends on
73n/a language : string
74n/a extension language (i.e. "c", "c++", "objc"). Will be detected
75n/a from the source extensions if not provided.
76n/a optional : boolean
77n/a specifies that a build failure in the extension should not abort the
78n/a build process, but simply not install the failing extension.
79n/a """
80n/a
81n/a # **kwargs are allowed so that a warning is emitted instead of an
82n/a # exception
83n/a def __init__(self, name, sources, include_dirs=None, define_macros=None,
84n/a undef_macros=None, library_dirs=None, libraries=None,
85n/a runtime_library_dirs=None, extra_objects=None,
86n/a extra_compile_args=None, extra_link_args=None,
87n/a export_symbols=None, swig_opts=None, depends=None,
88n/a language=None, optional=None, **kw):
89n/a if not isinstance(name, str):
90n/a raise AssertionError("'name' must be a string")
91n/a
92n/a if not isinstance(sources, list):
93n/a raise AssertionError("'sources' must be a list of strings")
94n/a
95n/a for v in sources:
96n/a if not isinstance(v, str):
97n/a raise AssertionError("'sources' must be a list of strings")
98n/a
99n/a self.name = name
100n/a self.sources = sources
101n/a self.include_dirs = include_dirs or []
102n/a self.define_macros = define_macros or []
103n/a self.undef_macros = undef_macros or []
104n/a self.library_dirs = library_dirs or []
105n/a self.libraries = libraries or []
106n/a self.runtime_library_dirs = runtime_library_dirs or []
107n/a self.extra_objects = extra_objects or []
108n/a self.extra_compile_args = extra_compile_args or []
109n/a self.extra_link_args = extra_link_args or []
110n/a self.export_symbols = export_symbols or []
111n/a self.swig_opts = swig_opts or []
112n/a self.depends = depends or []
113n/a self.language = language
114n/a self.optional = optional
115n/a
116n/a # If there are unknown keyword options, warn about them
117n/a if len(kw) > 0:
118n/a options = [repr(option) for option in kw]
119n/a options = ', '.join(sorted(options))
120n/a logger.warning(
121n/a 'unknown arguments given to Extension: %s', options)