Skip to content

Commit

Permalink
ez_setup.py now takes a --insecure argument to bypass the secure down…
Browse files Browse the repository at this point in the history
…loaders. download_setuptools also now accepts a new keyword argument 'download_factory', enabling programmitic invocation to customize the downloader resolution. Fixes #75. Thanks to Pablo Algarvio for the report and suggestions.
  • Loading branch information
jaraco committed Aug 31, 2013
1 parent ae675b9 commit 0424d55
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
7 changes: 7 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
CHANGES
=======

----
next
----

* Issue #75: Add ``--insecure`` option to ez_setup.py to accommodate
environments where a trusted SSL connection cannot be validated.

---
1.1
---
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Contributors
* Marc Abramowitz
* Martin von Löwis
* Noufal Ibrahim
* Pedro Algarvio
* Pete Hollobon
* Phillip J. Eby
* Philip Jenvey
Expand Down
16 changes: 13 additions & 3 deletions ez_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,14 +254,18 @@ def get_best_downloader():
return dl

def download_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL,
to_dir=os.curdir, delay=15):
to_dir=os.curdir, delay=15,
downloader_factory=get_best_downloader):
"""Download setuptools from a specified location and return its filename
`version` should be a valid setuptools version number that is available
as an egg for download under the `download_base` URL (which should end
with a '/'). `to_dir` is the directory where the egg will be downloaded.
`delay` is the number of seconds to pause before an actual download
attempt.
``downloader_factory`` should be a function taking no arguments and
returning a function for downloading a URL to a target.
"""
# making sure we use the absolute path
to_dir = os.path.abspath(to_dir)
Expand All @@ -270,7 +274,7 @@ def download_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL,
saveto = os.path.join(to_dir, tgz_name)
if not os.path.exists(saveto): # Avoid repeated downloads
log.warn("Downloading %s", url)
downloader = get_best_downloader()
downloader = downloader_factory()
downloader(url, saveto)
return os.path.realpath(saveto)

Expand Down Expand Up @@ -346,14 +350,20 @@ def _parse_args():
'--download-base', dest='download_base', metavar="URL",
default=DEFAULT_URL,
help='alternative URL from where to download the setuptools package')
parser.add_option(
'--insecure', dest='downloader_factory', action='store_const',
const=lambda: download_file_insecure, default=get_best_downloader,
help='Use internal, non-validating downloader'
)
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)
tarball = download_setuptools(download_base=options.download_base,
downloader_factory=options.downloader_factory)
return _install(tarball, _build_install_args(options))

if __name__ == '__main__':
Expand Down

0 comments on commit 0424d55

Please sign in to comment.