bdist_dumb.py 4.76 KB
Newer Older
1 2 3 4 5 6 7 8
"""distutils.command.bdist_dumb

Implements the Distutils 'bdist_dumb' command (create a "dumb" built
distribution -- i.e., just an archive to be unpacked under $prefix or
$exec_prefix)."""

import os
from distutils.core import Command
9
from distutils.util import get_platform
10
from distutils.dir_util import remove_tree, ensure_relative
11 12
from distutils.errors import *
from distutils.sysconfig import get_python_version
13
from distutils import log
14

15
class bdist_dumb(Command):
16

17
    description = "create a \"dumb\" built distribution"
18

19 20
    user_options = [('bdist-dir=', 'd',
                     "temporary directory for creating the distribution"),
21 22 23
                    ('plat-name=', 'p',
                     "platform name to embed in generated filenames "
                     "(default: %s)" % get_platform()),
24
                    ('format=', 'f',
25
                     "archive format to create (tar, ztar, gztar, zip)"),
26
                    ('keep-temp', 'k',
27 28
                     "keep the pseudo-installation tree around after " +
                     "creating the distribution archive"),
29 30
                    ('dist-dir=', 'd',
                     "directory to put final built distributions in"),
31 32
                    ('skip-build', None,
                     "skip rebuilding everything (for testing/debugging)"),
33 34 35
                    ('relative', None,
                     "build the archive using relative paths"
                     "(default: false)"),
36 37 38 39 40 41
                    ('owner=', 'u',
                     "Owner name used when creating a tar file"
                     " [default: current user]"),
                    ('group=', 'g',
                     "Group name used when creating a tar file"
                     " [default: current group]"),
42 43
                   ]

44
    boolean_options = ['keep-temp', 'skip-build', 'relative']
45

46
    default_format = { 'posix': 'gztar',
47
                       'nt': 'zip' }
48

49
    def initialize_options(self):
50
        self.bdist_dir = None
51
        self.plat_name = None
52
        self.format = None
53
        self.keep_temp = 0
54
        self.dist_dir = None
55
        self.skip_build = None
56
        self.relative = 0
57 58
        self.owner = None
        self.group = None
59

60
    def finalize_options(self):
61
        if self.bdist_dir is None:
62
            bdist_base = self.get_finalized_command('bdist').bdist_base
63 64
            self.bdist_dir = os.path.join(bdist_base, 'dumb')

65 66 67 68
        if self.format is None:
            try:
                self.format = self.default_format[os.name]
            except KeyError:
69 70 71
                raise DistutilsPlatformError(
                       "don't know how to create dumb built distributions "
                       "on platform %s" % os.name)
72

73 74
        self.set_undefined_options('bdist',
                                   ('dist_dir', 'dist_dir'),
75 76
                                   ('plat_name', 'plat_name'),
                                   ('skip_build', 'skip_build'))
77

78
    def run(self):
79 80
        if not self.skip_build:
            self.run_command('build')
81

82
        install = self.reinitialize_command('install', reinit_subcommands=1)
83
        install.root = self.bdist_dir
84
        install.skip_build = self.skip_build
85
        install.warn_dir = 0
86

87
        log.info("installing to %s" % self.bdist_dir)
88
        self.run_command('install')
89 90 91

        # And make an archive relative to the root of the
        # pseudo-installation tree.
92
        archive_basename = "%s.%s" % (self.distribution.get_fullname(),
93
                                      self.plat_name)
94

95 96 97 98 99 100
        pseudoinstall_root = os.path.join(self.dist_dir, archive_basename)
        if not self.relative:
            archive_root = self.bdist_dir
        else:
            if (self.distribution.has_ext_modules() and
                (install.install_base != install.install_platbase)):
101 102
                raise DistutilsPlatformError(
                       "can't make a dumb built distribution where "
103 104 105 106 107 108 109 110
                       "base and platbase are different (%s, %s)"
                       % (repr(install.install_base),
                          repr(install.install_platbase)))
            else:
                archive_root = os.path.join(self.bdist_dir,
                                   ensure_relative(install.install_base))

        # Make the archive
111
        filename = self.make_archive(pseudoinstall_root,
112 113
                                     self.format, root_dir=archive_root,
                                     owner=self.owner, group=self.group)
114 115 116 117 118 119
        if self.distribution.has_ext_modules():
            pyversion = get_python_version()
        else:
            pyversion = 'any'
        self.distribution.dist_files.append(('bdist_dumb', pyversion,
                                             filename))
120

121
        if not self.keep_temp:
122
            remove_tree(self.bdist_dir, dry_run=self.dry_run)