ยปCore Development>Code coverage>Lib/distutils/command/build.py

Python code coverage for Lib/distutils/command/build.py

#countcontent
1n/a"""distutils.command.build
2n/a
3n/aImplements the Distutils 'build' command."""
4n/a
5n/aimport sys, os
6n/afrom distutils.core import Command
7n/afrom distutils.errors import DistutilsOptionError
8n/afrom distutils.util import get_platform
9n/a
10n/a
11n/adef show_compilers():
12n/a from distutils.ccompiler import show_compilers
13n/a show_compilers()
14n/a
15n/a
16n/aclass build(Command):
17n/a
18n/a description = "build everything needed to install"
19n/a
20n/a user_options = [
21n/a ('build-base=', 'b',
22n/a "base directory for build library"),
23n/a ('build-purelib=', None,
24n/a "build directory for platform-neutral distributions"),
25n/a ('build-platlib=', None,
26n/a "build directory for platform-specific distributions"),
27n/a ('build-lib=', None,
28n/a "build directory for all distribution (defaults to either " +
29n/a "build-purelib or build-platlib"),
30n/a ('build-scripts=', None,
31n/a "build directory for scripts"),
32n/a ('build-temp=', 't',
33n/a "temporary build directory"),
34n/a ('plat-name=', 'p',
35n/a "platform name to build for, if supported "
36n/a "(default: %s)" % get_platform()),
37n/a ('compiler=', 'c',
38n/a "specify the compiler type"),
39n/a ('parallel=', 'j',
40n/a "number of parallel build jobs"),
41n/a ('debug', 'g',
42n/a "compile extensions and libraries with debugging information"),
43n/a ('force', 'f',
44n/a "forcibly build everything (ignore file timestamps)"),
45n/a ('executable=', 'e',
46n/a "specify final destination interpreter path (build.py)"),
47n/a ]
48n/a
49n/a boolean_options = ['debug', 'force']
50n/a
51n/a help_options = [
52n/a ('help-compiler', None,
53n/a "list available compilers", show_compilers),
54n/a ]
55n/a
56n/a def initialize_options(self):
57n/a self.build_base = 'build'
58n/a # these are decided only after 'build_base' has its final value
59n/a # (unless overridden by the user or client)
60n/a self.build_purelib = None
61n/a self.build_platlib = None
62n/a self.build_lib = None
63n/a self.build_temp = None
64n/a self.build_scripts = None
65n/a self.compiler = None
66n/a self.plat_name = None
67n/a self.debug = None
68n/a self.force = 0
69n/a self.executable = None
70n/a self.parallel = None
71n/a
72n/a def finalize_options(self):
73n/a if self.plat_name is None:
74n/a self.plat_name = get_platform()
75n/a else:
76n/a # plat-name only supported for windows (other platforms are
77n/a # supported via ./configure flags, if at all). Avoid misleading
78n/a # other platforms.
79n/a if os.name != 'nt':
80n/a raise DistutilsOptionError(
81n/a "--plat-name only supported on Windows (try "
82n/a "using './configure --help' on your platform)")
83n/a
84n/a plat_specifier = ".%s-%d.%d" % (self.plat_name, *sys.version_info[:2])
85n/a
86n/a # Make it so Python 2.x and Python 2.x with --with-pydebug don't
87n/a # share the same build directories. Doing so confuses the build
88n/a # process for C modules
89n/a if hasattr(sys, 'gettotalrefcount'):
90n/a plat_specifier += '-pydebug'
91n/a
92n/a # 'build_purelib' and 'build_platlib' just default to 'lib' and
93n/a # 'lib.<plat>' under the base build directory. We only use one of
94n/a # them for a given distribution, though --
95n/a if self.build_purelib is None:
96n/a self.build_purelib = os.path.join(self.build_base, 'lib')
97n/a if self.build_platlib is None:
98n/a self.build_platlib = os.path.join(self.build_base,
99n/a 'lib' + plat_specifier)
100n/a
101n/a # 'build_lib' is the actual directory that we will use for this
102n/a # particular module distribution -- if user didn't supply it, pick
103n/a # one of 'build_purelib' or 'build_platlib'.
104n/a if self.build_lib is None:
105n/a if self.distribution.ext_modules:
106n/a self.build_lib = self.build_platlib
107n/a else:
108n/a self.build_lib = self.build_purelib
109n/a
110n/a # 'build_temp' -- temporary directory for compiler turds,
111n/a # "build/temp.<plat>"
112n/a if self.build_temp is None:
113n/a self.build_temp = os.path.join(self.build_base,
114n/a 'temp' + plat_specifier)
115n/a if self.build_scripts is None:
116n/a self.build_scripts = os.path.join(self.build_base,
117n/a 'scripts-%d.%d' % sys.version_info[:2])
118n/a
119n/a if self.executable is None:
120n/a self.executable = os.path.normpath(sys.executable)
121n/a
122n/a if isinstance(self.parallel, str):
123n/a try:
124n/a self.parallel = int(self.parallel)
125n/a except ValueError:
126n/a raise DistutilsOptionError("parallel should be an integer")
127n/a
128n/a def run(self):
129n/a # Run all relevant sub-commands. This will be some subset of:
130n/a # - build_py - pure Python modules
131n/a # - build_clib - standalone C libraries
132n/a # - build_ext - Python extensions
133n/a # - build_scripts - (Python) scripts
134n/a for cmd_name in self.get_sub_commands():
135n/a self.run_command(cmd_name)
136n/a
137n/a
138n/a # -- Predicates for the sub-command list ---------------------------
139n/a
140n/a def has_pure_modules(self):
141n/a return self.distribution.has_pure_modules()
142n/a
143n/a def has_c_libraries(self):
144n/a return self.distribution.has_c_libraries()
145n/a
146n/a def has_ext_modules(self):
147n/a return self.distribution.has_ext_modules()
148n/a
149n/a def has_scripts(self):
150n/a return self.distribution.has_scripts()
151n/a
152n/a
153n/a sub_commands = [('build_py', has_pure_modules),
154n/a ('build_clib', has_c_libraries),
155n/a ('build_ext', has_ext_modules),
156n/a ('build_scripts', has_scripts),
157n/a ]