aboutsummaryrefslogtreecommitdiffstats
path: root/setuptools/command
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2014-09-29 21:14:51 -0400
committerJason R. Coombs <jaraco@jaraco.com>2014-09-29 21:14:51 -0400
commit626fa69fb0470710e870628afd0cb7ec0ba96ddf (patch)
treebefcacc09c560133266eb5a1757a45ea43d93453 /setuptools/command
parent96aed21b42121acde68dd6b3732c3fbae0903569 (diff)
parent9e7f35fec4178dea678693cb768b6076d45e7ddd (diff)
downloadexternal_python_setuptools-626fa69fb0470710e870628afd0cb7ec0ba96ddf.tar.gz
external_python_setuptools-626fa69fb0470710e870628afd0cb7ec0ba96ddf.tar.bz2
external_python_setuptools-626fa69fb0470710e870628afd0cb7ec0ba96ddf.zip
Merge with 6.0.2
--HG-- branch : feature/issue-229
Diffstat (limited to 'setuptools/command')
-rwxr-xr-xsetuptools/command/egg_info.py2
-rw-r--r--setuptools/command/install_lib.py83
-rwxr-xr-xsetuptools/command/sdist.py8
3 files changed, 74 insertions, 19 deletions
diff --git a/setuptools/command/egg_info.py b/setuptools/command/egg_info.py
index debb52e4..14ff0763 100755
--- a/setuptools/command/egg_info.py
+++ b/setuptools/command/egg_info.py
@@ -390,7 +390,7 @@ def write_toplevel_names(cmd, basename, filename):
for k in cmd.distribution.iter_distribution_names()
]
)
- cmd.write_file("top-level names", filename, '\n'.join(pkgs) + '\n')
+ cmd.write_file("top-level names", filename, '\n'.join(sorted(pkgs)) + '\n')
def overwrite_arg(cmd, basename, filename):
diff --git a/setuptools/command/install_lib.py b/setuptools/command/install_lib.py
index d7e117f0..9b772227 100644
--- a/setuptools/command/install_lib.py
+++ b/setuptools/command/install_lib.py
@@ -1,6 +1,7 @@
-import distutils.command.install_lib as orig
import os
-
+import imp
+from itertools import product, starmap
+import distutils.command.install_lib as orig
class install_lib(orig.install_lib):
"""Don't add compiled flags to filenames of non-Python files"""
@@ -13,19 +14,71 @@ class install_lib(orig.install_lib):
self.byte_compile(outfiles)
def get_exclusions(self):
- exclude = {}
- nsp = self.distribution.namespace_packages
- svem = (nsp and self.get_finalized_command('install')
- .single_version_externally_managed)
- if svem:
- for pkg in nsp:
- parts = pkg.split('.')
- while parts:
- pkgdir = os.path.join(self.install_dir, *parts)
- for f in '__init__.py', '__init__.pyc', '__init__.pyo':
- exclude[os.path.join(pkgdir, f)] = 1
- parts.pop()
- return exclude
+ """
+ Return a collections.Sized collections.Container of paths to be
+ excluded for single_version_externally_managed installations.
+ """
+ all_packages = (
+ pkg
+ for ns_pkg in self._get_SVEM_NSPs()
+ for pkg in self._all_packages(ns_pkg)
+ )
+
+ excl_specs = product(all_packages, self._gen_exclusion_paths())
+ return set(starmap(self._exclude_pkg_path, excl_specs))
+
+ def _exclude_pkg_path(self, pkg, exclusion_path):
+ """
+ Given a package name and exclusion path within that package,
+ compute the full exclusion path.
+ """
+ parts = pkg.split('.') + [exclusion_path]
+ return os.path.join(self.install_dir, *parts)
+
+ @staticmethod
+ def _all_packages(pkg_name):
+ """
+ >>> list(install_lib._all_packages('foo.bar.baz'))
+ ['foo.bar.baz', 'foo.bar', 'foo']
+ """
+ while pkg_name:
+ yield pkg_name
+ pkg_name, sep, child = pkg_name.rpartition('.')
+
+ def _get_SVEM_NSPs(self):
+ """
+ Get namespace packages (list) but only for
+ single_version_externally_managed installations and empty otherwise.
+ """
+ # TODO: is it necessary to short-circuit here? i.e. what's the cost
+ # if get_finalized_command is called even when namespace_packages is
+ # False?
+ if not self.distribution.namespace_packages:
+ return []
+
+ install_cmd = self.get_finalized_command('install')
+ svem = install_cmd.single_version_externally_managed
+
+ return self.distribution.namespace_packages if svem else []
+
+ @staticmethod
+ def _gen_exclusion_paths():
+ """
+ Generate file paths to be excluded for namespace packages (bytecode
+ cache files).
+ """
+ # always exclude the package module itself
+ yield '__init__.py'
+
+ yield '__init__.pyc'
+ yield '__init__.pyo'
+
+ if not hasattr(imp, 'get_tag'):
+ return
+
+ base = os.path.join('__pycache__', '__init__.' + imp.get_tag())
+ yield base + '.pyc'
+ yield base + '.pyo'
def copy_tree(
self, infile, outfile,
diff --git a/setuptools/command/sdist.py b/setuptools/command/sdist.py
index c99ad9b1..a15582c3 100755
--- a/setuptools/command/sdist.py
+++ b/setuptools/command/sdist.py
@@ -9,6 +9,8 @@ import sys
import six
from setuptools import svn_utils
+from setuptools.utils import cs_path_exists
+
import pkg_resources
READMES = ('README', 'README.rst', 'README.txt')
@@ -147,7 +149,7 @@ class sdist(orig.sdist):
alts = fn
got_it = 0
for fn in alts:
- if os.path.exists(fn):
+ if cs_path_exists(fn):
got_it = 1
self.filelist.append(fn)
break
@@ -156,14 +158,14 @@ class sdist(orig.sdist):
self.warn("standard file not found: should have one of " +
', '.join(alts))
else:
- if os.path.exists(fn):
+ if cs_path_exists(fn):
self.filelist.append(fn)
else:
self.warn("standard file '%s' not found" % fn)
optional = ['test/test*.py', 'setup.cfg']
for pattern in optional:
- files = list(filter(os.path.isfile, glob(pattern)))
+ files = list(filter(cs_path_exists, glob(pattern)))
if files:
self.filelist.extend(files)