1 | n/a | """distutils.command.bdist_dumb |
---|
2 | n/a | |
---|
3 | n/a | Implements the Distutils 'bdist_dumb' command (create a "dumb" built |
---|
4 | n/a | distribution -- i.e., just an archive to be unpacked under $prefix or |
---|
5 | n/a | $exec_prefix).""" |
---|
6 | n/a | |
---|
7 | n/a | import os |
---|
8 | n/a | from distutils.core import Command |
---|
9 | n/a | from distutils.util import get_platform |
---|
10 | n/a | from distutils.dir_util import remove_tree, ensure_relative |
---|
11 | n/a | from distutils.errors import * |
---|
12 | n/a | from distutils.sysconfig import get_python_version |
---|
13 | n/a | from distutils import log |
---|
14 | n/a | |
---|
15 | n/a | class bdist_dumb(Command): |
---|
16 | n/a | |
---|
17 | n/a | description = "create a \"dumb\" built distribution" |
---|
18 | n/a | |
---|
19 | n/a | user_options = [('bdist-dir=', 'd', |
---|
20 | n/a | "temporary directory for creating the distribution"), |
---|
21 | n/a | ('plat-name=', 'p', |
---|
22 | n/a | "platform name to embed in generated filenames " |
---|
23 | n/a | "(default: %s)" % get_platform()), |
---|
24 | n/a | ('format=', 'f', |
---|
25 | n/a | "archive format to create (tar, gztar, bztar, xztar, " |
---|
26 | n/a | "ztar, zip)"), |
---|
27 | n/a | ('keep-temp', 'k', |
---|
28 | n/a | "keep the pseudo-installation tree around after " + |
---|
29 | n/a | "creating the distribution archive"), |
---|
30 | n/a | ('dist-dir=', 'd', |
---|
31 | n/a | "directory to put final built distributions in"), |
---|
32 | n/a | ('skip-build', None, |
---|
33 | n/a | "skip rebuilding everything (for testing/debugging)"), |
---|
34 | n/a | ('relative', None, |
---|
35 | n/a | "build the archive using relative paths" |
---|
36 | n/a | "(default: false)"), |
---|
37 | n/a | ('owner=', 'u', |
---|
38 | n/a | "Owner name used when creating a tar file" |
---|
39 | n/a | " [default: current user]"), |
---|
40 | n/a | ('group=', 'g', |
---|
41 | n/a | "Group name used when creating a tar file" |
---|
42 | n/a | " [default: current group]"), |
---|
43 | n/a | ] |
---|
44 | n/a | |
---|
45 | n/a | boolean_options = ['keep-temp', 'skip-build', 'relative'] |
---|
46 | n/a | |
---|
47 | n/a | default_format = { 'posix': 'gztar', |
---|
48 | n/a | 'nt': 'zip' } |
---|
49 | n/a | |
---|
50 | n/a | def initialize_options(self): |
---|
51 | n/a | self.bdist_dir = None |
---|
52 | n/a | self.plat_name = None |
---|
53 | n/a | self.format = None |
---|
54 | n/a | self.keep_temp = 0 |
---|
55 | n/a | self.dist_dir = None |
---|
56 | n/a | self.skip_build = None |
---|
57 | n/a | self.relative = 0 |
---|
58 | n/a | self.owner = None |
---|
59 | n/a | self.group = None |
---|
60 | n/a | |
---|
61 | n/a | def finalize_options(self): |
---|
62 | n/a | if self.bdist_dir is None: |
---|
63 | n/a | bdist_base = self.get_finalized_command('bdist').bdist_base |
---|
64 | n/a | self.bdist_dir = os.path.join(bdist_base, 'dumb') |
---|
65 | n/a | |
---|
66 | n/a | if self.format is None: |
---|
67 | n/a | try: |
---|
68 | n/a | self.format = self.default_format[os.name] |
---|
69 | n/a | except KeyError: |
---|
70 | n/a | raise DistutilsPlatformError( |
---|
71 | n/a | "don't know how to create dumb built distributions " |
---|
72 | n/a | "on platform %s" % os.name) |
---|
73 | n/a | |
---|
74 | n/a | self.set_undefined_options('bdist', |
---|
75 | n/a | ('dist_dir', 'dist_dir'), |
---|
76 | n/a | ('plat_name', 'plat_name'), |
---|
77 | n/a | ('skip_build', 'skip_build')) |
---|
78 | n/a | |
---|
79 | n/a | def run(self): |
---|
80 | n/a | if not self.skip_build: |
---|
81 | n/a | self.run_command('build') |
---|
82 | n/a | |
---|
83 | n/a | install = self.reinitialize_command('install', reinit_subcommands=1) |
---|
84 | n/a | install.root = self.bdist_dir |
---|
85 | n/a | install.skip_build = self.skip_build |
---|
86 | n/a | install.warn_dir = 0 |
---|
87 | n/a | |
---|
88 | n/a | log.info("installing to %s", self.bdist_dir) |
---|
89 | n/a | self.run_command('install') |
---|
90 | n/a | |
---|
91 | n/a | # And make an archive relative to the root of the |
---|
92 | n/a | # pseudo-installation tree. |
---|
93 | n/a | archive_basename = "%s.%s" % (self.distribution.get_fullname(), |
---|
94 | n/a | self.plat_name) |
---|
95 | n/a | |
---|
96 | n/a | pseudoinstall_root = os.path.join(self.dist_dir, archive_basename) |
---|
97 | n/a | if not self.relative: |
---|
98 | n/a | archive_root = self.bdist_dir |
---|
99 | n/a | else: |
---|
100 | n/a | if (self.distribution.has_ext_modules() and |
---|
101 | n/a | (install.install_base != install.install_platbase)): |
---|
102 | n/a | raise DistutilsPlatformError( |
---|
103 | n/a | "can't make a dumb built distribution where " |
---|
104 | n/a | "base and platbase are different (%s, %s)" |
---|
105 | n/a | % (repr(install.install_base), |
---|
106 | n/a | repr(install.install_platbase))) |
---|
107 | n/a | else: |
---|
108 | n/a | archive_root = os.path.join(self.bdist_dir, |
---|
109 | n/a | ensure_relative(install.install_base)) |
---|
110 | n/a | |
---|
111 | n/a | # Make the archive |
---|
112 | n/a | filename = self.make_archive(pseudoinstall_root, |
---|
113 | n/a | self.format, root_dir=archive_root, |
---|
114 | n/a | owner=self.owner, group=self.group) |
---|
115 | n/a | if self.distribution.has_ext_modules(): |
---|
116 | n/a | pyversion = get_python_version() |
---|
117 | n/a | else: |
---|
118 | n/a | pyversion = 'any' |
---|
119 | n/a | self.distribution.dist_files.append(('bdist_dumb', pyversion, |
---|
120 | n/a | filename)) |
---|
121 | n/a | |
---|
122 | n/a | if not self.keep_temp: |
---|
123 | n/a | remove_tree(self.bdist_dir, dry_run=self.dry_run) |
---|