Commit 8427babe authored by Jason R. Coombs's avatar Jason R. Coombs

ez_setup now loads latest version using metadata

parent 627d4b47
...@@ -16,7 +16,8 @@ import subprocess ...@@ -16,7 +16,8 @@ import subprocess
import platform import platform
import textwrap import textwrap
import contextlib import contextlib
import warnings import json
import codecs
from distutils import log from distutils import log
...@@ -30,7 +31,8 @@ try: ...@@ -30,7 +31,8 @@ try:
except ImportError: except ImportError:
USER_SITE = None USER_SITE = None
DEFAULT_VERSION = "19.1" LATEST = object()
DEFAULT_VERSION = LATEST
DEFAULT_URL = "https://pypi.python.org/packages/source/s/setuptools/" DEFAULT_URL = "https://pypi.python.org/packages/source/s/setuptools/"
DEFAULT_SAVE_DIR = os.curdir DEFAULT_SAVE_DIR = os.curdir
...@@ -140,6 +142,7 @@ def use_setuptools( ...@@ -140,6 +142,7 @@ def use_setuptools(
Return None. Raise SystemExit if the requested version Return None. Raise SystemExit if the requested version
or later cannot be installed. or later cannot be installed.
""" """
version = _resolve_version(version)
to_dir = os.path.abspath(to_dir) to_dir = os.path.abspath(to_dir)
# prior to importing, capture the module state for # prior to importing, capture the module state for
...@@ -321,6 +324,7 @@ def download_setuptools( ...@@ -321,6 +324,7 @@ def download_setuptools(
``downloader_factory`` should be a function taking no arguments and ``downloader_factory`` should be a function taking no arguments and
returning a function for downloading a URL to a target. returning a function for downloading a URL to a target.
""" """
version = _resolve_version(version)
# making sure we use the absolute path # making sure we use the absolute path
to_dir = os.path.abspath(to_dir) to_dir = os.path.abspath(to_dir)
zip_name = "setuptools-%s.zip" % version zip_name = "setuptools-%s.zip" % version
...@@ -333,6 +337,27 @@ def download_setuptools( ...@@ -333,6 +337,27 @@ def download_setuptools(
return os.path.realpath(saveto) return os.path.realpath(saveto)
def _resolve_version(version):
"""
Resolve LATEST version
"""
if version is not LATEST:
return version
with urlopen('https://pypi.python.org/pypi/setuptools/json') as resp:
charset = resp.info().get_content_charset()
reader = codecs.getreader(charset)
doc = json.load(reader(resp))
def by_vals(ver_string):
try:
return tuple(map(int, ver_string.split('.')))
except Exception:
return (0,)
return max(doc['releases'], key=by_vals)
def _build_install_args(options): def _build_install_args(options):
""" """
Build the arguments to 'python setup.py install' on the setuptools package. Build the arguments to 'python setup.py install' on the setuptools package.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment