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