jenkins-bot merged this change.

View Change

Approvals: Dalba: Looks good to me, approved jenkins-bot: Verified
Update ez_setup.py to v33.1.1

Change-Id: Ifeacd2dad5fd487e62dc68bc375bb829b907cebd
---
M ez_setup.py
1 file changed, 50 insertions(+), 46 deletions(-)

diff --git a/ez_setup.py b/ez_setup.py
index 41fcdc8..a11e42f 100644
--- a/ez_setup.py
+++ b/ez_setup.py
@@ -3,7 +3,12 @@
"""
Setuptools bootstrapping installer.

+Maintained at https://github.com/pypa/setuptools/tree/bootstrap.
+
Run this script to install or upgrade setuptools.
+
+This method is DEPRECATED.
+Check https://github.com/pypa/setuptools/issues/581 for more details.
"""

import os
@@ -16,8 +21,6 @@
import platform
import textwrap
import contextlib
-import json
-import codecs

from distutils import log

@@ -31,10 +34,20 @@
except ImportError:
USER_SITE = None

-LATEST = object()
-DEFAULT_VERSION = LATEST
-DEFAULT_URL = "https://pypi.python.org/packages/source/s/setuptools/"
+# 33.1.1 is the last version that supports setuptools self upgrade/installation
+DEFAULT_VERSION = '33.1.1'
+DEFAULT_URL = 'https://pypi.io/packages/source/s/setuptools/'
DEFAULT_SAVE_DIR = os.curdir
+DEFAULT_DEPRECATION_MESSAGE = (
+ 'ez_setup.py is deprecated and when using it setuptools will be pinned to '
+ "{0} since it's the last version that supports setuptools self upgrade/"
+ 'installation, check https://github.com/pypa/setuptools/issues/581 for '
+ 'more info; use pip to install setuptools')
+
+MEANINGFUL_INVALID_ZIP_ERR_MSG = (
+ 'Maybe {0} is corrupted, delete it and try again.')
+
+log.warn(DEFAULT_DEPRECATION_MESSAGE.format(DEFAULT_VERSION))


def _python_cmd(*args):
@@ -100,8 +113,16 @@
old_wd = os.getcwd()
try:
os.chdir(tmpdir)
- with ContextualZipFile(filename) as archive:
- archive.extractall()
+ try:
+ with ContextualZipFile(filename) as archive:
+ archive.extractall()
+ except zipfile.BadZipfile as err:
+ if not err.args:
+ err.args = ('', )
+ err.args = err.args + (
+ MEANINGFUL_INVALID_ZIP_ERR_MSG.format(filename),
+ )
+ raise

# going in the directory
subdir = os.path.join(tmpdir, os.listdir(tmpdir)[0])
@@ -116,11 +137,12 @@

def _do_download(version, download_base, to_dir, download_delay):
"""Download Setuptools."""
- egg = os.path.join(to_dir, 'setuptools-%s-py%d.%d.egg'
- % (version, sys.version_info[0], sys.version_info[1]))
+ py_desig = 'py{sys.version_info[0]}.{sys.version_info[1]}'.format(sys=sys)
+ tp = 'setuptools-{version}-{py_desig}.egg'
+ egg = os.path.join(to_dir, tp.format(**locals()))
if not os.path.exists(egg):
archive = download_setuptools(version, download_base,
- to_dir, download_delay)
+ to_dir, download_delay)
_build_egg(egg, archive, to_dir)
sys.path.insert(0, egg)

@@ -142,7 +164,6 @@
Return None. Raise SystemExit if the requested version
or later cannot be installed.
"""
- version = _resolve_version(version)
to_dir = os.path.abspath(to_dir)

# prior to importing, capture the module state for
@@ -192,6 +213,11 @@


def _unload_pkg_resources():
+ sys.meta_path = [
+ importer
+ for importer in sys.meta_path
+ if importer.__class__.__module__ != 'pkg_resources.extern'
+ ]
del_modules = [
name for name in sys.modules
if name.startswith('pkg_resources')
@@ -251,7 +277,7 @@


def download_file_curl(url, target):
- cmd = ['curl', url, '--silent', '--output', target]
+ cmd = ['curl', url, '--location', '--silent', '--output', target]
_clean_check(cmd, target)


@@ -324,7 +350,6 @@
``downloader_factory`` should be a function taking no arguments and
returning a function for downloading a URL to a target.
"""
- version = _resolve_version(version)
# making sure we use the absolute path
to_dir = os.path.abspath(to_dir)
zip_name = "setuptools-%s.zip" % version
@@ -335,26 +360,6 @@
downloader = downloader_factory()
downloader(url, saveto)
return os.path.realpath(saveto)
-
-
-def _resolve_version(version):
- """
- Resolve LATEST version
- """
- if version is not LATEST:
- return version
-
- resp = urlopen('https://pypi.python.org/pypi/setuptools/json')
- with contextlib.closing(resp):
- try:
- charset = resp.info().get_content_charset()
- except Exception:
- # Python 2 compat; assume UTF-8
- charset = 'UTF-8'
- reader = codecs.getreader(charset)
- doc = json.load(reader(resp))
-
- return str(doc['info']['version'])


def _build_install_args(options):
@@ -371,7 +376,7 @@
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)')
+ help='install in user site package')
parser.add_option(
'--download-base', dest='download_base', metavar="URL",
default=DEFAULT_URL,
@@ -382,13 +387,13 @@
help='Use internal, non-validating downloader'
)
parser.add_option(
- '--version', help="Specify which version to download",
+ '--version', help='Specify which version to download',
default=DEFAULT_VERSION,
)
parser.add_option(
- '--to-dir',
- help="Directory to save (and re-use) package",
- default=DEFAULT_SAVE_DIR,
+ '--to-dir',
+ help='Directory to save (and re-use) package',
+ default=DEFAULT_SAVE_DIR,
)
options, args = parser.parse_args()
# positional arguments are ignored
@@ -396,13 +401,13 @@


def _download_args(options):
- """Return args for download_setuptools function from cmdline args."""
- return dict(
- version=options.version,
- download_base=options.download_base,
- downloader_factory=options.downloader_factory,
- to_dir=options.to_dir,
- )
+ """Return args for download_setuptools function from cmdline args."""
+ return dict(
+ version=options.version,
+ download_base=options.download_base,
+ downloader_factory=options.downloader_factory,
+ to_dir=options.to_dir,
+ )


def main():
@@ -410,7 +415,6 @@
options = _parse_args()
archive = download_setuptools(**_download_args(options))
return _install(archive, _build_install_args(options))
-

if __name__ == '__main__':
sys.exit(main())

To view, visit change 423468. To unsubscribe, visit settings.

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: Ifeacd2dad5fd487e62dc68bc375bb829b907cebd
Gerrit-Change-Number: 423468
Gerrit-PatchSet: 3
Gerrit-Owner: Xqt <info@gno.de>
Gerrit-Reviewer: Dalba <dalba.wiki@gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb@gmail.com>
Gerrit-Reviewer: Zoranzoki21 <zorandori4444@gmail.com>
Gerrit-Reviewer: jenkins-bot <>