2000-02-17 19:56:15 -04:00
|
|
|
"""distutils.command.sdist
|
|
|
|
|
|
|
|
Implements the Distutils 'sdist' command (create a source distribution)."""
|
|
|
|
|
|
|
|
# created 1999/09/22, Greg Ward
|
|
|
|
|
2000-03-01 21:49:45 -04:00
|
|
|
__revision__ = "$Id$"
|
2000-02-17 19:56:15 -04:00
|
|
|
|
2000-07-29 22:05:02 -03:00
|
|
|
import sys, os, string
|
2000-02-17 19:56:15 -04:00
|
|
|
from types import *
|
|
|
|
from glob import glob
|
|
|
|
from distutils.core import Command
|
2000-08-04 22:31:54 -03:00
|
|
|
from distutils import dir_util, dep_util, file_util, archive_util
|
2000-02-17 19:56:15 -04:00
|
|
|
from distutils.text_file import TextFile
|
2000-07-29 22:47:16 -03:00
|
|
|
from distutils.errors import *
|
2000-07-29 22:05:02 -03:00
|
|
|
from distutils.filelist import FileList
|
2002-06-04 17:14:43 -03:00
|
|
|
from distutils import log
|
2000-02-17 19:56:15 -04:00
|
|
|
|
|
|
|
|
2000-06-23 22:23:37 -03:00
|
|
|
def show_formats ():
|
|
|
|
"""Print all possible values for the 'formats' option (used by
|
|
|
|
the "--help-formats" command-line option).
|
|
|
|
"""
|
|
|
|
from distutils.fancy_getopt import FancyGetopt
|
|
|
|
from distutils.archive_util import ARCHIVE_FORMATS
|
|
|
|
formats=[]
|
|
|
|
for format in ARCHIVE_FORMATS.keys():
|
|
|
|
formats.append(("formats=" + format, None,
|
|
|
|
ARCHIVE_FORMATS[format][2]))
|
|
|
|
formats.sort()
|
|
|
|
pretty_printer = FancyGetopt(formats)
|
|
|
|
pretty_printer.print_help(
|
|
|
|
"List of available source distribution formats:")
|
|
|
|
|
2000-02-17 20:13:53 -04:00
|
|
|
class sdist (Command):
|
2000-02-17 19:56:15 -04:00
|
|
|
|
|
|
|
description = "create a source distribution (tarball, zip file, etc.)"
|
|
|
|
|
2000-02-17 20:25:39 -04:00
|
|
|
user_options = [
|
|
|
|
('template=', 't',
|
|
|
|
"name of manifest template file [default: MANIFEST.in]"),
|
|
|
|
('manifest=', 'm',
|
|
|
|
"name of manifest file [default: MANIFEST]"),
|
|
|
|
('use-defaults', None,
|
|
|
|
"include the default file set in the manifest "
|
|
|
|
"[default; disable with --no-defaults]"),
|
2000-06-28 23:06:29 -03:00
|
|
|
('no-defaults', None,
|
|
|
|
"don't include the default file set"),
|
|
|
|
('prune', None,
|
|
|
|
"specifically exclude files/directories that should not be "
|
|
|
|
"distributed (build tree, RCS/CVS dirs, etc.) "
|
|
|
|
"[default; disable with --no-prune]"),
|
|
|
|
('no-prune', None,
|
|
|
|
"don't automatically exclude anything"),
|
2000-04-25 22:14:33 -03:00
|
|
|
('manifest-only', 'o',
|
2000-06-07 21:46:45 -03:00
|
|
|
"just regenerate the manifest and then stop "
|
|
|
|
"(implies --force-manifest)"),
|
2000-04-25 22:14:33 -03:00
|
|
|
('force-manifest', 'f',
|
2000-02-17 20:25:39 -04:00
|
|
|
"forcibly regenerate the manifest and carry on as usual"),
|
|
|
|
('formats=', None,
|
2000-06-23 21:23:20 -03:00
|
|
|
"formats for source distribution (comma-separated list)"),
|
2000-09-24 22:51:01 -03:00
|
|
|
('keep-temp', 'k',
|
2000-02-17 20:25:39 -04:00
|
|
|
"keep the distribution tree around after creating " +
|
|
|
|
"archive file(s)"),
|
2000-07-05 00:06:46 -03:00
|
|
|
('dist-dir=', 'd',
|
|
|
|
"directory to put the source distribution archive(s) in "
|
|
|
|
"[default: dist]"),
|
2000-02-17 20:25:39 -04:00
|
|
|
]
|
2000-06-07 21:14:18 -03:00
|
|
|
|
2000-09-24 22:41:15 -03:00
|
|
|
boolean_options = ['use-defaults', 'prune',
|
|
|
|
'manifest-only', 'force-manifest',
|
2000-09-24 22:51:01 -03:00
|
|
|
'keep-temp']
|
2000-06-07 21:14:18 -03:00
|
|
|
|
2000-06-07 00:00:06 -03:00
|
|
|
help_options = [
|
|
|
|
('help-formats', None,
|
2000-06-23 21:23:20 -03:00
|
|
|
"list available distribution formats", show_formats),
|
2000-10-14 01:06:40 -03:00
|
|
|
]
|
2000-06-07 00:00:06 -03:00
|
|
|
|
2000-06-28 23:06:29 -03:00
|
|
|
negative_opt = {'no-defaults': 'use-defaults',
|
|
|
|
'no-prune': 'prune' }
|
2000-02-17 19:56:15 -04:00
|
|
|
|
|
|
|
default_format = { 'posix': 'gztar',
|
|
|
|
'nt': 'zip' }
|
|
|
|
|
2000-02-17 20:35:22 -04:00
|
|
|
def initialize_options (self):
|
2000-02-17 19:56:15 -04:00
|
|
|
# 'template' and 'manifest' are, respectively, the names of
|
|
|
|
# the manifest template and manifest file.
|
|
|
|
self.template = None
|
|
|
|
self.manifest = None
|
|
|
|
|
|
|
|
# 'use_defaults': if true, we will include the default file set
|
|
|
|
# in the manifest
|
|
|
|
self.use_defaults = 1
|
2000-06-28 23:06:29 -03:00
|
|
|
self.prune = 1
|
2000-02-17 19:56:15 -04:00
|
|
|
|
|
|
|
self.manifest_only = 0
|
|
|
|
self.force_manifest = 0
|
|
|
|
|
|
|
|
self.formats = None
|
2000-09-24 22:51:01 -03:00
|
|
|
self.keep_temp = 0
|
2000-07-05 00:06:46 -03:00
|
|
|
self.dist_dir = None
|
2000-02-17 19:56:15 -04:00
|
|
|
|
2000-05-31 22:10:56 -03:00
|
|
|
self.archive_files = None
|
|
|
|
|
2000-02-17 19:56:15 -04:00
|
|
|
|
2000-02-17 20:35:22 -04:00
|
|
|
def finalize_options (self):
|
2000-02-17 19:56:15 -04:00
|
|
|
if self.manifest is None:
|
|
|
|
self.manifest = "MANIFEST"
|
|
|
|
if self.template is None:
|
|
|
|
self.template = "MANIFEST.in"
|
|
|
|
|
2000-06-04 12:12:51 -03:00
|
|
|
self.ensure_string_list('formats')
|
2000-02-17 19:56:15 -04:00
|
|
|
if self.formats is None:
|
|
|
|
try:
|
|
|
|
self.formats = [self.default_format[os.name]]
|
|
|
|
except KeyError:
|
|
|
|
raise DistutilsPlatformError, \
|
2000-03-30 22:50:04 -04:00
|
|
|
"don't know how to create source distributions " + \
|
|
|
|
"on platform %s" % os.name
|
2000-02-17 19:56:15 -04:00
|
|
|
|
2000-09-30 15:27:54 -03:00
|
|
|
bad_format = archive_util.check_archive_formats(self.formats)
|
2000-04-22 00:11:55 -03:00
|
|
|
if bad_format:
|
|
|
|
raise DistutilsOptionError, \
|
|
|
|
"unknown archive format '%s'" % bad_format
|
|
|
|
|
2000-07-05 00:06:46 -03:00
|
|
|
if self.dist_dir is None:
|
|
|
|
self.dist_dir = "dist"
|
|
|
|
|
2000-02-17 19:56:15 -04:00
|
|
|
|
|
|
|
def run (self):
|
|
|
|
|
2000-07-29 22:30:31 -03:00
|
|
|
# 'filelist' contains the list of files that will make up the
|
|
|
|
# manifest
|
|
|
|
self.filelist = FileList()
|
2001-12-06 17:01:19 -04:00
|
|
|
|
2000-02-17 19:56:15 -04:00
|
|
|
# Ensure that all required meta-data is given; warn if not (but
|
|
|
|
# don't die, it's not *that* serious!)
|
2000-09-30 15:27:54 -03:00
|
|
|
self.check_metadata()
|
2000-02-17 19:56:15 -04:00
|
|
|
|
|
|
|
# Do whatever it takes to get the list of files to process
|
|
|
|
# (process the manifest template, read an existing manifest,
|
2000-07-29 22:30:31 -03:00
|
|
|
# whatever). File list is accumulated in 'self.filelist'.
|
2000-09-30 15:27:54 -03:00
|
|
|
self.get_file_list()
|
2000-02-17 19:56:15 -04:00
|
|
|
|
|
|
|
# If user just wanted us to regenerate the manifest, stop now.
|
|
|
|
if self.manifest_only:
|
|
|
|
return
|
|
|
|
|
|
|
|
# Otherwise, go ahead and create the source distribution tarball,
|
|
|
|
# or zipfile, or whatever.
|
2000-09-30 15:27:54 -03:00
|
|
|
self.make_distribution()
|
2000-02-17 19:56:15 -04:00
|
|
|
|
|
|
|
|
|
|
|
def check_metadata (self):
|
2000-06-07 21:46:45 -03:00
|
|
|
"""Ensure that all required elements of meta-data (name, version,
|
|
|
|
URL, (author and author_email) or (maintainer and
|
|
|
|
maintainer_email)) are supplied by the Distribution object; warn if
|
|
|
|
any are missing.
|
|
|
|
"""
|
2000-04-21 01:37:12 -03:00
|
|
|
metadata = self.distribution.metadata
|
2000-02-17 19:56:15 -04:00
|
|
|
|
|
|
|
missing = []
|
|
|
|
for attr in ('name', 'version', 'url'):
|
2000-09-30 15:27:54 -03:00
|
|
|
if not (hasattr(metadata, attr) and getattr(metadata, attr)):
|
|
|
|
missing.append(attr)
|
2000-02-17 19:56:15 -04:00
|
|
|
|
|
|
|
if missing:
|
2000-09-30 15:27:54 -03:00
|
|
|
self.warn("missing required meta-data: " +
|
|
|
|
string.join(missing, ", "))
|
2000-02-17 19:56:15 -04:00
|
|
|
|
2000-04-21 01:37:12 -03:00
|
|
|
if metadata.author:
|
|
|
|
if not metadata.author_email:
|
2000-09-30 15:27:54 -03:00
|
|
|
self.warn("missing meta-data: if 'author' supplied, " +
|
|
|
|
"'author_email' must be supplied too")
|
2000-04-21 01:37:12 -03:00
|
|
|
elif metadata.maintainer:
|
|
|
|
if not metadata.maintainer_email:
|
2000-09-30 15:27:54 -03:00
|
|
|
self.warn("missing meta-data: if 'maintainer' supplied, " +
|
|
|
|
"'maintainer_email' must be supplied too")
|
2000-02-17 19:56:15 -04:00
|
|
|
else:
|
2000-09-30 15:27:54 -03:00
|
|
|
self.warn("missing meta-data: either (author and author_email) " +
|
|
|
|
"or (maintainer and maintainer_email) " +
|
|
|
|
"must be supplied")
|
2000-02-17 19:56:15 -04:00
|
|
|
|
|
|
|
# check_metadata ()
|
|
|
|
|
|
|
|
|
|
|
|
def get_file_list (self):
|
|
|
|
"""Figure out the list of files to include in the source
|
2000-07-29 22:30:31 -03:00
|
|
|
distribution, and put it in 'self.filelist'. This might involve
|
2000-06-07 21:24:01 -03:00
|
|
|
reading the manifest template (and writing the manifest), or just
|
|
|
|
reading the manifest, or just using the default file set -- it all
|
|
|
|
depends on the user's options and the state of the filesystem.
|
|
|
|
"""
|
2000-06-21 00:29:57 -03:00
|
|
|
|
|
|
|
# If we have a manifest template, see if it's newer than the
|
|
|
|
# manifest; if so, we'll regenerate the manifest.
|
2000-07-29 22:30:31 -03:00
|
|
|
template_exists = os.path.isfile(self.template)
|
2000-02-17 19:56:15 -04:00
|
|
|
if template_exists:
|
2000-08-04 22:31:54 -03:00
|
|
|
template_newer = dep_util.newer(self.template, self.manifest)
|
2000-02-17 19:56:15 -04:00
|
|
|
|
2000-06-21 00:29:57 -03:00
|
|
|
# The contents of the manifest file almost certainly depend on the
|
|
|
|
# setup script as well as the manifest template -- so if the setup
|
|
|
|
# script is newer than the manifest, we'll regenerate the manifest
|
|
|
|
# from the template. (Well, not quite: if we already have a
|
|
|
|
# manifest, but there's no template -- which will happen if the
|
|
|
|
# developer elects to generate a manifest some other way -- then we
|
|
|
|
# can't regenerate the manifest, so we don't.)
|
2000-08-28 22:15:18 -03:00
|
|
|
self.debug_print("checking if %s newer than %s" %
|
|
|
|
(self.distribution.script_name, self.manifest))
|
|
|
|
setup_newer = dep_util.newer(self.distribution.script_name,
|
|
|
|
self.manifest)
|
2000-06-21 00:29:57 -03:00
|
|
|
|
|
|
|
# cases:
|
|
|
|
# 1) no manifest, template exists: generate manifest
|
|
|
|
# (covered by 2a: no manifest == template newer)
|
|
|
|
# 2) manifest & template exist:
|
|
|
|
# 2a) template or setup script newer than manifest:
|
|
|
|
# regenerate manifest
|
|
|
|
# 2b) manifest newer than both:
|
|
|
|
# do nothing (unless --force or --manifest-only)
|
|
|
|
# 3) manifest exists, no template:
|
|
|
|
# do nothing (unless --force or --manifest-only)
|
|
|
|
# 4) no manifest, no template: generate w/ warning ("defaults only")
|
|
|
|
|
2000-09-05 23:08:24 -03:00
|
|
|
manifest_outofdate = (template_exists and
|
|
|
|
(template_newer or setup_newer))
|
|
|
|
force_regen = self.force_manifest or self.manifest_only
|
|
|
|
manifest_exists = os.path.isfile(self.manifest)
|
|
|
|
neither_exists = (not template_exists and not manifest_exists)
|
2000-02-17 19:56:15 -04:00
|
|
|
|
2000-09-05 23:08:24 -03:00
|
|
|
# Regenerate the manifest if necessary (or if explicitly told to)
|
|
|
|
if manifest_outofdate or neither_exists or force_regen:
|
2000-02-17 19:56:15 -04:00
|
|
|
if not template_exists:
|
2000-07-29 22:30:31 -03:00
|
|
|
self.warn(("manifest template '%s' does not exist " +
|
|
|
|
"(using default file list)") %
|
|
|
|
self.template)
|
2000-07-29 22:47:16 -03:00
|
|
|
self.filelist.findall()
|
|
|
|
|
2000-02-17 19:56:15 -04:00
|
|
|
if self.use_defaults:
|
2000-07-29 22:30:31 -03:00
|
|
|
self.add_defaults()
|
2000-02-17 19:56:15 -04:00
|
|
|
if template_exists:
|
2000-07-29 22:30:31 -03:00
|
|
|
self.read_template()
|
2000-06-28 23:06:29 -03:00
|
|
|
if self.prune:
|
|
|
|
self.prune_file_list()
|
2000-06-07 22:06:02 -03:00
|
|
|
|
2000-07-29 22:30:31 -03:00
|
|
|
self.filelist.sort()
|
|
|
|
self.filelist.remove_duplicates()
|
|
|
|
self.write_manifest()
|
2000-02-17 19:56:15 -04:00
|
|
|
|
|
|
|
# Don't regenerate the manifest, just read it in.
|
|
|
|
else:
|
2000-07-29 22:30:31 -03:00
|
|
|
self.read_manifest()
|
2000-02-17 19:56:15 -04:00
|
|
|
|
|
|
|
# get_file_list ()
|
|
|
|
|
|
|
|
|
2000-06-07 21:52:52 -03:00
|
|
|
def add_defaults (self):
|
2000-07-29 22:30:31 -03:00
|
|
|
"""Add all the default files to self.filelist:
|
2000-06-07 21:46:45 -03:00
|
|
|
- README or README.txt
|
|
|
|
- setup.py
|
|
|
|
- test/test*.py
|
|
|
|
- all pure Python modules mentioned in setup script
|
|
|
|
- all C sources listed as part of extensions or C libraries
|
|
|
|
in the setup script (doesn't catch C headers!)
|
|
|
|
Warns if (README or README.txt) or setup.py are missing; everything
|
|
|
|
else is optional.
|
|
|
|
"""
|
2000-06-07 22:22:48 -03:00
|
|
|
|
2000-09-05 23:08:24 -03:00
|
|
|
standards = [('README', 'README.txt'), self.distribution.script_name]
|
2000-02-17 19:56:15 -04:00
|
|
|
for fn in standards:
|
2000-09-30 15:27:54 -03:00
|
|
|
if type(fn) is TupleType:
|
2000-02-17 19:56:15 -04:00
|
|
|
alts = fn
|
2000-02-23 23:17:43 -04:00
|
|
|
got_it = 0
|
2000-02-17 19:56:15 -04:00
|
|
|
for fn in alts:
|
2000-09-30 15:27:54 -03:00
|
|
|
if os.path.exists(fn):
|
2000-02-17 19:56:15 -04:00
|
|
|
got_it = 1
|
2000-09-30 15:27:54 -03:00
|
|
|
self.filelist.append(fn)
|
2000-02-17 19:56:15 -04:00
|
|
|
break
|
|
|
|
|
|
|
|
if not got_it:
|
2000-09-30 15:27:54 -03:00
|
|
|
self.warn("standard file not found: should have one of " +
|
|
|
|
string.join(alts, ', '))
|
2000-02-17 19:56:15 -04:00
|
|
|
else:
|
2000-09-30 15:27:54 -03:00
|
|
|
if os.path.exists(fn):
|
|
|
|
self.filelist.append(fn)
|
2000-02-17 19:56:15 -04:00
|
|
|
else:
|
2000-09-30 15:27:54 -03:00
|
|
|
self.warn("standard file '%s' not found" % fn)
|
2000-02-17 19:56:15 -04:00
|
|
|
|
2000-06-07 22:22:48 -03:00
|
|
|
optional = ['test/test*.py', 'setup.cfg']
|
2000-02-17 19:56:15 -04:00
|
|
|
for pattern in optional:
|
2000-09-30 15:27:54 -03:00
|
|
|
files = filter(os.path.isfile, glob(pattern))
|
2000-02-17 19:56:15 -04:00
|
|
|
if files:
|
2000-09-30 15:27:54 -03:00
|
|
|
self.filelist.extend(files)
|
2000-02-17 19:56:15 -04:00
|
|
|
|
2000-03-30 22:50:04 -04:00
|
|
|
if self.distribution.has_pure_modules():
|
2000-09-30 15:27:54 -03:00
|
|
|
build_py = self.get_finalized_command('build_py')
|
|
|
|
self.filelist.extend(build_py.get_source_files())
|
2000-02-17 19:56:15 -04:00
|
|
|
|
2000-03-30 22:50:04 -04:00
|
|
|
if self.distribution.has_ext_modules():
|
2000-09-30 15:27:54 -03:00
|
|
|
build_ext = self.get_finalized_command('build_ext')
|
|
|
|
self.filelist.extend(build_ext.get_source_files())
|
2000-04-09 00:51:40 -03:00
|
|
|
|
|
|
|
if self.distribution.has_c_libraries():
|
2000-09-30 15:27:54 -03:00
|
|
|
build_clib = self.get_finalized_command('build_clib')
|
|
|
|
self.filelist.extend(build_clib.get_source_files())
|
2000-02-17 19:56:15 -04:00
|
|
|
|
2000-06-07 21:52:52 -03:00
|
|
|
# add_defaults ()
|
2001-12-06 17:01:19 -04:00
|
|
|
|
2000-02-17 19:56:15 -04:00
|
|
|
|
|
|
|
def read_template (self):
|
2002-06-04 17:14:43 -03:00
|
|
|
"""Read and parse manifest template file named by self.template.
|
2000-07-29 22:30:31 -03:00
|
|
|
|
2002-06-04 17:14:43 -03:00
|
|
|
(usually "MANIFEST.in") The parsing and processing is done by
|
|
|
|
'self.filelist', which updates itself accordingly.
|
2000-06-07 21:24:01 -03:00
|
|
|
"""
|
2002-06-04 17:14:43 -03:00
|
|
|
log.info("reading manifest template '%s'", self.template)
|
2000-09-30 15:27:54 -03:00
|
|
|
template = TextFile(self.template,
|
|
|
|
strip_comments=1,
|
|
|
|
skip_blanks=1,
|
|
|
|
join_lines=1,
|
|
|
|
lstrip_ws=1,
|
|
|
|
rstrip_ws=1,
|
|
|
|
collapse_join=1)
|
2000-02-17 19:56:15 -04:00
|
|
|
|
|
|
|
while 1:
|
|
|
|
line = template.readline()
|
|
|
|
if line is None: # end of file
|
|
|
|
break
|
|
|
|
|
2000-07-29 22:47:16 -03:00
|
|
|
try:
|
|
|
|
self.filelist.process_template_line(line)
|
|
|
|
except DistutilsTemplateError, msg:
|
|
|
|
self.warn("%s, line %d: %s" % (template.filename,
|
|
|
|
template.current_line,
|
|
|
|
msg))
|
2000-02-17 19:56:15 -04:00
|
|
|
|
2000-06-07 22:06:02 -03:00
|
|
|
# read_template ()
|
|
|
|
|
2000-05-27 00:03:23 -03:00
|
|
|
|
2000-06-07 22:06:02 -03:00
|
|
|
def prune_file_list (self):
|
|
|
|
"""Prune off branches that might slip into the file list as created
|
2000-06-28 23:06:29 -03:00
|
|
|
by 'read_template()', but really don't belong there:
|
|
|
|
* the build tree (typically "build")
|
|
|
|
* the release tree itself (only an issue if we ran "sdist"
|
2000-09-24 22:51:01 -03:00
|
|
|
previously with --keep-temp, or it aborted)
|
2000-06-28 23:06:29 -03:00
|
|
|
* any RCS or CVS directories
|
2000-06-07 22:06:02 -03:00
|
|
|
"""
|
|
|
|
build = self.get_finalized_command('build')
|
2000-05-27 00:03:23 -03:00
|
|
|
base_dir = self.distribution.get_fullname()
|
2000-06-07 21:08:14 -03:00
|
|
|
|
2000-07-29 22:30:31 -03:00
|
|
|
self.filelist.exclude_pattern(None, prefix=build.build_base)
|
|
|
|
self.filelist.exclude_pattern(None, prefix=base_dir)
|
|
|
|
self.filelist.exclude_pattern(r'/(RCS|CVS)/.*', is_regex=1)
|
2000-06-07 21:08:14 -03:00
|
|
|
|
|
|
|
|
2000-02-17 19:56:15 -04:00
|
|
|
def write_manifest (self):
|
2000-07-29 22:30:31 -03:00
|
|
|
"""Write the file list in 'self.filelist' (presumably as filled in
|
|
|
|
by 'add_defaults()' and 'read_template()') to the manifest file
|
|
|
|
named by 'self.manifest'.
|
2000-06-07 21:24:01 -03:00
|
|
|
"""
|
2000-08-04 22:31:54 -03:00
|
|
|
self.execute(file_util.write_file,
|
2000-07-29 22:30:31 -03:00
|
|
|
(self.manifest, self.filelist.files),
|
2000-06-07 21:08:14 -03:00
|
|
|
"writing manifest file '%s'" % self.manifest)
|
2000-02-17 19:56:15 -04:00
|
|
|
|
|
|
|
# write_manifest ()
|
|
|
|
|
|
|
|
|
|
|
|
def read_manifest (self):
|
2000-06-07 21:24:01 -03:00
|
|
|
"""Read the manifest file (named by 'self.manifest') and use it to
|
2000-07-29 22:30:31 -03:00
|
|
|
fill in 'self.filelist', the list of files to include in the source
|
2000-06-07 21:24:01 -03:00
|
|
|
distribution.
|
|
|
|
"""
|
2002-06-04 17:14:43 -03:00
|
|
|
log.info("reading manifest file '%s'", self.manifest)
|
2000-09-30 15:27:54 -03:00
|
|
|
manifest = open(self.manifest)
|
2000-02-17 19:56:15 -04:00
|
|
|
while 1:
|
2000-09-30 15:27:54 -03:00
|
|
|
line = manifest.readline()
|
2000-02-17 19:56:15 -04:00
|
|
|
if line == '': # end of file
|
|
|
|
break
|
|
|
|
if line[-1] == '\n':
|
|
|
|
line = line[0:-1]
|
2000-09-30 15:27:54 -03:00
|
|
|
self.filelist.append(line)
|
2000-02-17 19:56:15 -04:00
|
|
|
|
|
|
|
# read_manifest ()
|
2001-12-06 17:01:19 -04:00
|
|
|
|
2000-02-17 19:56:15 -04:00
|
|
|
|
|
|
|
def make_release_tree (self, base_dir, files):
|
2000-06-07 21:46:45 -03:00
|
|
|
"""Create the directory tree that will become the source
|
|
|
|
distribution archive. All directories implied by the filenames in
|
|
|
|
'files' are created under 'base_dir', and then we hard link or copy
|
|
|
|
(if hard linking is unavailable) those files into place.
|
|
|
|
Essentially, this duplicates the developer's source tree, but in a
|
|
|
|
directory named after the distribution, containing only the files
|
|
|
|
to be distributed.
|
|
|
|
"""
|
2000-03-30 22:50:04 -04:00
|
|
|
# Create all the directories under 'base_dir' necessary to
|
2000-09-05 23:18:59 -03:00
|
|
|
# put 'files' there; the 'mkpath()' is just so we don't die
|
|
|
|
# if the manifest happens to be empty.
|
|
|
|
self.mkpath(base_dir)
|
2002-06-04 17:14:43 -03:00
|
|
|
dir_util.create_tree(base_dir, files, dry_run=self.dry_run)
|
2000-02-17 19:56:15 -04:00
|
|
|
|
|
|
|
# And walk over the list of files, either making a hard link (if
|
|
|
|
# os.link exists) to each one that doesn't already exist in its
|
|
|
|
# corresponding location under 'base_dir', or copying each file
|
|
|
|
# that's out-of-date in 'base_dir'. (Usually, all files will be
|
|
|
|
# out-of-date, because by default we blow away 'base_dir' when
|
|
|
|
# we're done making the distribution archives.)
|
2001-12-06 17:01:19 -04:00
|
|
|
|
2000-09-30 15:27:54 -03:00
|
|
|
if hasattr(os, 'link'): # can make hard links on this system
|
2000-03-30 22:50:04 -04:00
|
|
|
link = 'hard'
|
2000-02-17 19:56:15 -04:00
|
|
|
msg = "making hard links in %s..." % base_dir
|
2000-03-30 22:50:04 -04:00
|
|
|
else: # nope, have to copy
|
|
|
|
link = None
|
2000-02-17 19:56:15 -04:00
|
|
|
msg = "copying files to %s..." % base_dir
|
|
|
|
|
2000-09-05 23:18:59 -03:00
|
|
|
if not files:
|
2002-06-04 17:14:43 -03:00
|
|
|
log.warn("no files to distribute -- empty manifest?")
|
2000-09-05 23:18:59 -03:00
|
|
|
else:
|
2002-06-04 17:14:43 -03:00
|
|
|
log.info(msg)
|
2000-02-17 19:56:15 -04:00
|
|
|
for file in files:
|
2000-09-05 23:18:59 -03:00
|
|
|
if not os.path.isfile(file):
|
2002-06-04 17:14:43 -03:00
|
|
|
log.warn("'%s' not a regular file -- skipping" % file)
|
2000-09-05 23:18:59 -03:00
|
|
|
else:
|
2000-09-30 15:27:54 -03:00
|
|
|
dest = os.path.join(base_dir, file)
|
|
|
|
self.copy_file(file, dest, link=link)
|
2000-02-17 19:56:15 -04:00
|
|
|
|
2001-03-21 23:10:05 -04:00
|
|
|
self.distribution.metadata.write_pkg_info(base_dir)
|
2001-12-06 17:01:19 -04:00
|
|
|
|
2000-02-17 19:56:15 -04:00
|
|
|
# make_release_tree ()
|
|
|
|
|
|
|
|
def make_distribution (self):
|
2000-06-07 21:46:45 -03:00
|
|
|
"""Create the source distribution(s). First, we create the release
|
|
|
|
tree with 'make_release_tree()'; then, we create all required
|
|
|
|
archive files (according to 'self.formats') from the release tree.
|
|
|
|
Finally, we clean up by blowing away the release tree (unless
|
2000-09-24 22:51:01 -03:00
|
|
|
'self.keep_temp' is true). The list of archive files created is
|
2000-06-07 21:46:45 -03:00
|
|
|
stored so it can be retrieved later by 'get_archive_files()'.
|
|
|
|
"""
|
2000-03-30 22:50:04 -04:00
|
|
|
# Don't warn about missing meta-data here -- should be (and is!)
|
|
|
|
# done elsewhere.
|
2000-04-21 23:51:25 -03:00
|
|
|
base_dir = self.distribution.get_fullname()
|
2000-07-05 00:06:46 -03:00
|
|
|
base_name = os.path.join(self.dist_dir, base_dir)
|
2000-02-17 19:56:15 -04:00
|
|
|
|
2000-09-30 15:27:54 -03:00
|
|
|
self.make_release_tree(base_dir, self.filelist.files)
|
2000-05-31 22:10:56 -03:00
|
|
|
archive_files = [] # remember names of files we create
|
2000-02-17 19:56:15 -04:00
|
|
|
for fmt in self.formats:
|
2000-09-30 15:27:54 -03:00
|
|
|
file = self.make_archive(base_name, fmt, base_dir=base_dir)
|
2000-05-31 22:10:56 -03:00
|
|
|
archive_files.append(file)
|
|
|
|
|
|
|
|
self.archive_files = archive_files
|
2000-02-17 19:56:15 -04:00
|
|
|
|
2000-09-24 22:51:01 -03:00
|
|
|
if not self.keep_temp:
|
2002-06-04 17:14:43 -03:00
|
|
|
dir_util.remove_tree(base_dir, dry_run=self.dry_run)
|
2000-02-17 19:56:15 -04:00
|
|
|
|
2000-05-31 22:10:56 -03:00
|
|
|
def get_archive_files (self):
|
|
|
|
"""Return the list of archive files created when the command
|
|
|
|
was run, or None if the command hasn't run yet.
|
|
|
|
"""
|
|
|
|
return self.archive_files
|
|
|
|
|
2000-05-24 22:10:04 -03:00
|
|
|
# class sdist
|