diff options
Diffstat (limited to 'ez_setup.py')
| -rw-r--r-- | ez_setup.py | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/ez_setup.py b/ez_setup.py index 975b45c5..9715bdc7 100644 --- a/ez_setup.py +++ b/ez_setup.py @@ -16,7 +16,8 @@ import subprocess import platform import textwrap import contextlib -import warnings +import json +import codecs from distutils import log @@ -30,7 +31,8 @@ try: except ImportError: USER_SITE = None -DEFAULT_VERSION = "18.7.2" +LATEST = object() +DEFAULT_VERSION = LATEST DEFAULT_URL = "https://pypi.python.org/packages/source/s/setuptools/" DEFAULT_SAVE_DIR = os.curdir @@ -140,6 +142,7 @@ def use_setuptools( 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 @@ -222,8 +225,8 @@ def download_file_powershell(url, target): ps_cmd = ( "[System.Net.WebRequest]::DefaultWebProxy.Credentials = " "[System.Net.CredentialCache]::DefaultCredentials; " - "(new-object System.Net.WebClient).DownloadFile(%(url)r, %(target)r)" - % vars() + '(new-object System.Net.WebClient).DownloadFile("%(url)s", "%(target)s")' + % locals() ) cmd = [ 'powershell', @@ -321,6 +324,7 @@ def download_setuptools( ``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 @@ -333,6 +337,26 @@ def download_setuptools( 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): """ Build the arguments to 'python setup.py install' on the setuptools package. |
