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

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

#countcontent
1n/a"""distutils.command.bdist_dumb
2n/a
3n/aImplements the Distutils 'bdist_dumb' command (create a "dumb" built
4n/adistribution -- i.e., just an archive to be unpacked under $prefix or
5n/a$exec_prefix)."""
6n/a
7n/aimport os
8n/afrom distutils.core import Command
9n/afrom distutils.util import get_platform
10n/afrom distutils.dir_util import remove_tree, ensure_relative
11n/afrom distutils.errors import *
12n/afrom distutils.sysconfig import get_python_version
13n/afrom distutils import log
14n/a
15n/aclass bdist_dumb(Command):
16n/a
17n/a description = "create a \"dumb\" built distribution"
18n/a
19n/a user_options = [('bdist-dir=', 'd',
20n/a "temporary directory for creating the distribution"),
21n/a ('plat-name=', 'p',
22n/a "platform name to embed in generated filenames "
23n/a "(default: %s)" % get_platform()),
24n/a ('format=', 'f',
25n/a "archive format to create (tar, gztar, bztar, xztar, "
26n/a "ztar, zip)"),
27n/a ('keep-temp', 'k',
28n/a "keep the pseudo-installation tree around after " +
29n/a "creating the distribution archive"),
30n/a ('dist-dir=', 'd',
31n/a "directory to put final built distributions in"),
32n/a ('skip-build', None,
33n/a "skip rebuilding everything (for testing/debugging)"),
34n/a ('relative', None,
35n/a "build the archive using relative paths"
36n/a "(default: false)"),
37n/a ('owner=', 'u',
38n/a "Owner name used when creating a tar file"
39n/a " [default: current user]"),
40n/a ('group=', 'g',
41n/a "Group name used when creating a tar file"
42n/a " [default: current group]"),
43n/a ]
44n/a
45n/a boolean_options = ['keep-temp', 'skip-build', 'relative']
46n/a
47n/a default_format = { 'posix': 'gztar',
48n/a 'nt': 'zip' }
49n/a
50n/a def initialize_options(self):
51n/a self.bdist_dir = None
52n/a self.plat_name = None
53n/a self.format = None
54n/a self.keep_temp = 0
55n/a self.dist_dir = None
56n/a self.skip_build = None
57n/a self.relative = 0
58n/a self.owner = None
59n/a self.group = None
60n/a
61n/a def finalize_options(self):
62n/a if self.bdist_dir is None:
63n/a bdist_base = self.get_finalized_command('bdist').bdist_base
64n/a self.bdist_dir = os.path.join(bdist_base, 'dumb')
65n/a
66n/a if self.format is None:
67n/a try:
68n/a self.format = self.default_format[os.name]
69n/a except KeyError:
70n/a raise DistutilsPlatformError(
71n/a "don't know how to create dumb built distributions "
72n/a "on platform %s" % os.name)
73n/a
74n/a self.set_undefined_options('bdist',
75n/a ('dist_dir', 'dist_dir'),
76n/a ('plat_name', 'plat_name'),
77n/a ('skip_build', 'skip_build'))
78n/a
79n/a def run(self):
80n/a if not self.skip_build:
81n/a self.run_command('build')
82n/a
83n/a install = self.reinitialize_command('install', reinit_subcommands=1)
84n/a install.root = self.bdist_dir
85n/a install.skip_build = self.skip_build
86n/a install.warn_dir = 0
87n/a
88n/a log.info("installing to %s", self.bdist_dir)
89n/a self.run_command('install')
90n/a
91n/a # And make an archive relative to the root of the
92n/a # pseudo-installation tree.
93n/a archive_basename = "%s.%s" % (self.distribution.get_fullname(),
94n/a self.plat_name)
95n/a
96n/a pseudoinstall_root = os.path.join(self.dist_dir, archive_basename)
97n/a if not self.relative:
98n/a archive_root = self.bdist_dir
99n/a else:
100n/a if (self.distribution.has_ext_modules() and
101n/a (install.install_base != install.install_platbase)):
102n/a raise DistutilsPlatformError(
103n/a "can't make a dumb built distribution where "
104n/a "base and platbase are different (%s, %s)"
105n/a % (repr(install.install_base),
106n/a repr(install.install_platbase)))
107n/a else:
108n/a archive_root = os.path.join(self.bdist_dir,
109n/a ensure_relative(install.install_base))
110n/a
111n/a # Make the archive
112n/a filename = self.make_archive(pseudoinstall_root,
113n/a self.format, root_dir=archive_root,
114n/a owner=self.owner, group=self.group)
115n/a if self.distribution.has_ext_modules():
116n/a pyversion = get_python_version()
117n/a else:
118n/a pyversion = 'any'
119n/a self.distribution.dist_files.append(('bdist_dumb', pyversion,
120n/a filename))
121n/a
122n/a if not self.keep_temp:
123n/a remove_tree(self.bdist_dir, dry_run=self.dry_run)