Greg Ward | e1664bd | 2000-03-31 02:56:34 +0000 | [diff] [blame] | 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 | |
Greg Ward | e1664bd | 2000-03-31 02:56:34 +0000 | [diff] [blame] | 7 | __revision__ = "$Id$" |
| 8 | |
| 9 | import os |
| 10 | from distutils.core import Command |
Tarek Ziadé | 3679727 | 2010-07-22 12:50:05 +0000 | [diff] [blame^] | 11 | from distutils.util import get_platform |
Christian Heimes | 05e8be1 | 2008-02-23 18:30:17 +0000 | [diff] [blame] | 12 | from distutils.dir_util import remove_tree, ensure_relative |
Tarek Ziadé | 3679727 | 2010-07-22 12:50:05 +0000 | [diff] [blame^] | 13 | from distutils.errors import * |
| 14 | from distutils.sysconfig import get_python_version |
Jeremy Hylton | cd8a114 | 2002-06-04 20:14:43 +0000 | [diff] [blame] | 15 | from distutils import log |
Greg Ward | e1664bd | 2000-03-31 02:56:34 +0000 | [diff] [blame] | 16 | |
Collin Winter | 5b7e9d7 | 2007-08-30 03:52:21 +0000 | [diff] [blame] | 17 | class bdist_dumb(Command): |
Greg Ward | e1664bd | 2000-03-31 02:56:34 +0000 | [diff] [blame] | 18 | |
Tarek Ziadé | 3679727 | 2010-07-22 12:50:05 +0000 | [diff] [blame^] | 19 | description = "create a \"dumb\" built distribution" |
Greg Ward | e1664bd | 2000-03-31 02:56:34 +0000 | [diff] [blame] | 20 | |
Gregory P. Smith | ba0506b | 2000-05-13 03:06:56 +0000 | [diff] [blame] | 21 | user_options = [('bdist-dir=', 'd', |
| 22 | "temporary directory for creating the distribution"), |
Greg Ward | 20283e5 | 2000-09-11 00:47:35 +0000 | [diff] [blame] | 23 | ('plat-name=', 'p', |
| 24 | "platform name to embed in generated filenames " |
| 25 | "(default: %s)" % get_platform()), |
Gregory P. Smith | ba0506b | 2000-05-13 03:06:56 +0000 | [diff] [blame] | 26 | ('format=', 'f', |
Greg Ward | e1664bd | 2000-03-31 02:56:34 +0000 | [diff] [blame] | 27 | "archive format to create (tar, ztar, gztar, zip)"), |
Greg Ward | 8429036 | 2000-09-16 15:53:41 +0000 | [diff] [blame] | 28 | ('keep-temp', 'k', |
Greg Ward | b4c850c | 2000-03-31 05:22:47 +0000 | [diff] [blame] | 29 | "keep the pseudo-installation tree around after " + |
| 30 | "creating the distribution archive"), |
Greg Ward | c4eb84a | 2000-07-05 03:07:37 +0000 | [diff] [blame] | 31 | ('dist-dir=', 'd', |
| 32 | "directory to put final built distributions in"), |
Martin v. Löwis | 9668b93 | 2002-01-12 11:27:42 +0000 | [diff] [blame] | 33 | ('skip-build', None, |
| 34 | "skip rebuilding everything (for testing/debugging)"), |
Andrew M. Kuchling | acd5cb2 | 2002-11-26 17:45:19 +0000 | [diff] [blame] | 35 | ('relative', None, |
| 36 | "build the archive using relative paths" |
| 37 | "(default: false)"), |
Greg Ward | e1664bd | 2000-03-31 02:56:34 +0000 | [diff] [blame] | 38 | ] |
| 39 | |
Andrew M. Kuchling | acd5cb2 | 2002-11-26 17:45:19 +0000 | [diff] [blame] | 40 | boolean_options = ['keep-temp', 'skip-build', 'relative'] |
Greg Ward | 99b032e | 2000-09-25 01:41:15 +0000 | [diff] [blame] | 41 | |
Greg Ward | e1664bd | 2000-03-31 02:56:34 +0000 | [diff] [blame] | 42 | default_format = { 'posix': 'gztar', |
Marc-André Lemburg | 2544f51 | 2002-01-31 18:56:00 +0000 | [diff] [blame] | 43 | 'nt': 'zip', |
| 44 | 'os2': 'zip' } |
Greg Ward | e1664bd | 2000-03-31 02:56:34 +0000 | [diff] [blame] | 45 | |
Collin Winter | 5b7e9d7 | 2007-08-30 03:52:21 +0000 | [diff] [blame] | 46 | def initialize_options(self): |
Gregory P. Smith | ba0506b | 2000-05-13 03:06:56 +0000 | [diff] [blame] | 47 | self.bdist_dir = None |
Greg Ward | 20283e5 | 2000-09-11 00:47:35 +0000 | [diff] [blame] | 48 | self.plat_name = None |
Greg Ward | e1664bd | 2000-03-31 02:56:34 +0000 | [diff] [blame] | 49 | self.format = None |
Greg Ward | 8429036 | 2000-09-16 15:53:41 +0000 | [diff] [blame] | 50 | self.keep_temp = 0 |
Greg Ward | c4eb84a | 2000-07-05 03:07:37 +0000 | [diff] [blame] | 51 | self.dist_dir = None |
Martin v. Löwis | 9668b93 | 2002-01-12 11:27:42 +0000 | [diff] [blame] | 52 | self.skip_build = 0 |
Andrew M. Kuchling | acd5cb2 | 2002-11-26 17:45:19 +0000 | [diff] [blame] | 53 | self.relative = 0 |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 54 | |
Collin Winter | 5b7e9d7 | 2007-08-30 03:52:21 +0000 | [diff] [blame] | 55 | def finalize_options(self): |
Gregory P. Smith | ba0506b | 2000-05-13 03:06:56 +0000 | [diff] [blame] | 56 | if self.bdist_dir is None: |
Greg Ward | 4fb29e5 | 2000-05-27 17:27:23 +0000 | [diff] [blame] | 57 | bdist_base = self.get_finalized_command('bdist').bdist_base |
Gregory P. Smith | ba0506b | 2000-05-13 03:06:56 +0000 | [diff] [blame] | 58 | self.bdist_dir = os.path.join(bdist_base, 'dumb') |
| 59 | |
Greg Ward | e1664bd | 2000-03-31 02:56:34 +0000 | [diff] [blame] | 60 | if self.format is None: |
| 61 | try: |
| 62 | self.format = self.default_format[os.name] |
| 63 | except KeyError: |
Collin Winter | 5b7e9d7 | 2007-08-30 03:52:21 +0000 | [diff] [blame] | 64 | raise DistutilsPlatformError( |
| 65 | "don't know how to create dumb built distributions " |
| 66 | "on platform %s" % os.name) |
Greg Ward | e1664bd | 2000-03-31 02:56:34 +0000 | [diff] [blame] | 67 | |
Greg Ward | 20283e5 | 2000-09-11 00:47:35 +0000 | [diff] [blame] | 68 | self.set_undefined_options('bdist', |
| 69 | ('dist_dir', 'dist_dir'), |
| 70 | ('plat_name', 'plat_name')) |
Greg Ward | c4eb84a | 2000-07-05 03:07:37 +0000 | [diff] [blame] | 71 | |
Collin Winter | 5b7e9d7 | 2007-08-30 03:52:21 +0000 | [diff] [blame] | 72 | def run(self): |
Martin v. Löwis | 9668b93 | 2002-01-12 11:27:42 +0000 | [diff] [blame] | 73 | if not self.skip_build: |
| 74 | self.run_command('build') |
Greg Ward | e1664bd | 2000-03-31 02:56:34 +0000 | [diff] [blame] | 75 | |
Greg Ward | 24511d2 | 2000-09-16 15:30:47 +0000 | [diff] [blame] | 76 | install = self.reinitialize_command('install', reinit_subcommands=1) |
Gregory P. Smith | ba0506b | 2000-05-13 03:06:56 +0000 | [diff] [blame] | 77 | install.root = self.bdist_dir |
Martin v. Löwis | 9668b93 | 2002-01-12 11:27:42 +0000 | [diff] [blame] | 78 | install.skip_build = self.skip_build |
Thomas Heller | fd0e82a | 2002-04-09 14:14:38 +0000 | [diff] [blame] | 79 | install.warn_dir = 0 |
Greg Ward | e1664bd | 2000-03-31 02:56:34 +0000 | [diff] [blame] | 80 | |
Jeremy Hylton | cd8a114 | 2002-06-04 20:14:43 +0000 | [diff] [blame] | 81 | log.info("installing to %s" % self.bdist_dir) |
Greg Ward | 24511d2 | 2000-09-16 15:30:47 +0000 | [diff] [blame] | 82 | self.run_command('install') |
Greg Ward | e1664bd | 2000-03-31 02:56:34 +0000 | [diff] [blame] | 83 | |
| 84 | # And make an archive relative to the root of the |
| 85 | # pseudo-installation tree. |
Greg Ward | 0ae7f76 | 2000-04-22 02:51:25 +0000 | [diff] [blame] | 86 | archive_basename = "%s.%s" % (self.distribution.get_fullname(), |
Greg Ward | 20283e5 | 2000-09-11 00:47:35 +0000 | [diff] [blame] | 87 | self.plat_name) |
Marc-André Lemburg | 2544f51 | 2002-01-31 18:56:00 +0000 | [diff] [blame] | 88 | |
| 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. Kuchling | acd5cb2 | 2002-11-26 17:45:19 +0000 | [diff] [blame] | 94 | 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 Winter | 5b7e9d7 | 2007-08-30 03:52:21 +0000 | [diff] [blame] | 100 | raise DistutilsPlatformError( |
| 101 | "can't make a dumb built distribution where " |
Andrew M. Kuchling | acd5cb2 | 2002-11-26 17:45:19 +0000 | [diff] [blame] | 102 | "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öwis | 55f1bb8 | 2005-03-21 20:56:35 +0000 | [diff] [blame] | 110 | filename = self.make_archive(pseudoinstall_root, |
Tarek Ziadé | 3679727 | 2010-07-22 12:50:05 +0000 | [diff] [blame^] | 111 | self.format, root_dir=archive_root) |
Martin v. Löwis | 98da562 | 2005-03-23 18:54:36 +0000 | [diff] [blame] | 112 | 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 Ward | e1664bd | 2000-03-31 02:56:34 +0000 | [diff] [blame] | 118 | |
Greg Ward | 8429036 | 2000-09-16 15:53:41 +0000 | [diff] [blame] | 119 | if not self.keep_temp: |
Jeremy Hylton | cd8a114 | 2002-06-04 20:14:43 +0000 | [diff] [blame] | 120 | remove_tree(self.bdist_dir, dry_run=self.dry_run) |