Browse code

remove ez_setup

ez_setup is annoying. pip install s3cmd always complains that
setuptools isn't new enough, and you've got to update that. In
Fedora and all sane build systems, the RPM package build can't use
ez_setup as it downloads bits, which isn't allowed, so I had removed
ez_setup frm there already.

We aren't using any new features from setuptools that the base repo
packages don't already provide. pip already requires setuptools, so
installing via pip we don't need to add anything. We added the RPM
BuildRequires: python-setuptools a few commits ago, so building there
is fine.

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