blob: 535b8d2aea4ae0e8b8654b9e95d14f8e574b6d95 [file] [log] [blame]
Greg Warda82122b2000-02-17 23:56:15 +00001"""distutils.command.sdist
2
3Implements the Distutils 'sdist' command (create a source distribution)."""
4
Martin v. Löwis5a6601c2004-11-10 22:23:15 +00005# This module should be kept compatible with Python 2.1.
Andrew M. Kuchlingd448f662002-11-19 13:12:28 +00006
Greg Ward3ce77fd2000-03-02 01:49:45 +00007__revision__ = "$Id$"
Greg Warda82122b2000-02-17 23:56:15 +00008
Christian Heimesc5f05e42008-02-23 17:40:11 +00009import os, string
Tarek Ziadé653cb622009-01-04 00:07:14 +000010import sys
Greg Warda82122b2000-02-17 23:56:15 +000011from types import *
12from glob import glob
Greg Warda82122b2000-02-17 23:56:15 +000013from distutils.core import Command
Greg Wardab3a0f32000-08-05 01:31:54 +000014from distutils import dir_util, dep_util, file_util, archive_util
Greg Warda82122b2000-02-17 23:56:15 +000015from distutils.text_file import TextFile
Greg Ward6b24dff2000-07-30 01:47:16 +000016from distutils.errors import *
Greg Ward4571ac12000-07-30 01:05:02 +000017from distutils.filelist import FileList
Jeremy Hyltoncd8a1142002-06-04 20:14:43 +000018from distutils import log
Greg Warda82122b2000-02-17 23:56:15 +000019
20
Greg Ward34593812000-06-24 01:23:37 +000021def show_formats ():
22 """Print all possible values for the 'formats' option (used by
23 the "--help-formats" command-line option).
24 """
25 from distutils.fancy_getopt import FancyGetopt
26 from distutils.archive_util import ARCHIVE_FORMATS
27 formats=[]
28 for format in ARCHIVE_FORMATS.keys():
29 formats.append(("formats=" + format, None,
30 ARCHIVE_FORMATS[format][2]))
31 formats.sort()
32 pretty_printer = FancyGetopt(formats)
33 pretty_printer.print_help(
34 "List of available source distribution formats:")
35
Greg Ward1993f9a2000-02-18 00:13:53 +000036class sdist (Command):
Greg Warda82122b2000-02-17 23:56:15 +000037
38 description = "create a source distribution (tarball, zip file, etc.)"
39
Greg Wardbbeceea2000-02-18 00:25:39 +000040 user_options = [
41 ('template=', 't',
42 "name of manifest template file [default: MANIFEST.in]"),
43 ('manifest=', 'm',
44 "name of manifest file [default: MANIFEST]"),
45 ('use-defaults', None,
46 "include the default file set in the manifest "
47 "[default; disable with --no-defaults]"),
Greg Ward499822d2000-06-29 02:06:29 +000048 ('no-defaults', None,
49 "don't include the default file set"),
50 ('prune', None,
51 "specifically exclude files/directories that should not be "
52 "distributed (build tree, RCS/CVS dirs, etc.) "
53 "[default; disable with --no-prune]"),
54 ('no-prune', None,
55 "don't automatically exclude anything"),
Greg Ward839d5322000-04-26 01:14:33 +000056 ('manifest-only', 'o',
Greg Wardc3c8c6e2000-06-08 00:46:45 +000057 "just regenerate the manifest and then stop "
58 "(implies --force-manifest)"),
Greg Ward839d5322000-04-26 01:14:33 +000059 ('force-manifest', 'f',
Tarek Ziadé83175562010-05-17 11:00:17 +000060 "forcibly regenerate the manifest and carry on as usual. "
61 "Deprecated: now the manifest is always regenerated."),
Greg Wardbbeceea2000-02-18 00:25:39 +000062 ('formats=', None,
Greg Ward2ff78872000-06-24 00:23:20 +000063 "formats for source distribution (comma-separated list)"),
Greg Wardaf64aed2000-09-25 01:51:01 +000064 ('keep-temp', 'k',
Greg Wardbbeceea2000-02-18 00:25:39 +000065 "keep the distribution tree around after creating " +
66 "archive file(s)"),
Greg Wardc0614102000-07-05 03:06:46 +000067 ('dist-dir=', 'd',
68 "directory to put the source distribution archive(s) in "
69 "[default: dist]"),
Greg Wardbbeceea2000-02-18 00:25:39 +000070 ]
Greg Wardf1fe1032000-06-08 00:14:18 +000071
Greg Ward99b032e2000-09-25 01:41:15 +000072 boolean_options = ['use-defaults', 'prune',
73 'manifest-only', 'force-manifest',
Greg Wardaf64aed2000-09-25 01:51:01 +000074 'keep-temp']
Greg Wardf1fe1032000-06-08 00:14:18 +000075
Greg Ward9d17a7a2000-06-07 03:00:06 +000076 help_options = [
77 ('help-formats', None,
Greg Ward2ff78872000-06-24 00:23:20 +000078 "list available distribution formats", show_formats),
Greg Wardfa9ff762000-10-14 04:06:40 +000079 ]
Greg Ward9d17a7a2000-06-07 03:00:06 +000080
Greg Ward499822d2000-06-29 02:06:29 +000081 negative_opt = {'no-defaults': 'use-defaults',
82 'no-prune': 'prune' }
Greg Warda82122b2000-02-17 23:56:15 +000083
84 default_format = { 'posix': 'gztar',
85 'nt': 'zip' }
86
Greg Warde01149c2000-02-18 00:35:22 +000087 def initialize_options (self):
Greg Warda82122b2000-02-17 23:56:15 +000088 # 'template' and 'manifest' are, respectively, the names of
89 # the manifest template and manifest file.
90 self.template = None
91 self.manifest = None
92
93 # 'use_defaults': if true, we will include the default file set
94 # in the manifest
95 self.use_defaults = 1
Greg Ward499822d2000-06-29 02:06:29 +000096 self.prune = 1
Greg Warda82122b2000-02-17 23:56:15 +000097
98 self.manifest_only = 0
99 self.force_manifest = 0
100
101 self.formats = None
Greg Wardaf64aed2000-09-25 01:51:01 +0000102 self.keep_temp = 0
Greg Wardc0614102000-07-05 03:06:46 +0000103 self.dist_dir = None
Greg Warda82122b2000-02-17 23:56:15 +0000104
Greg Wardd87eb732000-06-01 01:10:56 +0000105 self.archive_files = None
106
Greg Warda82122b2000-02-17 23:56:15 +0000107
Greg Warde01149c2000-02-18 00:35:22 +0000108 def finalize_options (self):
Greg Warda82122b2000-02-17 23:56:15 +0000109 if self.manifest is None:
110 self.manifest = "MANIFEST"
111 if self.template is None:
112 self.template = "MANIFEST.in"
113
Greg Ward62d5a572000-06-04 15:12:51 +0000114 self.ensure_string_list('formats')
Greg Warda82122b2000-02-17 23:56:15 +0000115 if self.formats is None:
116 try:
117 self.formats = [self.default_format[os.name]]
118 except KeyError:
119 raise DistutilsPlatformError, \
Greg Ward578c10d2000-03-31 02:50:04 +0000120 "don't know how to create source distributions " + \
121 "on platform %s" % os.name
Greg Warda82122b2000-02-17 23:56:15 +0000122
Greg Wardcb1f4c42000-09-30 18:27:54 +0000123 bad_format = archive_util.check_archive_formats(self.formats)
Greg Ward6a9a5452000-04-22 03:11:55 +0000124 if bad_format:
125 raise DistutilsOptionError, \
126 "unknown archive format '%s'" % bad_format
127
Greg Wardc0614102000-07-05 03:06:46 +0000128 if self.dist_dir is None:
129 self.dist_dir = "dist"
130
Greg Warda82122b2000-02-17 23:56:15 +0000131
132 def run (self):
133
Greg Ward23266fe2000-07-30 01:30:31 +0000134 # 'filelist' contains the list of files that will make up the
135 # manifest
136 self.filelist = FileList()
Fred Drake21d45352001-12-06 21:01:19 +0000137
Greg Warda82122b2000-02-17 23:56:15 +0000138 # Ensure that all required meta-data is given; warn if not (but
139 # don't die, it's not *that* serious!)
Greg Wardcb1f4c42000-09-30 18:27:54 +0000140 self.check_metadata()
Greg Warda82122b2000-02-17 23:56:15 +0000141
142 # Do whatever it takes to get the list of files to process
143 # (process the manifest template, read an existing manifest,
Greg Ward23266fe2000-07-30 01:30:31 +0000144 # whatever). File list is accumulated in 'self.filelist'.
Greg Wardcb1f4c42000-09-30 18:27:54 +0000145 self.get_file_list()
Greg Warda82122b2000-02-17 23:56:15 +0000146
147 # If user just wanted us to regenerate the manifest, stop now.
148 if self.manifest_only:
149 return
150
151 # Otherwise, go ahead and create the source distribution tarball,
152 # or zipfile, or whatever.
Greg Wardcb1f4c42000-09-30 18:27:54 +0000153 self.make_distribution()
Greg Warda82122b2000-02-17 23:56:15 +0000154
155
156 def check_metadata (self):
Greg Wardc3c8c6e2000-06-08 00:46:45 +0000157 """Ensure that all required elements of meta-data (name, version,
158 URL, (author and author_email) or (maintainer and
159 maintainer_email)) are supplied by the Distribution object; warn if
160 any are missing.
161 """
Greg Ward535f2d92000-04-21 04:37:12 +0000162 metadata = self.distribution.metadata
Greg Warda82122b2000-02-17 23:56:15 +0000163
164 missing = []
165 for attr in ('name', 'version', 'url'):
Greg Wardcb1f4c42000-09-30 18:27:54 +0000166 if not (hasattr(metadata, attr) and getattr(metadata, attr)):
167 missing.append(attr)
Greg Warda82122b2000-02-17 23:56:15 +0000168
169 if missing:
Greg Wardcb1f4c42000-09-30 18:27:54 +0000170 self.warn("missing required meta-data: " +
171 string.join(missing, ", "))
Greg Warda82122b2000-02-17 23:56:15 +0000172
Greg Ward535f2d92000-04-21 04:37:12 +0000173 if metadata.author:
174 if not metadata.author_email:
Greg Wardcb1f4c42000-09-30 18:27:54 +0000175 self.warn("missing meta-data: if 'author' supplied, " +
176 "'author_email' must be supplied too")
Greg Ward535f2d92000-04-21 04:37:12 +0000177 elif metadata.maintainer:
178 if not metadata.maintainer_email:
Greg Wardcb1f4c42000-09-30 18:27:54 +0000179 self.warn("missing meta-data: if 'maintainer' supplied, " +
180 "'maintainer_email' must be supplied too")
Greg Warda82122b2000-02-17 23:56:15 +0000181 else:
Greg Wardcb1f4c42000-09-30 18:27:54 +0000182 self.warn("missing meta-data: either (author and author_email) " +
183 "or (maintainer and maintainer_email) " +
184 "must be supplied")
Greg Warda82122b2000-02-17 23:56:15 +0000185
186 # check_metadata ()
187
188
189 def get_file_list (self):
190 """Figure out the list of files to include in the source
Greg Ward23266fe2000-07-30 01:30:31 +0000191 distribution, and put it in 'self.filelist'. This might involve
Greg Warde0c8c2f2000-06-08 00:24:01 +0000192 reading the manifest template (and writing the manifest), or just
193 reading the manifest, or just using the default file set -- it all
Tarek Ziadée7281162010-05-17 10:26:15 +0000194 depends on the user's options.
Greg Warde0c8c2f2000-06-08 00:24:01 +0000195 """
Tarek Ziadée7281162010-05-17 10:26:15 +0000196 # new behavior:
197 # the file list is recalculated everytime because
198 # even if MANIFEST.in or setup.py are not changed
199 # the user might have added some files in the tree that
200 # need to be included.
201 #
202 # This makes --force the default and only behavior.
Greg Ward23266fe2000-07-30 01:30:31 +0000203 template_exists = os.path.isfile(self.template)
Tarek Ziadée7281162010-05-17 10:26:15 +0000204 if not template_exists:
205 self.warn(("manifest template '%s' does not exist " +
206 "(using default file list)") %
207 self.template)
208 self.filelist.findall()
209
210 if self.use_defaults:
211 self.add_defaults()
212
Greg Warda82122b2000-02-17 23:56:15 +0000213 if template_exists:
Tarek Ziadée7281162010-05-17 10:26:15 +0000214 self.read_template()
Greg Warda82122b2000-02-17 23:56:15 +0000215
Tarek Ziadée7281162010-05-17 10:26:15 +0000216 if self.prune:
217 self.prune_file_list()
Greg Wardb2db0eb2000-06-21 03:29:57 +0000218
Tarek Ziadée7281162010-05-17 10:26:15 +0000219 self.filelist.sort()
220 self.filelist.remove_duplicates()
221 self.write_manifest()
Greg Warda82122b2000-02-17 23:56:15 +0000222
223 # get_file_list ()
224
225
Greg Ward4a7319c2000-06-08 00:52:52 +0000226 def add_defaults (self):
Greg Ward23266fe2000-07-30 01:30:31 +0000227 """Add all the default files to self.filelist:
Greg Wardc3c8c6e2000-06-08 00:46:45 +0000228 - README or README.txt
229 - setup.py
230 - test/test*.py
231 - all pure Python modules mentioned in setup script
232 - all C sources listed as part of extensions or C libraries
233 in the setup script (doesn't catch C headers!)
234 Warns if (README or README.txt) or setup.py are missing; everything
235 else is optional.
236 """
Greg Ward14c8d052000-06-08 01:22:48 +0000237
Greg Wardd3b76a82000-09-06 02:08:24 +0000238 standards = [('README', 'README.txt'), self.distribution.script_name]
Greg Warda82122b2000-02-17 23:56:15 +0000239 for fn in standards:
Greg Wardcb1f4c42000-09-30 18:27:54 +0000240 if type(fn) is TupleType:
Greg Warda82122b2000-02-17 23:56:15 +0000241 alts = fn
Greg Ward48401122000-02-24 03:17:43 +0000242 got_it = 0
Greg Warda82122b2000-02-17 23:56:15 +0000243 for fn in alts:
Greg Wardcb1f4c42000-09-30 18:27:54 +0000244 if os.path.exists(fn):
Greg Warda82122b2000-02-17 23:56:15 +0000245 got_it = 1
Greg Wardcb1f4c42000-09-30 18:27:54 +0000246 self.filelist.append(fn)
Greg Warda82122b2000-02-17 23:56:15 +0000247 break
248
249 if not got_it:
Greg Wardcb1f4c42000-09-30 18:27:54 +0000250 self.warn("standard file not found: should have one of " +
251 string.join(alts, ', '))
Greg Warda82122b2000-02-17 23:56:15 +0000252 else:
Greg Wardcb1f4c42000-09-30 18:27:54 +0000253 if os.path.exists(fn):
254 self.filelist.append(fn)
Greg Warda82122b2000-02-17 23:56:15 +0000255 else:
Greg Wardcb1f4c42000-09-30 18:27:54 +0000256 self.warn("standard file '%s' not found" % fn)
Greg Warda82122b2000-02-17 23:56:15 +0000257
Greg Ward14c8d052000-06-08 01:22:48 +0000258 optional = ['test/test*.py', 'setup.cfg']
Greg Warda82122b2000-02-17 23:56:15 +0000259 for pattern in optional:
Greg Wardcb1f4c42000-09-30 18:27:54 +0000260 files = filter(os.path.isfile, glob(pattern))
Greg Warda82122b2000-02-17 23:56:15 +0000261 if files:
Greg Wardcb1f4c42000-09-30 18:27:54 +0000262 self.filelist.extend(files)
Greg Warda82122b2000-02-17 23:56:15 +0000263
Greg Ward578c10d2000-03-31 02:50:04 +0000264 if self.distribution.has_pure_modules():
Greg Wardcb1f4c42000-09-30 18:27:54 +0000265 build_py = self.get_finalized_command('build_py')
266 self.filelist.extend(build_py.get_source_files())
Greg Warda82122b2000-02-17 23:56:15 +0000267
Greg Ward578c10d2000-03-31 02:50:04 +0000268 if self.distribution.has_ext_modules():
Greg Wardcb1f4c42000-09-30 18:27:54 +0000269 build_ext = self.get_finalized_command('build_ext')
270 self.filelist.extend(build_ext.get_source_files())
Greg Warda82122b2000-02-17 23:56:15 +0000271
Greg Ward60908f12000-04-09 03:51:40 +0000272 if self.distribution.has_c_libraries():
Greg Wardcb1f4c42000-09-30 18:27:54 +0000273 build_clib = self.get_finalized_command('build_clib')
274 self.filelist.extend(build_clib.get_source_files())
Greg Ward60908f12000-04-09 03:51:40 +0000275
Fred Drake4b498232004-03-25 22:04:52 +0000276 if self.distribution.has_scripts():
277 build_scripts = self.get_finalized_command('build_scripts')
278 self.filelist.extend(build_scripts.get_source_files())
279
Greg Ward4a7319c2000-06-08 00:52:52 +0000280 # add_defaults ()
Fred Drake21d45352001-12-06 21:01:19 +0000281
Greg Warda82122b2000-02-17 23:56:15 +0000282
Greg Warda82122b2000-02-17 23:56:15 +0000283 def read_template (self):
Jeremy Hyltoncd8a1142002-06-04 20:14:43 +0000284 """Read and parse manifest template file named by self.template.
Greg Warda82122b2000-02-17 23:56:15 +0000285
Jeremy Hyltoncd8a1142002-06-04 20:14:43 +0000286 (usually "MANIFEST.in") The parsing and processing is done by
287 'self.filelist', which updates itself accordingly.
Greg Ward23266fe2000-07-30 01:30:31 +0000288 """
Jeremy Hyltoncd8a1142002-06-04 20:14:43 +0000289 log.info("reading manifest template '%s'", self.template)
Greg Wardcb1f4c42000-09-30 18:27:54 +0000290 template = TextFile(self.template,
291 strip_comments=1,
292 skip_blanks=1,
293 join_lines=1,
294 lstrip_ws=1,
295 rstrip_ws=1,
296 collapse_join=1)
Greg Warda82122b2000-02-17 23:56:15 +0000297
Greg Warda82122b2000-02-17 23:56:15 +0000298 while 1:
Greg Warda82122b2000-02-17 23:56:15 +0000299 line = template.readline()
300 if line is None: # end of file
301 break
302
Greg Ward6b24dff2000-07-30 01:47:16 +0000303 try:
304 self.filelist.process_template_line(line)
305 except DistutilsTemplateError, msg:
306 self.warn("%s, line %d: %s" % (template.filename,
307 template.current_line,
308 msg))
Greg Warda82122b2000-02-17 23:56:15 +0000309
310 # read_template ()
311
312
Greg Wardce15c6c2000-06-08 01:06:02 +0000313 def prune_file_list (self):
314 """Prune off branches that might slip into the file list as created
Greg Ward499822d2000-06-29 02:06:29 +0000315 by 'read_template()', but really don't belong there:
316 * the build tree (typically "build")
317 * the release tree itself (only an issue if we ran "sdist"
Greg Wardaf64aed2000-09-25 01:51:01 +0000318 previously with --keep-temp, or it aborted)
Georg Brandl1df03402008-03-06 06:47:18 +0000319 * any RCS, CVS, .svn, .hg, .git, .bzr, _darcs directories
Greg Wardce15c6c2000-06-08 01:06:02 +0000320 """
321 build = self.get_finalized_command('build')
322 base_dir = self.distribution.get_fullname()
Greg Wardce15c6c2000-06-08 01:06:02 +0000323
Greg Ward23266fe2000-07-30 01:30:31 +0000324 self.filelist.exclude_pattern(None, prefix=build.build_base)
325 self.filelist.exclude_pattern(None, prefix=base_dir)
Greg Wardf8b9e202000-06-08 00:08:14 +0000326
Tarek Ziadé653cb622009-01-04 00:07:14 +0000327 # pruning out vcs directories
328 # both separators are used under win32
Tarek Ziadé2e159992009-01-04 10:43:32 +0000329 if sys.platform == 'win32':
330 seps = r'/|\\'
331 else:
332 seps = '/'
333
334 vcs_dirs = ['RCS', 'CVS', r'\.svn', r'\.hg', r'\.git', r'\.bzr',
335 '_darcs']
Tarek Ziadé653cb622009-01-04 00:07:14 +0000336 vcs_ptrn = r'(^|%s)(%s)(%s).*' % (seps, '|'.join(vcs_dirs), seps)
337 self.filelist.exclude_pattern(vcs_ptrn, is_regex=1)
Greg Wardf8b9e202000-06-08 00:08:14 +0000338
Greg Warda82122b2000-02-17 23:56:15 +0000339 def write_manifest (self):
Greg Ward23266fe2000-07-30 01:30:31 +0000340 """Write the file list in 'self.filelist' (presumably as filled in
341 by 'add_defaults()' and 'read_template()') to the manifest file
342 named by 'self.manifest'.
Greg Warde0c8c2f2000-06-08 00:24:01 +0000343 """
Greg Wardab3a0f32000-08-05 01:31:54 +0000344 self.execute(file_util.write_file,
Greg Ward23266fe2000-07-30 01:30:31 +0000345 (self.manifest, self.filelist.files),
Greg Wardf8b9e202000-06-08 00:08:14 +0000346 "writing manifest file '%s'" % self.manifest)
Greg Warda82122b2000-02-17 23:56:15 +0000347
348 # write_manifest ()
349
350
351 def read_manifest (self):
Greg Warde0c8c2f2000-06-08 00:24:01 +0000352 """Read the manifest file (named by 'self.manifest') and use it to
Greg Ward23266fe2000-07-30 01:30:31 +0000353 fill in 'self.filelist', the list of files to include in the source
Greg Warde0c8c2f2000-06-08 00:24:01 +0000354 distribution.
355 """
Jeremy Hyltoncd8a1142002-06-04 20:14:43 +0000356 log.info("reading manifest file '%s'", self.manifest)
Greg Wardcb1f4c42000-09-30 18:27:54 +0000357 manifest = open(self.manifest)
Greg Warda82122b2000-02-17 23:56:15 +0000358 while 1:
Greg Wardcb1f4c42000-09-30 18:27:54 +0000359 line = manifest.readline()
Greg Warda82122b2000-02-17 23:56:15 +0000360 if line == '': # end of file
361 break
362 if line[-1] == '\n':
363 line = line[0:-1]
Greg Wardcb1f4c42000-09-30 18:27:54 +0000364 self.filelist.append(line)
Andrew M. Kuchling2d6c13e2008-02-21 14:23:38 +0000365 manifest.close()
Greg Warda82122b2000-02-17 23:56:15 +0000366
367 # read_manifest ()
Fred Drake21d45352001-12-06 21:01:19 +0000368
Greg Warda82122b2000-02-17 23:56:15 +0000369
Greg Warda82122b2000-02-17 23:56:15 +0000370 def make_release_tree (self, base_dir, files):
Greg Wardc3c8c6e2000-06-08 00:46:45 +0000371 """Create the directory tree that will become the source
372 distribution archive. All directories implied by the filenames in
373 'files' are created under 'base_dir', and then we hard link or copy
374 (if hard linking is unavailable) those files into place.
375 Essentially, this duplicates the developer's source tree, but in a
376 directory named after the distribution, containing only the files
377 to be distributed.
378 """
Greg Ward578c10d2000-03-31 02:50:04 +0000379 # Create all the directories under 'base_dir' necessary to
Greg Ward5fad2682000-09-06 02:18:59 +0000380 # put 'files' there; the 'mkpath()' is just so we don't die
381 # if the manifest happens to be empty.
382 self.mkpath(base_dir)
Jeremy Hyltoncd8a1142002-06-04 20:14:43 +0000383 dir_util.create_tree(base_dir, files, dry_run=self.dry_run)
Greg Warda82122b2000-02-17 23:56:15 +0000384
385 # And walk over the list of files, either making a hard link (if
386 # os.link exists) to each one that doesn't already exist in its
387 # corresponding location under 'base_dir', or copying each file
388 # that's out-of-date in 'base_dir'. (Usually, all files will be
389 # out-of-date, because by default we blow away 'base_dir' when
390 # we're done making the distribution archives.)
Fred Drake21d45352001-12-06 21:01:19 +0000391
Greg Wardcb1f4c42000-09-30 18:27:54 +0000392 if hasattr(os, 'link'): # can make hard links on this system
Greg Ward578c10d2000-03-31 02:50:04 +0000393 link = 'hard'
Greg Warda82122b2000-02-17 23:56:15 +0000394 msg = "making hard links in %s..." % base_dir
Greg Ward578c10d2000-03-31 02:50:04 +0000395 else: # nope, have to copy
396 link = None
Greg Warda82122b2000-02-17 23:56:15 +0000397 msg = "copying files to %s..." % base_dir
398
Greg Ward5fad2682000-09-06 02:18:59 +0000399 if not files:
Jeremy Hyltoncd8a1142002-06-04 20:14:43 +0000400 log.warn("no files to distribute -- empty manifest?")
Greg Ward5fad2682000-09-06 02:18:59 +0000401 else:
Jeremy Hyltoncd8a1142002-06-04 20:14:43 +0000402 log.info(msg)
Greg Warda82122b2000-02-17 23:56:15 +0000403 for file in files:
Greg Ward5fad2682000-09-06 02:18:59 +0000404 if not os.path.isfile(file):
Jeremy Hyltoncd8a1142002-06-04 20:14:43 +0000405 log.warn("'%s' not a regular file -- skipping" % file)
Greg Ward5fad2682000-09-06 02:18:59 +0000406 else:
Greg Wardcb1f4c42000-09-30 18:27:54 +0000407 dest = os.path.join(base_dir, file)
408 self.copy_file(file, dest, link=link)
Greg Warda82122b2000-02-17 23:56:15 +0000409
Andrew M. Kuchlinga7f225d2001-03-22 03:10:05 +0000410 self.distribution.metadata.write_pkg_info(base_dir)
Fred Drake21d45352001-12-06 21:01:19 +0000411
Greg Warda82122b2000-02-17 23:56:15 +0000412 # make_release_tree ()
413
Greg Warda82122b2000-02-17 23:56:15 +0000414 def make_distribution (self):
Greg Wardc3c8c6e2000-06-08 00:46:45 +0000415 """Create the source distribution(s). First, we create the release
416 tree with 'make_release_tree()'; then, we create all required
417 archive files (according to 'self.formats') from the release tree.
418 Finally, we clean up by blowing away the release tree (unless
Greg Wardaf64aed2000-09-25 01:51:01 +0000419 'self.keep_temp' is true). The list of archive files created is
Greg Wardc3c8c6e2000-06-08 00:46:45 +0000420 stored so it can be retrieved later by 'get_archive_files()'.
421 """
Greg Ward578c10d2000-03-31 02:50:04 +0000422 # Don't warn about missing meta-data here -- should be (and is!)
423 # done elsewhere.
Greg Ward0ae7f762000-04-22 02:51:25 +0000424 base_dir = self.distribution.get_fullname()
Greg Wardc0614102000-07-05 03:06:46 +0000425 base_name = os.path.join(self.dist_dir, base_dir)
Greg Warda82122b2000-02-17 23:56:15 +0000426
Greg Wardcb1f4c42000-09-30 18:27:54 +0000427 self.make_release_tree(base_dir, self.filelist.files)
Greg Wardd87eb732000-06-01 01:10:56 +0000428 archive_files = [] # remember names of files we create
Tarek Ziadéf66326f2009-01-26 17:20:15 +0000429 # tar archive must be created last to avoid overwrite and remove
430 if 'tar' in self.formats:
431 self.formats.append(self.formats.pop(self.formats.index('tar')))
432
Greg Warda82122b2000-02-17 23:56:15 +0000433 for fmt in self.formats:
Greg Wardcb1f4c42000-09-30 18:27:54 +0000434 file = self.make_archive(base_name, fmt, base_dir=base_dir)
Greg Wardd87eb732000-06-01 01:10:56 +0000435 archive_files.append(file)
Martin v. Löwis98da5622005-03-23 18:54:36 +0000436 self.distribution.dist_files.append(('sdist', '', file))
Greg Wardd87eb732000-06-01 01:10:56 +0000437
438 self.archive_files = archive_files
Greg Warda82122b2000-02-17 23:56:15 +0000439
Greg Wardaf64aed2000-09-25 01:51:01 +0000440 if not self.keep_temp:
Jeremy Hyltoncd8a1142002-06-04 20:14:43 +0000441 dir_util.remove_tree(base_dir, dry_run=self.dry_run)
Greg Warda82122b2000-02-17 23:56:15 +0000442
Greg Wardd87eb732000-06-01 01:10:56 +0000443 def get_archive_files (self):
444 """Return the list of archive files created when the command
445 was run, or None if the command hasn't run yet.
446 """
447 return self.archive_files
448
Greg Wardfcd974e2000-05-25 01:10:04 +0000449# class sdist