annotate ez_setup.py @ 595:d78126d82ca0 frontends_multi_profiles

browser side (blog module): fixed isJidAccepted + added __str__ method to facilitate debugging + use of AttributeError and TypeError in some exception (because pyjamas can raise both depending on compilation options)
author Goffi <goffi@goffi.org>
date Fri, 06 Feb 2015 19:15:52 +0100
parents 77bf2654ca0a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
560
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
1 #!/usr/bin/env python
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
2 """Bootstrap setuptools installation
360
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
3
560
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
4 To use setuptools in your package's setup.py, include this
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
5 file in the same directory and add this to the top of your setup.py::
360
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
6
560
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
7 from ez_setup import use_setuptools
360
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
8 use_setuptools()
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
9
560
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
10 To require a specific version of setuptools, set a download
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
11 mirror, or use an alternate download directory, simply supply
360
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
12 the appropriate options to ``use_setuptools()``.
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
13
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
14 This file can also be run as a script to install or upgrade setuptools.
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
15 """
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
16 import os
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
17 import shutil
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
18 import sys
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
19 import tempfile
560
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
20 import zipfile
360
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
21 import optparse
560
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
22 import subprocess
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
23 import platform
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
24 import textwrap
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
25 import contextlib
360
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
26
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
27 from distutils import log
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
28
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
29 try:
560
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
30 from urllib.request import urlopen
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
31 except ImportError:
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
32 from urllib2 import urlopen
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
33
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
34 try:
360
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
35 from site import USER_SITE
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
36 except ImportError:
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
37 USER_SITE = None
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
38
560
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
39 DEFAULT_VERSION = "5.5"
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
40 DEFAULT_URL = "https://pypi.python.org/packages/source/s/setuptools/"
360
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
41
560
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
42 def _python_cmd(*args):
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
43 """
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
44 Return True if the command succeeded.
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
45 """
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
46 args = (sys.executable,) + args
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
47 return subprocess.call(args) == 0
360
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
48
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
49
560
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
50 def _install(archive_filename, install_args=()):
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
51 with archive_context(archive_filename):
360
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
52 # installing
560
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
53 log.warn('Installing Setuptools')
360
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
54 if not _python_cmd('setup.py', 'install', *install_args):
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
55 log.warn('Something went wrong during the installation.')
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
56 log.warn('See the error message above.')
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
57 # exitcode will be 2
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
58 return 2
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
59
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
60
560
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
61 def _build_egg(egg, archive_filename, to_dir):
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
62 with archive_context(archive_filename):
360
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
63 # building an egg
560
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
64 log.warn('Building a Setuptools egg in %s', to_dir)
360
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
65 _python_cmd('setup.py', '-q', 'bdist_egg', '--dist-dir', to_dir)
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
66 # returning the result
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
67 log.warn(egg)
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
68 if not os.path.exists(egg):
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
69 raise IOError('Could not build the egg.')
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
70
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
71
560
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
72 class ContextualZipFile(zipfile.ZipFile):
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
73 """
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
74 Supplement ZipFile class to support context manager for Python 2.6
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
75 """
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
76
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
77 def __enter__(self):
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
78 return self
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
79
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
80 def __exit__(self, type, value, traceback):
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
81 self.close()
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
82
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
83 def __new__(cls, *args, **kwargs):
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
84 """
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
85 Construct a ZipFile or ContextualZipFile as appropriate
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
86 """
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
87 if hasattr(zipfile.ZipFile, '__exit__'):
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
88 return zipfile.ZipFile(*args, **kwargs)
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
89 return super(ContextualZipFile, cls).__new__(cls)
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
90
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
91
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
92 @contextlib.contextmanager
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
93 def archive_context(filename):
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
94 # extracting the archive
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
95 tmpdir = tempfile.mkdtemp()
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
96 log.warn('Extracting in %s', tmpdir)
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
97 old_wd = os.getcwd()
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
98 try:
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
99 os.chdir(tmpdir)
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
100 with ContextualZipFile(filename) as archive:
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
101 archive.extractall()
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
102
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
103 # going in the directory
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
104 subdir = os.path.join(tmpdir, os.listdir(tmpdir)[0])
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
105 os.chdir(subdir)
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
106 log.warn('Now working in %s', subdir)
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
107 yield
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
108
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
109 finally:
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
110 os.chdir(old_wd)
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
111 shutil.rmtree(tmpdir)
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
112
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
113
360
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
114 def _do_download(version, download_base, to_dir, download_delay):
560
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
115 egg = os.path.join(to_dir, 'setuptools-%s-py%d.%d.egg'
360
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
116 % (version, sys.version_info[0], sys.version_info[1]))
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
117 if not os.path.exists(egg):
560
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
118 archive = download_setuptools(version, download_base,
360
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
119 to_dir, download_delay)
560
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
120 _build_egg(egg, archive, to_dir)
360
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
121 sys.path.insert(0, egg)
560
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
122
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
123 # Remove previously-imported pkg_resources if present (see
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
124 # https://bitbucket.org/pypa/setuptools/pull-request/7/ for details).
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
125 if 'pkg_resources' in sys.modules:
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
126 del sys.modules['pkg_resources']
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
127
360
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
128 import setuptools
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
129 setuptools.bootstrap_install_from = egg
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
130
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
131
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
132 def use_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL,
560
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
133 to_dir=os.curdir, download_delay=15):
360
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
134 to_dir = os.path.abspath(to_dir)
560
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
135 rep_modules = 'pkg_resources', 'setuptools'
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
136 imported = set(sys.modules).intersection(rep_modules)
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
137 try:
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
138 import pkg_resources
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
139 except ImportError:
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
140 return _do_download(version, download_base, to_dir, download_delay)
360
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
141 try:
560
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
142 pkg_resources.require("setuptools>=" + version)
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
143 return
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
144 except pkg_resources.DistributionNotFound:
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
145 return _do_download(version, download_base, to_dir, download_delay)
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
146 except pkg_resources.VersionConflict as VC_err:
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
147 if imported:
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
148 msg = textwrap.dedent("""
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
149 The required version of setuptools (>={version}) is not available,
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
150 and can't be installed while this script is running. Please
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
151 install a more recent version first, using
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
152 'easy_install -U setuptools'.
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
153
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
154 (Currently using {VC_err.args[0]!r})
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
155 """).format(VC_err=VC_err, version=version)
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
156 sys.stderr.write(msg)
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
157 sys.exit(2)
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
158
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
159 # otherwise, reload ok
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
160 del pkg_resources, sys.modules['pkg_resources']
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
161 return _do_download(version, download_base, to_dir, download_delay)
360
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
162
560
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
163 def _clean_check(cmd, target):
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
164 """
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
165 Run the command to download target. If the command fails, clean up before
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
166 re-raising the error.
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
167 """
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
168 try:
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
169 subprocess.check_call(cmd)
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
170 except subprocess.CalledProcessError:
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
171 if os.access(target, os.F_OK):
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
172 os.unlink(target)
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
173 raise
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
174
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
175 def download_file_powershell(url, target):
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
176 """
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
177 Download the file at url to target using Powershell (which will validate
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
178 trust). Raise an exception if the command cannot complete.
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
179 """
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
180 target = os.path.abspath(target)
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
181 ps_cmd = (
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
182 "[System.Net.WebRequest]::DefaultWebProxy.Credentials = "
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
183 "[System.Net.CredentialCache]::DefaultCredentials; "
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
184 "(new-object System.Net.WebClient).DownloadFile(%(url)r, %(target)r)"
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
185 % vars()
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
186 )
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
187 cmd = [
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
188 'powershell',
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
189 '-Command',
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
190 ps_cmd,
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
191 ]
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
192 _clean_check(cmd, target)
360
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
193
560
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
194 def has_powershell():
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
195 if platform.system() != 'Windows':
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
196 return False
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
197 cmd = ['powershell', '-Command', 'echo test']
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
198 with open(os.path.devnull, 'wb') as devnull:
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
199 try:
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
200 subprocess.check_call(cmd, stdout=devnull, stderr=devnull)
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
201 except Exception:
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
202 return False
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
203 return True
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
204
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
205 download_file_powershell.viable = has_powershell
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
206
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
207 def download_file_curl(url, target):
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
208 cmd = ['curl', url, '--silent', '--output', target]
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
209 _clean_check(cmd, target)
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
210
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
211 def has_curl():
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
212 cmd = ['curl', '--version']
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
213 with open(os.path.devnull, 'wb') as devnull:
360
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
214 try:
560
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
215 subprocess.check_call(cmd, stdout=devnull, stderr=devnull)
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
216 except Exception:
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
217 return False
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
218 return True
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
219
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
220 download_file_curl.viable = has_curl
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
221
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
222 def download_file_wget(url, target):
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
223 cmd = ['wget', url, '--quiet', '--output-document', target]
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
224 _clean_check(cmd, target)
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
225
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
226 def has_wget():
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
227 cmd = ['wget', '--version']
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
228 with open(os.path.devnull, 'wb') as devnull:
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
229 try:
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
230 subprocess.check_call(cmd, stdout=devnull, stderr=devnull)
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
231 except Exception:
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
232 return False
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
233 return True
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
234
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
235 download_file_wget.viable = has_wget
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
236
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
237 def download_file_insecure(url, target):
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
238 """
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
239 Use Python to download the file, even though it cannot authenticate the
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
240 connection.
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
241 """
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
242 src = urlopen(url)
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
243 try:
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
244 # Read all the data in one block.
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
245 data = src.read()
360
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
246 finally:
560
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
247 src.close()
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
248
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
249 # Write all the data in one block to avoid creating a partial file.
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
250 with open(target, "wb") as dst:
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
251 dst.write(data)
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
252
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
253 download_file_insecure.viable = lambda: True
360
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
254
560
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
255 def get_best_downloader():
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
256 downloaders = (
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
257 download_file_powershell,
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
258 download_file_curl,
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
259 download_file_wget,
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
260 download_file_insecure,
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
261 )
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
262 viable_downloaders = (dl for dl in downloaders if dl.viable())
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
263 return next(viable_downloaders, None)
360
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
264
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
265 def download_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL,
560
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
266 to_dir=os.curdir, delay=15, downloader_factory=get_best_downloader):
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
267 """
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
268 Download setuptools from a specified location and return its filename
360
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
269
560
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
270 `version` should be a valid setuptools version number that is available
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
271 as an sdist for download under the `download_base` URL (which should end
360
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
272 with a '/'). `to_dir` is the directory where the egg will be downloaded.
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
273 `delay` is the number of seconds to pause before an actual download
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
274 attempt.
560
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
275
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
276 ``downloader_factory`` should be a function taking no arguments and
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
277 returning a function for downloading a URL to a target.
360
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
278 """
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
279 # making sure we use the absolute path
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
280 to_dir = os.path.abspath(to_dir)
560
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
281 zip_name = "setuptools-%s.zip" % version
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
282 url = download_base + zip_name
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
283 saveto = os.path.join(to_dir, zip_name)
360
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
284 if not os.path.exists(saveto): # Avoid repeated downloads
560
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
285 log.warn("Downloading %s", url)
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
286 downloader = downloader_factory()
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
287 downloader(url, saveto)
360
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
288 return os.path.realpath(saveto)
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
289
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
290 def _build_install_args(options):
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
291 """
560
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
292 Build the arguments to 'python setup.py install' on the setuptools package
360
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
293 """
560
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
294 return ['--user'] if options.user_install else []
360
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
295
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
296 def _parse_args():
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
297 """
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
298 Parse the command line for options
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
299 """
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
300 parser = optparse.OptionParser()
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
301 parser.add_option(
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
302 '--user', dest='user_install', action='store_true', default=False,
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
303 help='install in user site package (requires Python 2.6 or later)')
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
304 parser.add_option(
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
305 '--download-base', dest='download_base', metavar="URL",
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
306 default=DEFAULT_URL,
560
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
307 help='alternative URL from where to download the setuptools package')
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
308 parser.add_option(
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
309 '--insecure', dest='downloader_factory', action='store_const',
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
310 const=lambda: download_file_insecure, default=get_best_downloader,
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
311 help='Use internal, non-validating downloader'
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
312 )
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
313 parser.add_option(
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
314 '--version', help="Specify which version to download",
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
315 default=DEFAULT_VERSION,
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
316 )
360
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
317 options, args = parser.parse_args()
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
318 # positional arguments are ignored
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
319 return options
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
320
560
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
321 def main():
360
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
322 """Install or upgrade setuptools and EasyInstall"""
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
323 options = _parse_args()
560
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
324 archive = download_setuptools(
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
325 version=options.version,
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
326 download_base=options.download_base,
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
327 downloader_factory=options.downloader_factory,
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
328 )
77bf2654ca0a installation: replaced the deprecated distribute_setup.py by ez_setup.py
Goffi <goffi@goffi.org>
parents: 360
diff changeset
329 return _install(archive, _build_install_args(options))
360
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
330
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
331 if __name__ == '__main__':
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
332 sys.exit(main())