Fixed #1885: --formats=tar,gztar was not working properly in the sdist command
[python.git] / Lib / distutils / command / bdist_dumb.py
blob7324c6c2faa712ffd33126bc055374cf64666c5c
1 """distutils.command.bdist_dumb
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)."""
7 __revision__ = "$Id$"
9 import os
10 from distutils.core import Command
11 from distutils.util import get_platform
12 from distutils.dir_util import remove_tree, ensure_relative
13 from distutils.errors import *
14 from distutils.sysconfig import get_python_version
15 from distutils import log
17 class bdist_dumb (Command):
19 description = "create a \"dumb\" built distribution"
21 user_options = [('bdist-dir=', 'd',
22 "temporary directory for creating the distribution"),
23 ('plat-name=', 'p',
24 "platform name to embed in generated filenames "
25 "(default: %s)" % get_platform()),
26 ('format=', 'f',
27 "archive format to create (tar, ztar, gztar, zip)"),
28 ('keep-temp', 'k',
29 "keep the pseudo-installation tree around after " +
30 "creating the distribution archive"),
31 ('dist-dir=', 'd',
32 "directory to put final built distributions in"),
33 ('skip-build', None,
34 "skip rebuilding everything (for testing/debugging)"),
35 ('relative', None,
36 "build the archive using relative paths"
37 "(default: false)"),
40 boolean_options = ['keep-temp', 'skip-build', 'relative']
42 default_format = { 'posix': 'gztar',
43 'nt': 'zip',
44 'os2': 'zip' }
47 def initialize_options (self):
48 self.bdist_dir = None
49 self.plat_name = None
50 self.format = None
51 self.keep_temp = 0
52 self.dist_dir = None
53 self.skip_build = 0
54 self.relative = 0
56 # initialize_options()
59 def finalize_options (self):
61 if self.bdist_dir is None:
62 bdist_base = self.get_finalized_command('bdist').bdist_base
63 self.bdist_dir = os.path.join(bdist_base, 'dumb')
65 if self.format is None:
66 try:
67 self.format = self.default_format[os.name]
68 except KeyError:
69 raise DistutilsPlatformError, \
70 ("don't know how to create dumb built distributions " +
71 "on platform %s") % os.name
73 self.set_undefined_options('bdist',
74 ('dist_dir', 'dist_dir'),
75 ('plat_name', 'plat_name'))
77 # finalize_options()
80 def run (self):
82 if not self.skip_build:
83 self.run_command('build')
85 install = self.reinitialize_command('install', reinit_subcommands=1)
86 install.root = self.bdist_dir
87 install.skip_build = self.skip_build
88 install.warn_dir = 0
90 log.info("installing to %s" % self.bdist_dir)
91 self.run_command('install')
93 # And make an archive relative to the root of the
94 # pseudo-installation tree.
95 archive_basename = "%s.%s" % (self.distribution.get_fullname(),
96 self.plat_name)
98 # OS/2 objects to any ":" characters in a filename (such as when
99 # a timestamp is used in a version) so change them to hyphens.
100 if os.name == "os2":
101 archive_basename = archive_basename.replace(":", "-")
103 pseudoinstall_root = os.path.join(self.dist_dir, archive_basename)
104 if not self.relative:
105 archive_root = self.bdist_dir
106 else:
107 if (self.distribution.has_ext_modules() and
108 (install.install_base != install.install_platbase)):
109 raise DistutilsPlatformError, \
110 ("can't make a dumb built distribution where "
111 "base and platbase are different (%s, %s)"
112 % (repr(install.install_base),
113 repr(install.install_platbase)))
114 else:
115 archive_root = os.path.join(self.bdist_dir,
116 ensure_relative(install.install_base))
118 # Make the archive
119 filename = self.make_archive(pseudoinstall_root,
120 self.format, root_dir=archive_root)
121 if self.distribution.has_ext_modules():
122 pyversion = get_python_version()
123 else:
124 pyversion = 'any'
125 self.distribution.dist_files.append(('bdist_dumb', pyversion,
126 filename))
128 if not self.keep_temp:
129 remove_tree(self.bdist_dir, dry_run=self.dry_run)
131 # run()
133 # class bdist_dumb