blob: 2d39922672c59c65ed37461b183a61c31b499464 [file] [log] [blame]
Greg Warde1664bd2000-03-31 02:56:34 +00001"""distutils.command.bdist_dumb
2
3Implements the Distutils 'bdist_dumb' command (create a "dumb" built
4distribution -- i.e., just an archive to be unpacked under $prefix or
5$exec_prefix)."""
6
Greg Warde1664bd2000-03-31 02:56:34 +00007__revision__ = "$Id$"
8
9import os
10from distutils.core import Command
Tarek Ziadé36797272010-07-22 12:50:05 +000011from distutils.util import get_platform
Christian Heimes05e8be12008-02-23 18:30:17 +000012from distutils.dir_util import remove_tree, ensure_relative
Tarek Ziadé36797272010-07-22 12:50:05 +000013from distutils.errors import *
14from distutils.sysconfig import get_python_version
Jeremy Hyltoncd8a1142002-06-04 20:14:43 +000015from distutils import log
Greg Warde1664bd2000-03-31 02:56:34 +000016
Collin Winter5b7e9d72007-08-30 03:52:21 +000017class bdist_dumb(Command):
Greg Warde1664bd2000-03-31 02:56:34 +000018
Tarek Ziadé36797272010-07-22 12:50:05 +000019 description = "create a \"dumb\" built distribution"
Greg Warde1664bd2000-03-31 02:56:34 +000020
Gregory P. Smithba0506b2000-05-13 03:06:56 +000021 user_options = [('bdist-dir=', 'd',
22 "temporary directory for creating the distribution"),
Greg Ward20283e52000-09-11 00:47:35 +000023 ('plat-name=', 'p',
24 "platform name to embed in generated filenames "
25 "(default: %s)" % get_platform()),
Gregory P. Smithba0506b2000-05-13 03:06:56 +000026 ('format=', 'f',
Greg Warde1664bd2000-03-31 02:56:34 +000027 "archive format to create (tar, ztar, gztar, zip)"),
Greg Ward84290362000-09-16 15:53:41 +000028 ('keep-temp', 'k',
Greg Wardb4c850c2000-03-31 05:22:47 +000029 "keep the pseudo-installation tree around after " +
30 "creating the distribution archive"),
Greg Wardc4eb84a2000-07-05 03:07:37 +000031 ('dist-dir=', 'd',
32 "directory to put final built distributions in"),
Martin v. Löwis9668b932002-01-12 11:27:42 +000033 ('skip-build', None,
34 "skip rebuilding everything (for testing/debugging)"),
Andrew M. Kuchlingacd5cb22002-11-26 17:45:19 +000035 ('relative', None,
36 "build the archive using relative paths"
37 "(default: false)"),
Greg Warde1664bd2000-03-31 02:56:34 +000038 ]
39
Andrew M. Kuchlingacd5cb22002-11-26 17:45:19 +000040 boolean_options = ['keep-temp', 'skip-build', 'relative']
Greg Ward99b032e2000-09-25 01:41:15 +000041
Greg Warde1664bd2000-03-31 02:56:34 +000042 default_format = { 'posix': 'gztar',
Marc-André Lemburg2544f512002-01-31 18:56:00 +000043 'nt': 'zip',
44 'os2': 'zip' }
Greg Warde1664bd2000-03-31 02:56:34 +000045
Collin Winter5b7e9d72007-08-30 03:52:21 +000046 def initialize_options(self):
Gregory P. Smithba0506b2000-05-13 03:06:56 +000047 self.bdist_dir = None
Greg Ward20283e52000-09-11 00:47:35 +000048 self.plat_name = None
Greg Warde1664bd2000-03-31 02:56:34 +000049 self.format = None
Greg Ward84290362000-09-16 15:53:41 +000050 self.keep_temp = 0
Greg Wardc4eb84a2000-07-05 03:07:37 +000051 self.dist_dir = None
Martin v. Löwis9668b932002-01-12 11:27:42 +000052 self.skip_build = 0
Andrew M. Kuchlingacd5cb22002-11-26 17:45:19 +000053 self.relative = 0
Tim Peters182b5ac2004-07-18 06:16:08 +000054
Collin Winter5b7e9d72007-08-30 03:52:21 +000055 def finalize_options(self):
Gregory P. Smithba0506b2000-05-13 03:06:56 +000056 if self.bdist_dir is None:
Greg Ward4fb29e52000-05-27 17:27:23 +000057 bdist_base = self.get_finalized_command('bdist').bdist_base
Gregory P. Smithba0506b2000-05-13 03:06:56 +000058 self.bdist_dir = os.path.join(bdist_base, 'dumb')
59
Greg Warde1664bd2000-03-31 02:56:34 +000060 if self.format is None:
61 try:
62 self.format = self.default_format[os.name]
63 except KeyError:
Collin Winter5b7e9d72007-08-30 03:52:21 +000064 raise DistutilsPlatformError(
65 "don't know how to create dumb built distributions "
66 "on platform %s" % os.name)
Greg Warde1664bd2000-03-31 02:56:34 +000067
Greg Ward20283e52000-09-11 00:47:35 +000068 self.set_undefined_options('bdist',
69 ('dist_dir', 'dist_dir'),
70 ('plat_name', 'plat_name'))
Greg Wardc4eb84a2000-07-05 03:07:37 +000071
Collin Winter5b7e9d72007-08-30 03:52:21 +000072 def run(self):
Martin v. Löwis9668b932002-01-12 11:27:42 +000073 if not self.skip_build:
74 self.run_command('build')
Greg Warde1664bd2000-03-31 02:56:34 +000075
Greg Ward24511d22000-09-16 15:30:47 +000076 install = self.reinitialize_command('install', reinit_subcommands=1)
Gregory P. Smithba0506b2000-05-13 03:06:56 +000077 install.root = self.bdist_dir
Martin v. Löwis9668b932002-01-12 11:27:42 +000078 install.skip_build = self.skip_build
Thomas Hellerfd0e82a2002-04-09 14:14:38 +000079 install.warn_dir = 0
Greg Warde1664bd2000-03-31 02:56:34 +000080
Jeremy Hyltoncd8a1142002-06-04 20:14:43 +000081 log.info("installing to %s" % self.bdist_dir)
Greg Ward24511d22000-09-16 15:30:47 +000082 self.run_command('install')
Greg Warde1664bd2000-03-31 02:56:34 +000083
84 # And make an archive relative to the root of the
85 # pseudo-installation tree.
Greg Ward0ae7f762000-04-22 02:51:25 +000086 archive_basename = "%s.%s" % (self.distribution.get_fullname(),
Greg Ward20283e52000-09-11 00:47:35 +000087 self.plat_name)
Marc-André Lemburg2544f512002-01-31 18:56:00 +000088
89 # OS/2 objects to any ":" characters in a filename (such as when
90 # a timestamp is used in a version) so change them to hyphens.
91 if os.name == "os2":
92 archive_basename = archive_basename.replace(":", "-")
93
Andrew M. Kuchlingacd5cb22002-11-26 17:45:19 +000094 pseudoinstall_root = os.path.join(self.dist_dir, archive_basename)
95 if not self.relative:
96 archive_root = self.bdist_dir
97 else:
98 if (self.distribution.has_ext_modules() and
99 (install.install_base != install.install_platbase)):
Collin Winter5b7e9d72007-08-30 03:52:21 +0000100 raise DistutilsPlatformError(
101 "can't make a dumb built distribution where "
Andrew M. Kuchlingacd5cb22002-11-26 17:45:19 +0000102 "base and platbase are different (%s, %s)"
103 % (repr(install.install_base),
104 repr(install.install_platbase)))
105 else:
106 archive_root = os.path.join(self.bdist_dir,
107 ensure_relative(install.install_base))
108
109 # Make the archive
Martin v. Löwis55f1bb82005-03-21 20:56:35 +0000110 filename = self.make_archive(pseudoinstall_root,
Tarek Ziadé36797272010-07-22 12:50:05 +0000111 self.format, root_dir=archive_root)
Martin v. Löwis98da5622005-03-23 18:54:36 +0000112 if self.distribution.has_ext_modules():
113 pyversion = get_python_version()
114 else:
115 pyversion = 'any'
116 self.distribution.dist_files.append(('bdist_dumb', pyversion,
117 filename))
Greg Warde1664bd2000-03-31 02:56:34 +0000118
Greg Ward84290362000-09-16 15:53:41 +0000119 if not self.keep_temp:
Jeremy Hyltoncd8a1142002-06-04 20:14:43 +0000120 remove_tree(self.bdist_dir, dry_run=self.dry_run)