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

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

#countcontent
1n/a"""Main build command, which calls the other build_* commands."""
2n/a
3n/aimport sys
4n/aimport os
5n/a
6n/afrom packaging.util import get_platform
7n/afrom packaging.command.cmd import Command
8n/afrom packaging.errors import PackagingOptionError
9n/afrom packaging.compiler import show_compilers
10n/a
11n/a
12n/aclass build(Command):
13n/a
14n/a description = "build everything needed to install"
15n/a
16n/a user_options = [
17n/a ('build-base=', 'b',
18n/a "base directory for build library"),
19n/a ('build-purelib=', None,
20n/a "build directory for platform-neutral distributions"),
21n/a ('build-platlib=', None,
22n/a "build directory for platform-specific distributions"),
23n/a ('build-lib=', None,
24n/a "build directory for all distribution (defaults to either " +
25n/a "build-purelib or build-platlib"),
26n/a ('build-scripts=', None,
27n/a "build directory for scripts"),
28n/a ('build-temp=', 't',
29n/a "temporary build directory"),
30n/a ('plat-name=', 'p',
31n/a "platform name to build for, if supported "
32n/a "(default: %s)" % get_platform()),
33n/a ('compiler=', 'c',
34n/a "specify the compiler type"),
35n/a ('debug', 'g',
36n/a "compile extensions and libraries with debugging information"),
37n/a ('force', 'f',
38n/a "forcibly build everything (ignore file timestamps)"),
39n/a ('executable=', 'e',
40n/a "specify final destination interpreter path (build.py)"),
41n/a ('use-2to3', None,
42n/a "use 2to3 to make source python 3.x compatible"),
43n/a ('convert-2to3-doctests', None,
44n/a "use 2to3 to convert doctests in separate text files"),
45n/a ('use-2to3-fixers', None,
46n/a "list additional fixers opted for during 2to3 conversion"),
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 = False
69n/a self.executable = None
70n/a self.use_2to3 = False
71n/a self.convert_2to3_doctests = None
72n/a self.use_2to3_fixers = None
73n/a
74n/a def finalize_options(self):
75n/a if self.plat_name is None:
76n/a self.plat_name = get_platform()
77n/a else:
78n/a # plat-name only supported for windows (other platforms are
79n/a # supported via ./configure flags, if at all). Avoid misleading
80n/a # other platforms.
81n/a if os.name != 'nt':
82n/a raise PackagingOptionError(
83n/a "--plat-name only supported on Windows (try "
84n/a "using './configure --help' on your platform)")
85n/a pyversion = '%s.%s' % sys.version_info[:2]
86n/a plat_specifier = ".%s-%s" % (self.plat_name, pyversion)
87n/a
88n/a # Make it so Python 2.x and Python 2.x with --with-pydebug don't
89n/a # share the same build directories. Doing so confuses the build
90n/a # process for C modules
91n/a if hasattr(sys, 'gettotalrefcount'):
92n/a plat_specifier += '-pydebug'
93n/a
94n/a # 'build_purelib' and 'build_platlib' just default to 'lib' and
95n/a # 'lib.<plat>' under the base build directory. We only use one of
96n/a # them for a given distribution, though --
97n/a if self.build_purelib is None:
98n/a self.build_purelib = os.path.join(self.build_base, 'lib')
99n/a if self.build_platlib is None:
100n/a self.build_platlib = os.path.join(self.build_base,
101n/a 'lib' + plat_specifier)
102n/a
103n/a # 'build_lib' is the actual directory that we will use for this
104n/a # particular module distribution -- if user didn't supply it, pick
105n/a # one of 'build_purelib' or 'build_platlib'.
106n/a if self.build_lib is None:
107n/a if self.distribution.ext_modules:
108n/a self.build_lib = self.build_platlib
109n/a else:
110n/a self.build_lib = self.build_purelib
111n/a
112n/a # 'build_temp' -- temporary directory for compiler turds,
113n/a # "build/temp.<plat>"
114n/a if self.build_temp is None:
115n/a self.build_temp = os.path.join(self.build_base,
116n/a 'temp' + plat_specifier)
117n/a if self.build_scripts is None:
118n/a self.build_scripts = os.path.join(self.build_base,
119n/a 'scripts-' + pyversion)
120n/a
121n/a if self.executable is None:
122n/a self.executable = os.path.normpath(sys.executable)
123n/a
124n/a def run(self):
125n/a # Run all relevant sub-commands. This will be some subset of:
126n/a # - build_py - pure Python modules
127n/a # - build_clib - standalone C libraries
128n/a # - build_ext - Python extension modules
129n/a # - build_scripts - Python scripts
130n/a for cmd_name in self.get_sub_commands():
131n/a self.run_command(cmd_name)
132n/a
133n/a # -- Predicates for the sub-command list ---------------------------
134n/a
135n/a def has_pure_modules(self):
136n/a return self.distribution.has_pure_modules()
137n/a
138n/a def has_c_libraries(self):
139n/a return self.distribution.has_c_libraries()
140n/a
141n/a def has_ext_modules(self):
142n/a return self.distribution.has_ext_modules()
143n/a
144n/a def has_scripts(self):
145n/a return self.distribution.has_scripts()
146n/a
147n/a sub_commands = [('build_py', has_pure_modules),
148n/a ('build_clib', has_c_libraries),
149n/a ('build_ext', has_ext_modules),
150n/a ('build_scripts', has_scripts),
151n/a ]