aboutsummaryrefslogtreecommitdiffstats
path: root/setuptools/command
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2015-01-02 18:38:36 -0500
committerJason R. Coombs <jaraco@jaraco.com>2015-01-02 18:38:36 -0500
commit16ee10c47583a4a2b7480af6fc5a205343acfdfd (patch)
tree7cfbb6d488a92fa01ddb86d6f226f549ad26a01e /setuptools/command
parent866ff739f6e64aaaefcf7816263410527c9f55f7 (diff)
parent41f2c5ec8dd669747f3cfd8d6b2ae9a40d219545 (diff)
downloadexternal_python_setuptools-16ee10c47583a4a2b7480af6fc5a205343acfdfd.tar.gz
external_python_setuptools-16ee10c47583a4a2b7480af6fc5a205343acfdfd.tar.bz2
external_python_setuptools-16ee10c47583a4a2b7480af6fc5a205343acfdfd.zip
Merge with 10.2.1
--HG-- branch : feature/issue-229
Diffstat (limited to 'setuptools/command')
-rw-r--r--setuptools/command/build_ext.py58
-rwxr-xr-xsetuptools/command/easy_install.py67
-rwxr-xr-xsetuptools/command/egg_info.py50
-rwxr-xr-xsetuptools/command/sdist.py60
-rw-r--r--setuptools/command/test.py2
5 files changed, 119 insertions, 118 deletions
diff --git a/setuptools/command/build_ext.py b/setuptools/command/build_ext.py
index 53bf9cd3..e4b2c593 100644
--- a/setuptools/command/build_ext.py
+++ b/setuptools/command/build_ext.py
@@ -6,6 +6,7 @@ from distutils.errors import DistutilsError
from distutils import log
import os
import sys
+import itertools
from setuptools.extension import Library
@@ -33,18 +34,13 @@ if sys.platform == "darwin":
use_stubs = True
elif os.name != 'nt':
try:
- from dl import RTLD_NOW
-
- have_rtld = True
- use_stubs = True
+ import dl
+ use_stubs = have_rtld = hasattr(dl, 'RTLD_NOW')
except ImportError:
pass
-def if_dl(s):
- if have_rtld:
- return s
- return ''
+if_dl = lambda s: s if have_rtld else ''
class build_ext(_build_ext):
@@ -123,10 +119,10 @@ class build_ext(_build_ext):
# XXX what to do with conflicts?
self.ext_map[fullname.split('.')[-1]] = ext
- ltd = ext._links_to_dynamic = \
- self.shlibs and self.links_to_dynamic(ext) or False
- ext._needs_stub = ltd and use_stubs and not isinstance(ext,
- Library)
+ ltd = self.shlibs and self.links_to_dynamic(ext) or False
+ ns = ltd and use_stubs and not isinstance(ext, Library)
+ ext._links_to_dynamic = ltd
+ ext._needs_stub = ns
filename = ext._file_name = self.get_ext_filename(fullname)
libdir = os.path.dirname(os.path.join(self.build_lib, filename))
if ltd and libdir not in ext.library_dirs:
@@ -186,9 +182,8 @@ class build_ext(_build_ext):
self.compiler = self.shlib_compiler
_build_ext.build_extension(self, ext)
if ext._needs_stub:
- self.write_stub(
- self.get_finalized_command('build_py').build_lib, ext
- )
+ cmd = self.get_finalized_command('build_py').build_lib
+ self.write_stub(cmd, ext)
finally:
self.compiler = _compiler
@@ -199,22 +194,27 @@ class build_ext(_build_ext):
# XXX static-compiled version
libnames = dict.fromkeys([lib._full_name for lib in self.shlibs])
pkg = '.'.join(ext._full_name.split('.')[:-1] + [''])
- for libname in ext.libraries:
- if pkg + libname in libnames:
- return True
- return False
+ return any(pkg + libname in libnames for libname in ext.libraries)
def get_outputs(self):
- outputs = _build_ext.get_outputs(self)
- optimize = self.get_finalized_command('build_py').optimize
- for ext in self.extensions:
- if ext._needs_stub:
- base = os.path.join(self.build_lib, *ext._full_name.split('.'))
- outputs.append(base + '.py')
- outputs.append(base + '.pyc')
- if optimize:
- outputs.append(base + '.pyo')
- return outputs
+ return _build_ext.get_outputs(self) + self.__get_stubs_outputs()
+
+ def __get_stubs_outputs(self):
+ # assemble the base name for each extension that needs a stub
+ ns_ext_bases = (
+ os.path.join(self.build_lib, *ext._full_name.split('.'))
+ for ext in self.extensions
+ if ext._needs_stub
+ )
+ # pair each base with the extension
+ pairs = itertools.product(ns_ext_bases, self.__get_output_extensions())
+ return list(base + fnext for base, fnext in pairs)
+
+ def __get_output_extensions(self):
+ yield '.py'
+ yield '.pyc'
+ if self.get_finalized_command('build_py').optimize:
+ yield '.pyo'
def write_stub(self, output_dir, ext, compile=False):
log.info("writing stub loader for %s to %s", ext._full_name,
diff --git a/setuptools/command/easy_install.py b/setuptools/command/easy_install.py
index 5444ba53..a24e3b59 100755
--- a/setuptools/command/easy_install.py
+++ b/setuptools/command/easy_install.py
@@ -34,6 +34,7 @@ import textwrap
import warnings
import site
import struct
+import contextlib
import six
from six.moves import configparser
@@ -55,9 +56,14 @@ from pkg_resources import (
import pkg_resources
+# Turn on PEP440Warnings
+warnings.filterwarnings("default", category=pkg_resources.PEP440Warning)
+
+
sys_executable = os.environ.get('__PYVENV_LAUNCHER__',
os.path.normpath(sys.executable))
+
__all__ = [
'samefile', 'easy_install', 'PthDistributions', 'extract_wininst_cfg',
'main', 'get_exe_prefixes',
@@ -1541,10 +1547,14 @@ class PthDistributions(Environment):
def add(self, dist):
"""Add `dist` to the distribution map"""
- if (dist.location not in self.paths and (
- dist.location not in self.sitedirs or
- dist.location == os.getcwd() # account for '.' being in PYTHONPATH
- )):
+ new_path = (
+ dist.location not in self.paths and (
+ dist.location not in self.sitedirs or
+ # account for '.' being in PYTHONPATH
+ dist.location == os.getcwd()
+ )
+ )
+ if new_path:
self.paths.append(dist.location)
self.dirty = True
Environment.add(self, dist)
@@ -2112,39 +2122,42 @@ def bootstrap():
def main(argv=None, **kw):
from setuptools import setup
from setuptools.dist import Distribution
- import distutils.core
-
- USAGE = """\
-usage: %(script)s [options] requirement_or_url ...
- or: %(script)s --help
-"""
-
- def gen_usage(script_name):
- return USAGE % dict(
- script=os.path.basename(script_name),
- )
-
- def with_ei_usage(f):
- old_gen_usage = distutils.core.gen_usage
- try:
- distutils.core.gen_usage = gen_usage
- return f()
- finally:
- distutils.core.gen_usage = old_gen_usage
class DistributionWithoutHelpCommands(Distribution):
common_usage = ""
def _show_help(self, *args, **kw):
- with_ei_usage(lambda: Distribution._show_help(self, *args, **kw))
+ with _patch_usage():
+ Distribution._show_help(self, *args, **kw)
if argv is None:
argv = sys.argv[1:]
- with_ei_usage(
- lambda: setup(
+ with _patch_usage():
+ setup(
script_args=['-q', 'easy_install', '-v'] + argv,
script_name=sys.argv[0] or 'easy_install',
distclass=DistributionWithoutHelpCommands, **kw
)
- )
+
+
+@contextlib.contextmanager
+def _patch_usage():
+ import distutils.core
+ USAGE = textwrap.dedent("""
+ usage: %(script)s [options] requirement_or_url ...
+ or: %(script)s --help
+ """).lstrip()
+
+ def gen_usage(script_name):
+ return USAGE % dict(
+ script=os.path.basename(script_name),
+ )
+
+ saved = distutils.core.gen_usage
+ distutils.core.gen_usage = gen_usage
+ try:
+ yield
+ finally:
+ distutils.core.gen_usage = saved
+
diff --git a/setuptools/command/egg_info.py b/setuptools/command/egg_info.py
index 14ff0763..3f1db996 100755
--- a/setuptools/command/egg_info.py
+++ b/setuptools/command/egg_info.py
@@ -6,21 +6,27 @@ from distutils.filelist import FileList as _FileList
from distutils.util import convert_path
from distutils import log
import distutils.errors
+import distutils.filelist
import os
import re
import sys
import six
+try:
+ from setuptools_svn import svn_utils
+except ImportError:
+ pass
+
from setuptools import Command
from setuptools.command.sdist import sdist
-from setuptools import svn_utils
from setuptools.command.sdist import walk_revctrl
from pkg_resources import (
parse_requirements, safe_name, parse_version,
safe_version, yield_lines, EntryPoint, iter_entry_points, to_filename)
import setuptools.unicode_utils as unicode_utils
+from pkg_resources import packaging
class egg_info(Command):
description = "create a distribution's .egg-info directory"
@@ -69,10 +75,15 @@ class egg_info(Command):
self.vtags = self.tags()
self.egg_version = self.tagged_version()
+ parsed_version = parse_version(self.egg_version)
+
try:
+ is_version = isinstance(parsed_version, packaging.version.Version)
+ spec = (
+ "%s==%s" if is_version else "%s===%s"
+ )
list(
- parse_requirements('%s==%s' % (self.egg_name,
- self.egg_version))
+ parse_requirements(spec % (self.egg_name, self.egg_version))
)
except ValueError:
raise distutils.errors.DistutilsOptionError(
@@ -184,6 +195,8 @@ class egg_info(Command):
@staticmethod
def get_svn_revision():
+ if 'svn_utils' not in globals():
+ return "0"
return str(svn_utils.SvnInfo.load(os.curdir).get_revision())
def find_sources(self):
@@ -313,8 +326,33 @@ class manifest_maker(sdist):
elif os.path.exists(self.manifest):
self.read_manifest()
ei_cmd = self.get_finalized_command('egg_info')
+ self._add_egg_info(cmd=ei_cmd)
self.filelist.include_pattern("*", prefix=ei_cmd.egg_info)
+ def _add_egg_info(self, cmd):
+ """
+ Add paths for egg-info files for an external egg-base.
+
+ The egg-info files are written to egg-base. If egg-base is
+ outside the current working directory, this method
+ searchs the egg-base directory for files to include
+ in the manifest. Uses distutils.filelist.findall (which is
+ really the version monkeypatched in by setuptools/__init__.py)
+ to perform the search.
+
+ Since findall records relative paths, prefix the returned
+ paths with cmd.egg_base, so add_default's include_pattern call
+ (which is looking for the absolute cmd.egg_info) will match
+ them.
+ """
+ if cmd.egg_base == os.curdir:
+ # egg-info files were already added by something else
+ return
+
+ discovered = distutils.filelist.findall(cmd.egg_base)
+ resolved = (os.path.join(cmd.egg_base, path) for path in discovered)
+ self.filelist.allfiles.extend(resolved)
+
def prune_file_list(self):
build = self.get_finalized_command('build')
base_dir = self.distribution.get_fullname()
@@ -383,6 +421,12 @@ def write_requirements(cmd, basename, filename):
cmd.write_or_delete_file("requirements", filename, data.getvalue())
+def write_setup_requirements(cmd, basename, filename):
+ data = StringIO()
+ _write_requirements(data, cmd.distribution.setup_requires)
+ cmd.write_or_delete_file("setup-requirements", filename, data.getvalue())
+
+
def write_toplevel_names(cmd, basename, filename):
pkgs = dict.fromkeys(
[
diff --git a/setuptools/command/sdist.py b/setuptools/command/sdist.py
index a15582c3..4ec7ec91 100755
--- a/setuptools/command/sdist.py
+++ b/setuptools/command/sdist.py
@@ -1,20 +1,18 @@
from glob import glob
-from distutils.util import convert_path
from distutils import log
import distutils.command.sdist as orig
import os
-import re
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')
+READMES = 'README', 'README.rst', 'README.txt'
+_default_revctrl = list
def walk_revctrl(dirname=''):
"""Find all files under revision control"""
@@ -23,60 +21,6 @@ def walk_revctrl(dirname=''):
yield item
-# TODO will need test case
-class re_finder(object):
- """
- Finder that locates files based on entries in a file matched by a
- regular expression.
- """
-
- def __init__(self, path, pattern, postproc=lambda x: x):
- self.pattern = pattern
- self.postproc = postproc
- self.entries_path = convert_path(path)
-
- def _finder(self, dirname, filename):
- f = open(filename, 'rU')
- try:
- data = f.read()
- finally:
- f.close()
- for match in self.pattern.finditer(data):
- path = match.group(1)
- # postproc was formerly used when the svn finder
- # was an re_finder for calling unescape
- path = self.postproc(path)
- yield svn_utils.joinpath(dirname, path)
-
- def find(self, dirname=''):
- path = svn_utils.joinpath(dirname, self.entries_path)
-
- if not os.path.isfile(path):
- # entries file doesn't exist
- return
- for path in self._finder(dirname, path):
- if os.path.isfile(path):
- yield path
- elif os.path.isdir(path):
- for item in self.find(path):
- yield item
-
- __call__ = find
-
-
-def _default_revctrl(dirname=''):
- 'Primary svn_cvs entry point'
- for finder in finders:
- for item in finder(dirname):
- yield item
-
-
-finders = [
- re_finder('CVS/Entries', re.compile(r"^\w?/([^/]+)/", re.M)),
- svn_utils.svn_finder,
-]
-
-
class sdist(orig.sdist):
"""Smart sdist that finds anything supported by revision control"""
diff --git a/setuptools/command/test.py b/setuptools/command/test.py
index 14dd2600..c5644530 100644
--- a/setuptools/command/test.py
+++ b/setuptools/command/test.py
@@ -173,4 +173,4 @@ class test(Command):
if val is None:
return
parsed = EntryPoint.parse("x=" + val)
- return parsed.load(require=False)()
+ return parsed._load()()