2015-11-25 01:25:01 +00:00
|
|
|
from glob import glob
|
|
|
|
from distutils import log
|
|
|
|
import distutils.command.sdist as orig
|
2013-10-11 17:28:32 +00:00
|
|
|
import os
|
|
|
|
import sys
|
2015-11-25 01:25:01 +00:00
|
|
|
|
|
|
|
from setuptools.compat import PY3
|
|
|
|
from setuptools.utils import cs_path_exists
|
2013-10-11 17:28:32 +00:00
|
|
|
|
2014-08-12 08:44:01 +00:00
|
|
|
import pkg_resources
|
2013-10-11 17:28:32 +00:00
|
|
|
|
2015-11-25 01:25:01 +00:00
|
|
|
READMES = 'README', 'README.rst', 'README.txt'
|
2013-10-11 17:28:32 +00:00
|
|
|
|
2015-11-25 01:25:01 +00:00
|
|
|
_default_revctrl = list
|
2013-10-11 17:28:32 +00:00
|
|
|
|
|
|
|
def walk_revctrl(dirname=''):
|
|
|
|
"""Find all files under revision control"""
|
|
|
|
for ep in pkg_resources.iter_entry_points('setuptools.file_finders'):
|
|
|
|
for item in ep.load()(dirname):
|
|
|
|
yield item
|
|
|
|
|
|
|
|
|
2015-11-25 01:25:01 +00:00
|
|
|
class sdist(orig.sdist):
|
2013-10-11 17:28:32 +00:00
|
|
|
"""Smart sdist that finds anything supported by revision control"""
|
|
|
|
|
|
|
|
user_options = [
|
|
|
|
('formats=', None,
|
|
|
|
"formats for source distribution (comma-separated list)"),
|
|
|
|
('keep-temp', 'k',
|
|
|
|
"keep the distribution tree around after creating " +
|
|
|
|
"archive file(s)"),
|
|
|
|
('dist-dir=', 'd',
|
|
|
|
"directory to put the source distribution archive(s) in "
|
|
|
|
"[default: dist]"),
|
2015-11-25 01:25:01 +00:00
|
|
|
]
|
2013-10-11 17:28:32 +00:00
|
|
|
|
|
|
|
negative_opt = {}
|
|
|
|
|
|
|
|
def run(self):
|
|
|
|
self.run_command('egg_info')
|
|
|
|
ei_cmd = self.get_finalized_command('egg_info')
|
|
|
|
self.filelist = ei_cmd.filelist
|
2015-11-25 01:25:01 +00:00
|
|
|
self.filelist.append(os.path.join(ei_cmd.egg_info, 'SOURCES.txt'))
|
2013-10-11 17:28:32 +00:00
|
|
|
self.check_readme()
|
|
|
|
|
|
|
|
# Run sub commands
|
|
|
|
for cmd_name in self.get_sub_commands():
|
|
|
|
self.run_command(cmd_name)
|
|
|
|
|
|
|
|
# Call check_metadata only if no 'check' command
|
|
|
|
# (distutils <= 2.6)
|
|
|
|
import distutils.command
|
2015-11-25 01:25:01 +00:00
|
|
|
|
2013-10-11 17:28:32 +00:00
|
|
|
if 'check' not in distutils.command.__all__:
|
|
|
|
self.check_metadata()
|
|
|
|
|
|
|
|
self.make_distribution()
|
|
|
|
|
2015-11-25 01:25:01 +00:00
|
|
|
dist_files = getattr(self.distribution, 'dist_files', [])
|
2013-10-11 17:28:32 +00:00
|
|
|
for file in self.archive_files:
|
|
|
|
data = ('sdist', '', file)
|
|
|
|
if data not in dist_files:
|
|
|
|
dist_files.append(data)
|
|
|
|
|
|
|
|
def __read_template_hack(self):
|
|
|
|
# This grody hack closes the template file (MANIFEST.in) if an
|
|
|
|
# exception occurs during read_template.
|
|
|
|
# Doing so prevents an error when easy_install attempts to delete the
|
|
|
|
# file.
|
|
|
|
try:
|
2015-11-25 01:25:01 +00:00
|
|
|
orig.sdist.read_template(self)
|
2013-10-11 17:28:32 +00:00
|
|
|
except:
|
2015-11-25 01:25:01 +00:00
|
|
|
_, _, tb = sys.exc_info()
|
|
|
|
tb.tb_next.tb_frame.f_locals['template'].close()
|
2013-10-11 17:28:32 +00:00
|
|
|
raise
|
2015-11-25 01:25:01 +00:00
|
|
|
|
2013-10-11 17:28:32 +00:00
|
|
|
# Beginning with Python 2.7.2, 3.1.4, and 3.2.1, this leaky file handle
|
|
|
|
# has been fixed, so only override the method if we're using an earlier
|
|
|
|
# Python.
|
|
|
|
has_leaky_handle = (
|
2015-11-25 01:25:01 +00:00
|
|
|
sys.version_info < (2, 7, 2)
|
|
|
|
or (3, 0) <= sys.version_info < (3, 1, 4)
|
|
|
|
or (3, 2) <= sys.version_info < (3, 2, 1)
|
2013-10-11 17:28:32 +00:00
|
|
|
)
|
|
|
|
if has_leaky_handle:
|
|
|
|
read_template = __read_template_hack
|
|
|
|
|
|
|
|
def add_defaults(self):
|
|
|
|
standards = [READMES,
|
|
|
|
self.distribution.script_name]
|
|
|
|
for fn in standards:
|
|
|
|
if isinstance(fn, tuple):
|
|
|
|
alts = fn
|
|
|
|
got_it = 0
|
|
|
|
for fn in alts:
|
2015-11-25 01:25:01 +00:00
|
|
|
if cs_path_exists(fn):
|
2013-10-11 17:28:32 +00:00
|
|
|
got_it = 1
|
|
|
|
self.filelist.append(fn)
|
|
|
|
break
|
|
|
|
|
|
|
|
if not got_it:
|
|
|
|
self.warn("standard file not found: should have one of " +
|
|
|
|
', '.join(alts))
|
|
|
|
else:
|
2015-11-25 01:25:01 +00:00
|
|
|
if cs_path_exists(fn):
|
2013-10-11 17:28:32 +00:00
|
|
|
self.filelist.append(fn)
|
|
|
|
else:
|
|
|
|
self.warn("standard file '%s' not found" % fn)
|
|
|
|
|
|
|
|
optional = ['test/test*.py', 'setup.cfg']
|
|
|
|
for pattern in optional:
|
2015-11-25 01:25:01 +00:00
|
|
|
files = list(filter(cs_path_exists, glob(pattern)))
|
2013-10-11 17:28:32 +00:00
|
|
|
if files:
|
|
|
|
self.filelist.extend(files)
|
|
|
|
|
|
|
|
# getting python files
|
|
|
|
if self.distribution.has_pure_modules():
|
|
|
|
build_py = self.get_finalized_command('build_py')
|
|
|
|
self.filelist.extend(build_py.get_source_files())
|
|
|
|
# This functionality is incompatible with include_package_data, and
|
|
|
|
# will in fact create an infinite recursion if include_package_data
|
|
|
|
# is True. Use of include_package_data will imply that
|
|
|
|
# distutils-style automatic handling of package_data is disabled
|
|
|
|
if not self.distribution.include_package_data:
|
|
|
|
for _, src_dir, _, filenames in build_py.data_files:
|
|
|
|
self.filelist.extend([os.path.join(src_dir, filename)
|
|
|
|
for filename in filenames])
|
|
|
|
|
|
|
|
if self.distribution.has_ext_modules():
|
|
|
|
build_ext = self.get_finalized_command('build_ext')
|
|
|
|
self.filelist.extend(build_ext.get_source_files())
|
|
|
|
|
|
|
|
if self.distribution.has_c_libraries():
|
|
|
|
build_clib = self.get_finalized_command('build_clib')
|
|
|
|
self.filelist.extend(build_clib.get_source_files())
|
|
|
|
|
|
|
|
if self.distribution.has_scripts():
|
|
|
|
build_scripts = self.get_finalized_command('build_scripts')
|
|
|
|
self.filelist.extend(build_scripts.get_source_files())
|
|
|
|
|
|
|
|
def check_readme(self):
|
|
|
|
for f in READMES:
|
|
|
|
if os.path.exists(f):
|
|
|
|
return
|
|
|
|
else:
|
|
|
|
self.warn(
|
2015-11-25 01:25:01 +00:00
|
|
|
"standard file not found: should have one of " +
|
|
|
|
', '.join(READMES)
|
2013-10-11 17:28:32 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
def make_release_tree(self, base_dir, files):
|
2015-11-25 01:25:01 +00:00
|
|
|
orig.sdist.make_release_tree(self, base_dir, files)
|
2013-10-11 17:28:32 +00:00
|
|
|
|
|
|
|
# Save any egg_info command line options used to create this sdist
|
|
|
|
dest = os.path.join(base_dir, 'setup.cfg')
|
2015-11-25 01:25:01 +00:00
|
|
|
if hasattr(os, 'link') and os.path.exists(dest):
|
2013-10-11 17:28:32 +00:00
|
|
|
# unlink and re-copy, since it might be hard-linked, and
|
|
|
|
# we don't want to change the source version
|
|
|
|
os.unlink(dest)
|
|
|
|
self.copy_file('setup.cfg', dest)
|
|
|
|
|
|
|
|
self.get_finalized_command('egg_info').save_version_info(dest)
|
|
|
|
|
|
|
|
def _manifest_is_not_generated(self):
|
|
|
|
# check for special comment used in 2.7.1 and higher
|
|
|
|
if not os.path.isfile(self.manifest):
|
|
|
|
return False
|
|
|
|
|
|
|
|
fp = open(self.manifest, 'rbU')
|
|
|
|
try:
|
|
|
|
first_line = fp.readline()
|
|
|
|
finally:
|
|
|
|
fp.close()
|
2015-11-25 01:25:01 +00:00
|
|
|
return (first_line !=
|
|
|
|
'# file GENERATED by distutils, do NOT edit\n'.encode())
|
2013-10-11 17:28:32 +00:00
|
|
|
|
|
|
|
def read_manifest(self):
|
|
|
|
"""Read the manifest file (named by 'self.manifest') and use it to
|
|
|
|
fill in 'self.filelist', the list of files to include in the source
|
|
|
|
distribution.
|
|
|
|
"""
|
|
|
|
log.info("reading manifest file '%s'", self.manifest)
|
|
|
|
manifest = open(self.manifest, 'rbU')
|
|
|
|
for line in manifest:
|
|
|
|
# The manifest must contain UTF-8. See #303.
|
2015-11-25 01:25:01 +00:00
|
|
|
if PY3:
|
2013-10-11 17:28:32 +00:00
|
|
|
try:
|
|
|
|
line = line.decode('UTF-8')
|
|
|
|
except UnicodeDecodeError:
|
|
|
|
log.warn("%r not UTF-8 decodable -- skipping" % line)
|
|
|
|
continue
|
|
|
|
# ignore comments and blank lines
|
|
|
|
line = line.strip()
|
|
|
|
if line.startswith('#') or not line:
|
|
|
|
continue
|
|
|
|
self.filelist.append(line)
|
|
|
|
manifest.close()
|