[pycmd] Update distribute_setup.py (fixes rhbz#992844).

Thomas Moschny thm at fedoraproject.org
Sat Aug 17 10:37:26 UTC 2013


commit a1d885b07a339b935ff95df9017d3b6863b2c0ba
Author: Thomas Moschny <thm at fedoraproject.org>
Date:   Sat Aug 17 12:35:03 2013 +0200

    Update distribute_setup.py (fixes rhbz#992844).

 pycmd-1.0-update-distribute_setup.patch |  306 +++++++++++++++++++++++++++++++
 pycmd.spec                              |    4 +
 2 files changed, 310 insertions(+), 0 deletions(-)
---
diff --git a/pycmd-1.0-update-distribute_setup.patch b/pycmd-1.0-update-distribute_setup.patch
new file mode 100644
index 0000000..a8c850a
--- /dev/null
+++ b/pycmd-1.0-update-distribute_setup.patch
@@ -0,0 +1,306 @@
+diff -up pycmd-1.0/distribute_setup.py.orig pycmd-1.0/distribute_setup.py
+--- pycmd-1.0/distribute_setup.py.orig	2010-11-29 16:49:04.000000000 +0100
++++ pycmd-1.0/distribute_setup.py	2013-07-05 04:00:02.000000000 +0200
+@@ -14,11 +14,14 @@ the appropriate options to ``use_setupto
+ This file can also be run as a script to install or upgrade setuptools.
+ """
+ import os
++import shutil
+ import sys
+ import time
+ import fnmatch
+ import tempfile
+ import tarfile
++import optparse
++
+ from distutils import log
+ 
+ try:
+@@ -46,7 +49,7 @@ except ImportError:
+             args = [quote(arg) for arg in args]
+         return os.spawnl(os.P_WAIT, sys.executable, *args) == 0
+ 
+-DEFAULT_VERSION = "0.6.13"
++DEFAULT_VERSION = "0.6.49"
+ DEFAULT_URL = "http://pypi.python.org/packages/source/d/distribute/"
+ SETUPTOOLS_FAKED_VERSION = "0.6c11"
+ 
+@@ -63,7 +66,7 @@ Description: xxx
+ """ % SETUPTOOLS_FAKED_VERSION
+ 
+ 
+-def _install(tarball):
++def _install(tarball, install_args=()):
+     # extracting the tarball
+     tmpdir = tempfile.mkdtemp()
+     log.warn('Extracting in %s', tmpdir)
+@@ -81,11 +84,14 @@ def _install(tarball):
+ 
+         # installing
+         log.warn('Installing Distribute')
+-        if not _python_cmd('setup.py', 'install'):
++        if not _python_cmd('setup.py', 'install', *install_args):
+             log.warn('Something went wrong during the installation.')
+             log.warn('See the error message above.')
++            # exitcode will be 2
++            return 2
+     finally:
+         os.chdir(old_wd)
++        shutil.rmtree(tmpdir)
+ 
+ 
+ def _build_egg(egg, tarball, to_dir):
+@@ -110,6 +116,7 @@ def _build_egg(egg, tarball, to_dir):
+ 
+     finally:
+         os.chdir(old_wd)
++        shutil.rmtree(tmpdir)
+     # returning the result
+     log.warn(egg)
+     if not os.path.exists(egg):
+@@ -137,6 +144,16 @@ def use_setuptools(version=DEFAULT_VERSI
+     try:
+         try:
+             import pkg_resources
++
++            # Setuptools 0.7b and later is a suitable (and preferable)
++            # substitute for any Distribute version.
++            try:
++                pkg_resources.require("setuptools>=0.7b")
++                return
++            except (pkg_resources.DistributionNotFound,
++                    pkg_resources.VersionConflict):
++                pass
++
+             if not hasattr(pkg_resources, '_distribute'):
+                 if not no_fake:
+                     _fake_setuptools()
+@@ -144,7 +161,7 @@ def use_setuptools(version=DEFAULT_VERSI
+         except ImportError:
+             return _do_download(version, download_base, to_dir, download_delay)
+         try:
+-            pkg_resources.require("distribute>="+version)
++            pkg_resources.require("distribute>=" + version)
+             return
+         except pkg_resources.VersionConflict:
+             e = sys.exc_info()[1]
+@@ -167,6 +184,7 @@ def use_setuptools(version=DEFAULT_VERSI
+         if not no_fake:
+             _create_fake_setuptools_pkg_info(to_dir)
+ 
++
+ def download_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL,
+                         to_dir=os.curdir, delay=15):
+     """Download distribute from a specified location and return its filename
+@@ -203,6 +221,7 @@ def download_setuptools(version=DEFAULT_
+                 dst.close()
+     return os.path.realpath(saveto)
+ 
++
+ def _no_sandbox(function):
+     def __no_sandbox(*args, **kw):
+         try:
+@@ -227,9 +246,12 @@ def _no_sandbox(function):
+ 
+     return __no_sandbox
+ 
++
+ def _patch_file(path, content):
+     """Will backup the file then patch it"""
+-    existing_content = open(path).read()
++    f = open(path)
++    existing_content = f.read()
++    f.close()
+     if existing_content == content:
+         # already patched
+         log.warn('Already patched.')
+@@ -245,15 +267,21 @@ def _patch_file(path, content):
+ 
+ _patch_file = _no_sandbox(_patch_file)
+ 
++
+ def _same_content(path, content):
+-    return open(path).read() == content
++    f = open(path)
++    existing_content = f.read()
++    f.close()
++    return existing_content == content
++
+ 
+ def _rename_path(path):
+     new_name = path + '.OLD.%s' % time.time()
+-    log.warn('Renaming %s into %s', path, new_name)
++    log.warn('Renaming %s to %s', path, new_name)
+     os.rename(path, new_name)
+     return new_name
+ 
++
+ def _remove_flat_installation(placeholder):
+     if not os.path.isdir(placeholder):
+         log.warn('Unkown installation at %s', placeholder)
+@@ -267,7 +295,7 @@ def _remove_flat_installation(placeholde
+         log.warn('Could not locate setuptools*.egg-info')
+         return
+ 
+-    log.warn('Removing elements out of the way...')
++    log.warn('Moving elements out of the way...')
+     pkg_info = os.path.join(placeholder, file)
+     if os.path.isdir(pkg_info):
+         patched = _patch_egg_dir(pkg_info)
+@@ -289,11 +317,13 @@ def _remove_flat_installation(placeholde
+ 
+ _remove_flat_installation = _no_sandbox(_remove_flat_installation)
+ 
++
+ def _after_install(dist):
+     log.warn('After install bootstrap.')
+     placeholder = dist.get_command_obj('install').install_purelib
+     _create_fake_setuptools_pkg_info(placeholder)
+ 
++
+ def _create_fake_setuptools_pkg_info(placeholder):
+     if not placeholder or not os.path.exists(placeholder):
+         log.warn('Could not find the install location')
+@@ -307,7 +337,11 @@ def _create_fake_setuptools_pkg_info(pla
+         return
+ 
+     log.warn('Creating %s', pkg_info)
+-    f = open(pkg_info, 'w')
++    try:
++        f = open(pkg_info, 'w')
++    except EnvironmentError:
++        log.warn("Don't have permissions to write %s, skipping", pkg_info)
++        return
+     try:
+         f.write(SETUPTOOLS_PKG_INFO)
+     finally:
+@@ -321,7 +355,10 @@ def _create_fake_setuptools_pkg_info(pla
+     finally:
+         f.close()
+ 
+-_create_fake_setuptools_pkg_info = _no_sandbox(_create_fake_setuptools_pkg_info)
++_create_fake_setuptools_pkg_info = _no_sandbox(
++    _create_fake_setuptools_pkg_info
++)
++
+ 
+ def _patch_egg_dir(path):
+     # let's check if it's already patched
+@@ -343,6 +380,7 @@ def _patch_egg_dir(path):
+ 
+ _patch_egg_dir = _no_sandbox(_patch_egg_dir)
+ 
++
+ def _before_install():
+     log.warn('Before install bootstrap.')
+     _fake_setuptools()
+@@ -351,7 +389,7 @@ def _before_install():
+ def _under_prefix(location):
+     if 'install' not in sys.argv:
+         return True
+-    args = sys.argv[sys.argv.index('install')+1:]
++    args = sys.argv[sys.argv.index('install') + 1:]
+     for index, arg in enumerate(args):
+         for option in ('--root', '--prefix'):
+             if arg.startswith('%s=' % option):
+@@ -359,7 +397,7 @@ def _under_prefix(location):
+                 return location.startswith(top_dir)
+             elif arg == option:
+                 if len(args) > index:
+-                    top_dir = args[index+1]
++                    top_dir = args[index + 1]
+                     return location.startswith(top_dir)
+         if arg == '--user' and USER_SITE is not None:
+             return location.startswith(USER_SITE)
+@@ -376,11 +414,14 @@ def _fake_setuptools():
+         return
+     ws = pkg_resources.working_set
+     try:
+-        setuptools_dist = ws.find(pkg_resources.Requirement.parse('setuptools',
+-                                  replacement=False))
++        setuptools_dist = ws.find(
++            pkg_resources.Requirement.parse('setuptools', replacement=False)
++            )
+     except TypeError:
+         # old distribute API
+-        setuptools_dist = ws.find(pkg_resources.Requirement.parse('setuptools'))
++        setuptools_dist = ws.find(
++            pkg_resources.Requirement.parse('setuptools')
++        )
+ 
+     if setuptools_dist is None:
+         log.warn('No setuptools distribution found')
+@@ -414,7 +455,7 @@ def _fake_setuptools():
+         res = _patch_egg_dir(setuptools_location)
+         if not res:
+             return
+-    log.warn('Patched done.')
++    log.warn('Patching complete.')
+     _relaunch()
+ 
+ 
+@@ -422,7 +463,9 @@ def _relaunch():
+     log.warn('Relaunching...')
+     # we have to relaunch the process
+     # pip marker to avoid a relaunch bug
+-    if sys.argv[:3] == ['-c', 'install', '--single-version-externally-managed']:
++    _cmd1 = ['-c', 'install', '--single-version-externally-managed']
++    _cmd2 = ['-c', 'install', '--record']
++    if sys.argv[:3] == _cmd1 or sys.argv[:3] == _cmd2:
+         sys.argv[0] = 'setup.py'
+     args = [sys.executable] + sys.argv
+     sys.exit(subprocess.call(args))
+@@ -448,7 +491,7 @@ def _extractall(self, path=".", members=
+             # Extract directories with a safe mode.
+             directories.append(tarinfo)
+             tarinfo = copy.copy(tarinfo)
+-            tarinfo.mode = 448 # decimal for oct 0700
++            tarinfo.mode = 448  # decimal for oct 0700
+         self.extract(tarinfo, path)
+ 
+     # Reverse sort directories.
+@@ -475,11 +518,39 @@ def _extractall(self, path=".", members=
+                 self._dbg(1, "tarfile: %s" % e)
+ 
+ 
+-def main(argv, version=DEFAULT_VERSION):
+-    """Install or upgrade setuptools and EasyInstall"""
+-    tarball = download_setuptools()
+-    _install(tarball)
++def _build_install_args(options):
++    """
++    Build the arguments to 'python setup.py install' on the distribute package
++    """
++    install_args = []
++    if options.user_install:
++        if sys.version_info < (2, 6):
++            log.warn("--user requires Python 2.6 or later")
++            raise SystemExit(1)
++        install_args.append('--user')
++    return install_args
+ 
++def _parse_args():
++    """
++    Parse the command line for options
++    """
++    parser = optparse.OptionParser()
++    parser.add_option(
++        '--user', dest='user_install', action='store_true', default=False,
++        help='install in user site package (requires Python 2.6 or later)')
++    parser.add_option(
++        '--download-base', dest='download_base', metavar="URL",
++        default=DEFAULT_URL,
++        help='alternative URL from where to download the distribute package')
++    options, args = parser.parse_args()
++    # positional arguments are ignored
++    return options
++
++def main(version=DEFAULT_VERSION):
++    """Install or upgrade setuptools and EasyInstall"""
++    options = _parse_args()
++    tarball = download_setuptools(download_base=options.download_base)
++    return _install(tarball, _build_install_args(options))
+ 
+ if __name__ == '__main__':
+-    main(sys.argv[1:])
++    sys.exit(main())
diff --git a/pycmd.spec b/pycmd.spec
index b86aac3..efa00ca 100644
--- a/pycmd.spec
+++ b/pycmd.spec
@@ -15,6 +15,8 @@ Group:          Development/Languages
 License:        MIT
 URL:            http://pypi.python.org/pypi/pycmd
 Source0:        http://pypi.python.org/packages/source/p/%{name}/%{name}-%{version}.zip
+# fix F20 FTBFS bug 992844
+Patch0:         pycmd-1.0-update-distribute_setup.patch
 BuildArch:      noarch
 BuildRequires:  python-devel
 BuildRequires:  python-setuptools
@@ -50,6 +52,7 @@ development.
 
 %prep
 %setup -q
+%patch0 -p1
 
 %if 0%{?with_python3}
 cp -a . %{py3dir}
@@ -136,6 +139,7 @@ done
 
 %changelog
 * Sat Aug 17 2013 Thomas Moschny <thomas.moschny at gmx.de> - 1.0-10
+- Update distribute_setup.py (fixes rhbz#992844).
 - Modernize spec file.
 
 * Sun Aug 04 2013 Fedora Release Engineering <rel-eng at lists.fedoraproject.org> - 1.0-9


More information about the scm-commits mailing list