2000-02-17 19:56:15 -04:00
|
|
|
"""distutils.command.sdist
|
|
|
|
|
|
|
|
Implements the Distutils 'sdist' command (create a source distribution)."""
|
|
|
|
|
2000-03-01 21:49:45 -04:00
|
|
|
__revision__ = "$Id$"
|
2000-02-17 19:56:15 -04:00
|
|
|
|
2009-12-20 21:22:46 -04:00
|
|
|
import os
|
|
|
|
import string
|
2009-01-03 20:04:49 -04:00
|
|
|
import sys
|
2000-02-17 19:56:15 -04:00
|
|
|
from glob import glob
|
2009-05-16 13:37:06 -03:00
|
|
|
from warnings import warn
|
|
|
|
|
2000-02-17 19:56:15 -04:00
|
|
|
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
|
2009-12-20 21:22:46 -04:00
|
|
|
from distutils.errors import (DistutilsPlatformError, DistutilsOptionError,
|
|
|
|
DistutilsTemplateError)
|
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
|
2009-02-17 05:42:44 -04:00
|
|
|
from distutils.util import convert_path
|
2000-02-17 19:56:15 -04:00
|
|
|
|
2009-05-14 09:40:59 -03:00
|
|
|
def show_formats():
|
2000-06-23 22:23:37 -03:00
|
|
|
"""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
|
2009-05-14 09:40:59 -03:00
|
|
|
formats = []
|
2000-06-23 22:23:37 -03:00
|
|
|
for format in ARCHIVE_FORMATS.keys():
|
|
|
|
formats.append(("formats=" + format, None,
|
|
|
|
ARCHIVE_FORMATS[format][2]))
|
|
|
|
formats.sort()
|
2009-05-14 09:40:59 -03:00
|
|
|
FancyGetopt(formats).print_help(
|
2000-06-23 22:23:37 -03:00
|
|
|
"List of available source distribution formats:")
|
|
|
|
|
2009-05-14 11:56:14 -03:00
|
|
|
class sdist(Command):
|
2000-02-17 19:56:15 -04:00
|
|
|
|
|
|
|
description = "create a source distribution (tarball, zip file, etc.)"
|
|
|
|
|
2009-05-16 13:37:06 -03:00
|
|
|
def checking_metadata(self):
|
|
|
|
"""Callable used for the check sub-command.
|
|
|
|
|
|
|
|
Placed here so user_options can view it"""
|
|
|
|
return self.metadata_check
|
|
|
|
|
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',
|
2010-05-17 07:54:43 -03:00
|
|
|
"forcibly regenerate the manifest and carry on as usual. "
|
|
|
|
"Deprecated: now the manifest is always regenerated."),
|
2000-02-17 20:25:39 -04:00
|
|
|
('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]"),
|
2009-05-16 13:37:06 -03:00
|
|
|
('medata-check', None,
|
|
|
|
"Ensure that all required elements of meta-data "
|
|
|
|
"are supplied. Warn if any missing. [default]"),
|
2009-10-02 20:49:48 -03:00
|
|
|
('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]"),
|
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',
|
2009-05-16 13:37:06 -03:00
|
|
|
'keep-temp', 'metadata-check']
|
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
|
|
|
|
2009-05-14 11:56:14 -03:00
|
|
|
default_format = {'posix': 'gztar',
|
|
|
|
'nt': 'zip' }
|
2000-02-17 19:56:15 -04:00
|
|
|
|
2009-05-16 13:37:06 -03:00
|
|
|
sub_commands = [('check', checking_metadata)]
|
|
|
|
|
2009-05-14 11:56:14 -03: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
|
2009-05-16 13:37:06 -03:00
|
|
|
self.metadata_check = 1
|
2009-10-02 20:49:48 -03:00
|
|
|
self.owner = None
|
|
|
|
self.group = None
|
2000-05-31 22:10:56 -03:00
|
|
|
|
2009-05-14 11:56:14 -03: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"
|
|
|
|
|
2009-05-14 11:56:14 -03: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
|
|
|
|
2009-05-16 13:37:06 -03:00
|
|
|
# Run sub commands
|
|
|
|
for cmd_name in self.get_sub_commands():
|
|
|
|
self.run_command(cmd_name)
|
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
|
|
|
|
2009-05-14 11:56:14 -03:00
|
|
|
def check_metadata(self):
|
2009-05-16 13:37:06 -03:00
|
|
|
"""Deprecated API."""
|
|
|
|
warn("distutils.command.sdist.check_metadata is deprecated, \
|
|
|
|
use the check command instead", PendingDeprecationWarning)
|
|
|
|
check = self.distribution.get_command_obj('check')
|
|
|
|
check.ensure_finalized()
|
|
|
|
check.run()
|
2000-02-17 19:56:15 -04:00
|
|
|
|
2009-05-14 11:56:14 -03:00
|
|
|
def get_file_list(self):
|
2000-02-17 19:56:15 -04:00
|
|
|
"""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
|
2010-05-17 07:06:20 -03:00
|
|
|
depends on the user's options.
|
2000-06-07 21:24:01 -03:00
|
|
|
"""
|
2010-05-17 07:06:20 -03:00
|
|
|
# new behavior:
|
|
|
|
# the file list is recalculated everytime because
|
|
|
|
# even if MANIFEST.in or setup.py are not changed
|
|
|
|
# the user might have added some files in the tree that
|
|
|
|
# need to be included.
|
|
|
|
#
|
|
|
|
# This makes --force the default and only behavior.
|
2000-07-29 22:30:31 -03:00
|
|
|
template_exists = os.path.isfile(self.template)
|
2010-05-17 07:06:20 -03:00
|
|
|
if not template_exists:
|
|
|
|
self.warn(("manifest template '%s' does not exist " +
|
|
|
|
"(using default file list)") %
|
|
|
|
self.template)
|
|
|
|
self.filelist.findall()
|
|
|
|
|
|
|
|
if self.use_defaults:
|
|
|
|
self.add_defaults()
|
|
|
|
|
2000-02-17 19:56:15 -04:00
|
|
|
if template_exists:
|
2010-05-17 07:06:20 -03:00
|
|
|
self.read_template()
|
|
|
|
|
|
|
|
if self.prune:
|
|
|
|
self.prune_file_list()
|
|
|
|
|
|
|
|
self.filelist.sort()
|
|
|
|
self.filelist.remove_duplicates()
|
|
|
|
self.write_manifest()
|
2000-02-17 19:56:15 -04:00
|
|
|
|
2009-05-14 11:56:14 -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
|
2009-02-16 17:38:01 -04:00
|
|
|
- all files pointed by package_data (build_py)
|
|
|
|
- all files defined in data_files.
|
|
|
|
- all files defined as scripts.
|
2000-06-07 21:46:45 -03:00
|
|
|
- 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:
|
2009-12-20 21:22:46 -04:00
|
|
|
if isinstance(fn, tuple):
|
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
|
|
|
|
2009-02-16 17:38:01 -04:00
|
|
|
# build_py is used to get:
|
|
|
|
# - python modules
|
|
|
|
# - files defined in package_data
|
|
|
|
build_py = self.get_finalized_command('build_py')
|
|
|
|
|
|
|
|
# getting python files
|
2000-03-30 22:50:04 -04:00
|
|
|
if self.distribution.has_pure_modules():
|
2000-09-30 15:27:54 -03:00
|
|
|
self.filelist.extend(build_py.get_source_files())
|
2000-02-17 19:56:15 -04:00
|
|
|
|
2009-02-16 17:38:01 -04:00
|
|
|
# getting package_data files
|
|
|
|
# (computed in build_py.data_files by build_py.finalize_options)
|
|
|
|
for pkg, src_dir, build_dir, filenames in build_py.data_files:
|
|
|
|
for filename in filenames:
|
|
|
|
self.filelist.append(os.path.join(src_dir, filename))
|
|
|
|
|
|
|
|
# getting distribution.data_files
|
|
|
|
if self.distribution.has_data_files():
|
2009-02-17 05:42:44 -04:00
|
|
|
for item in self.distribution.data_files:
|
|
|
|
if isinstance(item, str): # plain file
|
|
|
|
item = convert_path(item)
|
|
|
|
if os.path.isfile(item):
|
|
|
|
self.filelist.append(item)
|
|
|
|
else: # a (dirname, filenames) tuple
|
|
|
|
dirname, filenames = item
|
|
|
|
for f in filenames:
|
2009-02-17 19:06:51 -04:00
|
|
|
f = convert_path(f)
|
2009-02-17 05:42:44 -04:00
|
|
|
if os.path.isfile(f):
|
|
|
|
self.filelist.append(f)
|
2009-02-16 17:38:01 -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())
|
2004-03-25 18:04:52 -04:00
|
|
|
|
|
|
|
if self.distribution.has_scripts():
|
|
|
|
build_scripts = self.get_finalized_command('build_scripts')
|
|
|
|
self.filelist.extend(build_scripts.get_source_files())
|
2000-02-17 19:56:15 -04:00
|
|
|
|
2009-05-14 11:56:14 -03: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
|
|
|
|
2009-05-14 11:56:14 -03:00
|
|
|
def prune_file_list(self):
|
2000-06-07 22:06:02 -03:00
|
|
|
"""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)
|
2008-03-06 02:47:18 -04:00
|
|
|
* any RCS, CVS, .svn, .hg, .git, .bzr, _darcs 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)
|
2000-06-07 21:08:14 -03:00
|
|
|
|
2009-01-03 20:04:49 -04:00
|
|
|
# pruning out vcs directories
|
|
|
|
# both separators are used under win32
|
2009-01-04 06:37:52 -04:00
|
|
|
if sys.platform == 'win32':
|
|
|
|
seps = r'/|\\'
|
|
|
|
else:
|
|
|
|
seps = '/'
|
|
|
|
|
|
|
|
vcs_dirs = ['RCS', 'CVS', r'\.svn', r'\.hg', r'\.git', r'\.bzr',
|
|
|
|
'_darcs']
|
2009-01-03 20:04:49 -04:00
|
|
|
vcs_ptrn = r'(^|%s)(%s)(%s).*' % (seps, '|'.join(vcs_dirs), seps)
|
|
|
|
self.filelist.exclude_pattern(vcs_ptrn, is_regex=1)
|
2000-06-07 21:08:14 -03:00
|
|
|
|
2009-05-14 11:56:14 -03: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
|
|
|
|
2009-05-14 11:56:14 -03:00
|
|
|
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)
|
2008-02-21 10:23:38 -04:00
|
|
|
manifest.close()
|
2000-02-17 19:56:15 -04:00
|
|
|
|
2009-05-14 11:56:14 -03: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
|
|
|
|
2009-05-14 11:56:14 -03:00
|
|
|
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
|
2009-01-25 19:34:00 -04:00
|
|
|
# tar archive must be created last to avoid overwrite and remove
|
|
|
|
if 'tar' in self.formats:
|
|
|
|
self.formats.append(self.formats.pop(self.formats.index('tar')))
|
|
|
|
|
2000-02-17 19:56:15 -04:00
|
|
|
for fmt in self.formats:
|
2009-10-02 20:49:48 -03:00
|
|
|
file = self.make_archive(base_name, fmt, base_dir=base_dir,
|
|
|
|
owner=self.owner, group=self.group)
|
2000-05-31 22:10:56 -03:00
|
|
|
archive_files.append(file)
|
2005-03-23 14:54:36 -04:00
|
|
|
self.distribution.dist_files.append(('sdist', '', file))
|
2000-05-31 22:10:56 -03:00
|
|
|
|
|
|
|
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
|
|
|
|
2009-05-14 11:56:14 -03:00
|
|
|
def get_archive_files(self):
|
2000-05-31 22:10:56 -03:00
|
|
|
"""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
|