blob: 3db332d5bd7893e24a470bd0932ef34ff4133c13 [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
Andrew M. Kuchlingd448f662002-11-19 13:12:28 +00007# This module should be kept compatible with Python 1.5.2.
8
Greg Warde1664bd2000-03-31 02:56:34 +00009__revision__ = "$Id$"
10
11import os
12from distutils.core import Command
Greg Wardab3a0f32000-08-05 01:31:54 +000013from distutils.util import get_platform
Andrew M. Kuchlingacd5cb22002-11-26 17:45:19 +000014from distutils.dir_util import create_tree, remove_tree, ensure_relative
Greg Ward6ce94b72000-04-26 02:29:51 +000015from distutils.errors import *
Jeremy Hyltoncd8a1142002-06-04 20:14:43 +000016from distutils import log
Greg Warde1664bd2000-03-31 02:56:34 +000017
18class bdist_dumb (Command):
19
20 description = "create a \"dumb\" built distribution"
21
Gregory P. Smithba0506b2000-05-13 03:06:56 +000022 user_options = [('bdist-dir=', 'd',
23 "temporary directory for creating the distribution"),
Greg Ward20283e52000-09-11 00:47:35 +000024 ('plat-name=', 'p',
25 "platform name to embed in generated filenames "
26 "(default: %s)" % get_platform()),
Gregory P. Smithba0506b2000-05-13 03:06:56 +000027 ('format=', 'f',
Greg Warde1664bd2000-03-31 02:56:34 +000028 "archive format to create (tar, ztar, gztar, zip)"),
Greg Ward84290362000-09-16 15:53:41 +000029 ('keep-temp', 'k',
Greg Wardb4c850c2000-03-31 05:22:47 +000030 "keep the pseudo-installation tree around after " +
31 "creating the distribution archive"),
Greg Wardc4eb84a2000-07-05 03:07:37 +000032 ('dist-dir=', 'd',
33 "directory to put final built distributions in"),
Martin v. Löwis9668b932002-01-12 11:27:42 +000034 ('skip-build', None,
35 "skip rebuilding everything (for testing/debugging)"),
Andrew M. Kuchlingacd5cb22002-11-26 17:45:19 +000036 ('relative', None,
37 "build the archive using relative paths"
38 "(default: false)"),
Greg Warde1664bd2000-03-31 02:56:34 +000039 ]
40
Andrew M. Kuchlingacd5cb22002-11-26 17:45:19 +000041 boolean_options = ['keep-temp', 'skip-build', 'relative']
Greg Ward99b032e2000-09-25 01:41:15 +000042
Greg Warde1664bd2000-03-31 02:56:34 +000043 default_format = { 'posix': 'gztar',
Marc-André Lemburg2544f512002-01-31 18:56:00 +000044 'nt': 'zip',
45 'os2': 'zip' }
Greg Warde1664bd2000-03-31 02:56:34 +000046
47
48 def initialize_options (self):
Gregory P. Smithba0506b2000-05-13 03:06:56 +000049 self.bdist_dir = None
Greg Ward20283e52000-09-11 00:47:35 +000050 self.plat_name = None
Greg Warde1664bd2000-03-31 02:56:34 +000051 self.format = None
Greg Ward84290362000-09-16 15:53:41 +000052 self.keep_temp = 0
Greg Wardc4eb84a2000-07-05 03:07:37 +000053 self.dist_dir = None
Martin v. Löwis9668b932002-01-12 11:27:42 +000054 self.skip_build = 0
Andrew M. Kuchlingacd5cb22002-11-26 17:45:19 +000055 self.relative = 0
Tim Peters182b5ac2004-07-18 06:16:08 +000056
Greg Warde1664bd2000-03-31 02:56:34 +000057 # initialize_options()
58
59
60 def finalize_options (self):
Greg Ward20283e52000-09-11 00:47:35 +000061
Gregory P. Smithba0506b2000-05-13 03:06:56 +000062 if self.bdist_dir is None:
Greg Ward4fb29e52000-05-27 17:27:23 +000063 bdist_base = self.get_finalized_command('bdist').bdist_base
Gregory P. Smithba0506b2000-05-13 03:06:56 +000064 self.bdist_dir = os.path.join(bdist_base, 'dumb')
65
Greg Warde1664bd2000-03-31 02:56:34 +000066 if self.format is None:
67 try:
68 self.format = self.default_format[os.name]
69 except KeyError:
70 raise DistutilsPlatformError, \
71 ("don't know how to create dumb built distributions " +
72 "on platform %s") % os.name
73
Greg Ward20283e52000-09-11 00:47:35 +000074 self.set_undefined_options('bdist',
75 ('dist_dir', 'dist_dir'),
76 ('plat_name', 'plat_name'))
Greg Wardc4eb84a2000-07-05 03:07:37 +000077
Greg Warde1664bd2000-03-31 02:56:34 +000078 # finalize_options()
79
80
81 def run (self):
82
Martin v. Löwis9668b932002-01-12 11:27:42 +000083 if not self.skip_build:
84 self.run_command('build')
Greg Warde1664bd2000-03-31 02:56:34 +000085
Greg Ward24511d22000-09-16 15:30:47 +000086 install = self.reinitialize_command('install', reinit_subcommands=1)
Gregory P. Smithba0506b2000-05-13 03:06:56 +000087 install.root = self.bdist_dir
Martin v. Löwis9668b932002-01-12 11:27:42 +000088 install.skip_build = self.skip_build
Thomas Hellerfd0e82a2002-04-09 14:14:38 +000089 install.warn_dir = 0
Greg Warde1664bd2000-03-31 02:56:34 +000090
Jeremy Hyltoncd8a1142002-06-04 20:14:43 +000091 log.info("installing to %s" % self.bdist_dir)
Greg Ward24511d22000-09-16 15:30:47 +000092 self.run_command('install')
Greg Warde1664bd2000-03-31 02:56:34 +000093
94 # And make an archive relative to the root of the
95 # pseudo-installation tree.
Greg Ward0ae7f762000-04-22 02:51:25 +000096 archive_basename = "%s.%s" % (self.distribution.get_fullname(),
Greg Ward20283e52000-09-11 00:47:35 +000097 self.plat_name)
Marc-André Lemburg2544f512002-01-31 18:56:00 +000098
99 # OS/2 objects to any ":" characters in a filename (such as when
100 # a timestamp is used in a version) so change them to hyphens.
101 if os.name == "os2":
102 archive_basename = archive_basename.replace(":", "-")
103
Andrew M. Kuchlingacd5cb22002-11-26 17:45:19 +0000104 pseudoinstall_root = os.path.join(self.dist_dir, archive_basename)
105 if not self.relative:
106 archive_root = self.bdist_dir
107 else:
108 if (self.distribution.has_ext_modules() and
109 (install.install_base != install.install_platbase)):
110 raise DistutilsPlatformError, \
111 ("can't make a dumb built distribution where "
112 "base and platbase are different (%s, %s)"
113 % (repr(install.install_base),
114 repr(install.install_platbase)))
115 else:
116 archive_root = os.path.join(self.bdist_dir,
117 ensure_relative(install.install_base))
118
119 # Make the archive
120 self.make_archive(pseudoinstall_root,
121 self.format, root_dir=archive_root)
Greg Warde1664bd2000-03-31 02:56:34 +0000122
Greg Ward84290362000-09-16 15:53:41 +0000123 if not self.keep_temp:
Jeremy Hyltoncd8a1142002-06-04 20:14:43 +0000124 remove_tree(self.bdist_dir, dry_run=self.dry_run)
Greg Wardb4c850c2000-03-31 05:22:47 +0000125
Greg Warde1664bd2000-03-31 02:56:34 +0000126 # run()
127
Greg Warde1664bd2000-03-31 02:56:34 +0000128# class bdist_dumb