blob: eefdfea5ad3e6a19417fa0147878a9c27b8a450c [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 +00007import os
8from distutils.core import Command
Tarek Ziadé36797272010-07-22 12:50:05 +00009from distutils.util import get_platform
Christian Heimes05e8be12008-02-23 18:30:17 +000010from distutils.dir_util import remove_tree, ensure_relative
Tarek Ziadé36797272010-07-22 12:50:05 +000011from distutils.errors import *
12from distutils.sysconfig import get_python_version
Jeremy Hyltoncd8a1142002-06-04 20:14:43 +000013from distutils import log
Greg Warde1664bd2000-03-31 02:56:34 +000014
Collin Winter5b7e9d72007-08-30 03:52:21 +000015class bdist_dumb(Command):
Greg Warde1664bd2000-03-31 02:56:34 +000016
Tarek Ziadé36797272010-07-22 12:50:05 +000017 description = "create a \"dumb\" built distribution"
Greg Warde1664bd2000-03-31 02:56:34 +000018
Gregory P. Smithba0506b2000-05-13 03:06:56 +000019 user_options = [('bdist-dir=', 'd',
20 "temporary directory for creating the distribution"),
Greg Ward20283e52000-09-11 00:47:35 +000021 ('plat-name=', 'p',
22 "platform name to embed in generated filenames "
23 "(default: %s)" % get_platform()),
Gregory P. Smithba0506b2000-05-13 03:06:56 +000024 ('format=', 'f',
Greg Warde1664bd2000-03-31 02:56:34 +000025 "archive format to create (tar, ztar, gztar, zip)"),
Greg Ward84290362000-09-16 15:53:41 +000026 ('keep-temp', 'k',
Greg Wardb4c850c2000-03-31 05:22:47 +000027 "keep the pseudo-installation tree around after " +
28 "creating the distribution archive"),
Greg Wardc4eb84a2000-07-05 03:07:37 +000029 ('dist-dir=', 'd',
30 "directory to put final built distributions in"),
Martin v. Löwis9668b932002-01-12 11:27:42 +000031 ('skip-build', None,
32 "skip rebuilding everything (for testing/debugging)"),
Andrew M. Kuchlingacd5cb22002-11-26 17:45:19 +000033 ('relative', None,
34 "build the archive using relative paths"
35 "(default: false)"),
Greg Warde1664bd2000-03-31 02:56:34 +000036 ]
37
Andrew M. Kuchlingacd5cb22002-11-26 17:45:19 +000038 boolean_options = ['keep-temp', 'skip-build', 'relative']
Greg Ward99b032e2000-09-25 01:41:15 +000039
Greg Warde1664bd2000-03-31 02:56:34 +000040 default_format = { 'posix': 'gztar',
Jesus Cead17833d2012-10-11 01:20:12 +020041 'nt': 'zip' }
Greg Warde1664bd2000-03-31 02:56:34 +000042
Collin Winter5b7e9d72007-08-30 03:52:21 +000043 def initialize_options(self):
Gregory P. Smithba0506b2000-05-13 03:06:56 +000044 self.bdist_dir = None
Greg Ward20283e52000-09-11 00:47:35 +000045 self.plat_name = None
Greg Warde1664bd2000-03-31 02:56:34 +000046 self.format = None
Greg Ward84290362000-09-16 15:53:41 +000047 self.keep_temp = 0
Greg Wardc4eb84a2000-07-05 03:07:37 +000048 self.dist_dir = None
Éric Araujofbe37df2011-08-29 21:48:39 +020049 self.skip_build = None
Andrew M. Kuchlingacd5cb22002-11-26 17:45:19 +000050 self.relative = 0
Tim Peters182b5ac2004-07-18 06:16:08 +000051
Collin Winter5b7e9d72007-08-30 03:52:21 +000052 def finalize_options(self):
Gregory P. Smithba0506b2000-05-13 03:06:56 +000053 if self.bdist_dir is None:
Greg Ward4fb29e52000-05-27 17:27:23 +000054 bdist_base = self.get_finalized_command('bdist').bdist_base
Gregory P. Smithba0506b2000-05-13 03:06:56 +000055 self.bdist_dir = os.path.join(bdist_base, 'dumb')
56
Greg Warde1664bd2000-03-31 02:56:34 +000057 if self.format is None:
58 try:
59 self.format = self.default_format[os.name]
60 except KeyError:
Collin Winter5b7e9d72007-08-30 03:52:21 +000061 raise DistutilsPlatformError(
62 "don't know how to create dumb built distributions "
63 "on platform %s" % os.name)
Greg Warde1664bd2000-03-31 02:56:34 +000064
Greg Ward20283e52000-09-11 00:47:35 +000065 self.set_undefined_options('bdist',
66 ('dist_dir', 'dist_dir'),
Éric Araujofbe37df2011-08-29 21:48:39 +020067 ('plat_name', 'plat_name'),
68 ('skip_build', 'skip_build'))
Greg Wardc4eb84a2000-07-05 03:07:37 +000069
Collin Winter5b7e9d72007-08-30 03:52:21 +000070 def run(self):
Martin v. Löwis9668b932002-01-12 11:27:42 +000071 if not self.skip_build:
72 self.run_command('build')
Greg Warde1664bd2000-03-31 02:56:34 +000073
Greg Ward24511d22000-09-16 15:30:47 +000074 install = self.reinitialize_command('install', reinit_subcommands=1)
Gregory P. Smithba0506b2000-05-13 03:06:56 +000075 install.root = self.bdist_dir
Martin v. Löwis9668b932002-01-12 11:27:42 +000076 install.skip_build = self.skip_build
Thomas Hellerfd0e82a2002-04-09 14:14:38 +000077 install.warn_dir = 0
Greg Warde1664bd2000-03-31 02:56:34 +000078
Jeremy Hyltoncd8a1142002-06-04 20:14:43 +000079 log.info("installing to %s" % self.bdist_dir)
Greg Ward24511d22000-09-16 15:30:47 +000080 self.run_command('install')
Greg Warde1664bd2000-03-31 02:56:34 +000081
82 # And make an archive relative to the root of the
83 # pseudo-installation tree.
Greg Ward0ae7f762000-04-22 02:51:25 +000084 archive_basename = "%s.%s" % (self.distribution.get_fullname(),
Greg Ward20283e52000-09-11 00:47:35 +000085 self.plat_name)
Marc-André Lemburg2544f512002-01-31 18:56:00 +000086
Andrew M. Kuchlingacd5cb22002-11-26 17:45:19 +000087 pseudoinstall_root = os.path.join(self.dist_dir, archive_basename)
88 if not self.relative:
89 archive_root = self.bdist_dir
90 else:
91 if (self.distribution.has_ext_modules() and
92 (install.install_base != install.install_platbase)):
Collin Winter5b7e9d72007-08-30 03:52:21 +000093 raise DistutilsPlatformError(
94 "can't make a dumb built distribution where "
Andrew M. Kuchlingacd5cb22002-11-26 17:45:19 +000095 "base and platbase are different (%s, %s)"
96 % (repr(install.install_base),
97 repr(install.install_platbase)))
98 else:
99 archive_root = os.path.join(self.bdist_dir,
100 ensure_relative(install.install_base))
101
102 # Make the archive
Martin v. Löwis55f1bb82005-03-21 20:56:35 +0000103 filename = self.make_archive(pseudoinstall_root,
Tarek Ziadé36797272010-07-22 12:50:05 +0000104 self.format, root_dir=archive_root)
Martin v. Löwis98da5622005-03-23 18:54:36 +0000105 if self.distribution.has_ext_modules():
106 pyversion = get_python_version()
107 else:
108 pyversion = 'any'
109 self.distribution.dist_files.append(('bdist_dumb', pyversion,
110 filename))
Greg Warde1664bd2000-03-31 02:56:34 +0000111
Greg Ward84290362000-09-16 15:53:41 +0000112 if not self.keep_temp:
Jeremy Hyltoncd8a1142002-06-04 20:14:43 +0000113 remove_tree(self.bdist_dir, dry_run=self.dry_run)