mirror of https://github.com/python/cpython
Changed to use the new 'has_pure_modules()' and 'has_ext_modules()' methods
provided by Distribution. Cosmetic and error message tweaks. Simplified 'make_release_tree()': * extracted 'distutils.util.create_tree()' * don't have to do hard-linking ourselves -- it's now handled by 'distutils.util.copy_file()' (although the detection of whether hard linking is available still needs to be factored out) Removed 'make_tarball()' and 'make_zipfile()' entirely -- their role is now amply filled by 'distutils.util.make_archive()'. Simplified 'make_distribution()': * use Distribution's new 'get_full_name()' method * use 'make_archive()' instead of if/elif/.../else on the archive format
This commit is contained in:
parent
43da798b42
commit
578c10d9a5
|
@ -11,7 +11,8 @@ import fnmatch
|
||||||
from types import *
|
from types import *
|
||||||
from glob import glob
|
from glob import glob
|
||||||
from distutils.core import Command
|
from distutils.core import Command
|
||||||
from distutils.util import newer, remove_tree, make_tarball, make_zipfile
|
from distutils.util import \
|
||||||
|
newer, remove_tree, make_tarball, make_zipfile, create_tree
|
||||||
from distutils.text_file import TextFile
|
from distutils.text_file import TextFile
|
||||||
from distutils.errors import DistutilsExecError
|
from distutils.errors import DistutilsExecError
|
||||||
|
|
||||||
|
@ -78,8 +79,8 @@ class sdist (Command):
|
||||||
self.formats = [self.default_format[os.name]]
|
self.formats = [self.default_format[os.name]]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise DistutilsPlatformError, \
|
raise DistutilsPlatformError, \
|
||||||
"don't know how to build source distributions on " + \
|
"don't know how to create source distributions " + \
|
||||||
"%s platform" % os.name
|
"on platform %s" % os.name
|
||||||
elif type (self.formats) is StringType:
|
elif type (self.formats) is StringType:
|
||||||
self.formats = string.split (self.formats, ',')
|
self.formats = string.split (self.formats, ',')
|
||||||
|
|
||||||
|
@ -219,18 +220,15 @@ class sdist (Command):
|
||||||
if files:
|
if files:
|
||||||
self.files.extend (files)
|
self.files.extend (files)
|
||||||
|
|
||||||
if self.distribution.packages or self.distribution.py_modules:
|
if self.distribution.has_pure_modules():
|
||||||
build_py = self.find_peer ('build_py')
|
build_py = self.find_peer ('build_py')
|
||||||
build_py.ensure_ready ()
|
|
||||||
self.files.extend (build_py.get_source_files ())
|
self.files.extend (build_py.get_source_files ())
|
||||||
|
|
||||||
if self.distribution.ext_modules:
|
if self.distribution.has_ext_modules():
|
||||||
build_ext = self.find_peer ('build_ext')
|
build_ext = self.find_peer ('build_ext')
|
||||||
build_ext.ensure_ready ()
|
|
||||||
self.files.extend (build_ext.get_source_files ())
|
self.files.extend (build_ext.get_source_files ())
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def search_dir (self, dir, pattern=None):
|
def search_dir (self, dir, pattern=None):
|
||||||
"""Recursively find files under 'dir' matching 'pattern' (a string
|
"""Recursively find files under 'dir' matching 'pattern' (a string
|
||||||
containing a Unix-style glob pattern). If 'pattern' is None,
|
containing a Unix-style glob pattern). If 'pattern' is None,
|
||||||
|
@ -465,16 +463,10 @@ class sdist (Command):
|
||||||
|
|
||||||
def make_release_tree (self, base_dir, files):
|
def make_release_tree (self, base_dir, files):
|
||||||
|
|
||||||
# First get the list of directories to create
|
# Create all the directories under 'base_dir' necessary to
|
||||||
need_dir = {}
|
# put 'files' there.
|
||||||
for file in files:
|
create_tree (base_dir, files,
|
||||||
need_dir[os.path.join (base_dir, os.path.dirname (file))] = 1
|
verbose=self.verbose, dry_run=self.dry_run)
|
||||||
need_dirs = need_dir.keys()
|
|
||||||
need_dirs.sort()
|
|
||||||
|
|
||||||
# Now create them
|
|
||||||
for dir in need_dirs:
|
|
||||||
self.mkpath (dir)
|
|
||||||
|
|
||||||
# And walk over the list of files, either making a hard link (if
|
# 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
|
# os.link exists) to each one that doesn't already exist in its
|
||||||
|
@ -483,44 +475,26 @@ class sdist (Command):
|
||||||
# out-of-date, because by default we blow away 'base_dir' when
|
# out-of-date, because by default we blow away 'base_dir' when
|
||||||
# we're done making the distribution archives.)
|
# we're done making the distribution archives.)
|
||||||
|
|
||||||
try:
|
if hasattr (os, 'link'): # can make hard links on this system
|
||||||
link = os.link
|
link = 'hard'
|
||||||
msg = "making hard links in %s..." % base_dir
|
msg = "making hard links in %s..." % base_dir
|
||||||
except AttributeError:
|
else: # nope, have to copy
|
||||||
link = 0
|
link = None
|
||||||
msg = "copying files to %s..." % base_dir
|
msg = "copying files to %s..." % base_dir
|
||||||
|
|
||||||
self.announce (msg)
|
self.announce (msg)
|
||||||
for file in files:
|
for file in files:
|
||||||
dest = os.path.join (base_dir, file)
|
dest = os.path.join (base_dir, file)
|
||||||
if link:
|
self.copy_file (file, dest, link=link)
|
||||||
if not os.path.exists (dest):
|
|
||||||
self.execute (os.link, (file, dest),
|
|
||||||
"linking %s -> %s" % (file, dest))
|
|
||||||
else:
|
|
||||||
self.copy_file (file, dest)
|
|
||||||
|
|
||||||
# make_release_tree ()
|
# make_release_tree ()
|
||||||
|
|
||||||
|
|
||||||
def make_tarball (self, base_dir, compress):
|
|
||||||
make_tarball (base_dir, compress, self.verbose, self.dry_run)
|
|
||||||
|
|
||||||
def make_zipfile (self, base_dir):
|
|
||||||
make_zipfile (base_dir, self.verbose, self.dry_run)
|
|
||||||
|
|
||||||
|
|
||||||
def make_distribution (self):
|
def make_distribution (self):
|
||||||
|
|
||||||
# Don't warn about missing meta-data here -- should be done
|
# Don't warn about missing meta-data here -- should be (and is!)
|
||||||
# elsewhere.
|
# done elsewhere.
|
||||||
name = self.distribution.name or "UNKNOWN"
|
base_dir = self.distribution.get_full_name()
|
||||||
version = self.distribution.version
|
|
||||||
|
|
||||||
if version:
|
|
||||||
base_dir = "%s-%s" % (name, version)
|
|
||||||
else:
|
|
||||||
base_dir = name
|
|
||||||
|
|
||||||
# Remove any files that match "base_dir" from the fileset -- we
|
# Remove any files that match "base_dir" from the fileset -- we
|
||||||
# don't want to go distributing the distribution inside itself!
|
# don't want to go distributing the distribution inside itself!
|
||||||
|
@ -528,14 +502,7 @@ class sdist (Command):
|
||||||
|
|
||||||
self.make_release_tree (base_dir, self.files)
|
self.make_release_tree (base_dir, self.files)
|
||||||
for fmt in self.formats:
|
for fmt in self.formats:
|
||||||
if fmt == 'gztar':
|
self.make_archive (base_dir, fmt, base_dir=base_dir)
|
||||||
self.make_tarball (base_dir, compress='gzip')
|
|
||||||
elif fmt == 'ztar':
|
|
||||||
self.make_tarball (base_dir, compress='compress')
|
|
||||||
elif fmt == 'tar':
|
|
||||||
self.make_tarball (base_dir, compress=None)
|
|
||||||
elif fmt == 'zip':
|
|
||||||
self.make_zipfile (base_dir)
|
|
||||||
|
|
||||||
if not self.keep_tree:
|
if not self.keep_tree:
|
||||||
remove_tree (base_dir, self.verbose, self.dry_run)
|
remove_tree (base_dir, self.verbose, self.dry_run)
|
||||||
|
|
Loading…
Reference in New Issue