Code

Ticket #11023: setuptools.diff

File setuptools.diff, 13.6 KB (added by benoitc, 5 years ago)

setuptools diff

Line 
1diff -r 97f6606f42b7 django/trunk/ez_setup.py
2--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
3+++ b/django/trunk/ez_setup.py  Thu May 07 12:24:59 2009 +0200
4@@ -0,0 +1,276 @@
5+#!python
6+"""Bootstrap setuptools installation
7+
8+If you want to use setuptools in your package's setup.py, just include this
9+file in the same directory with it, and add this to the top of your setup.py::
10+
11+    from ez_setup import use_setuptools
12+    use_setuptools()
13+
14+If you want to require a specific version of setuptools, set a download
15+mirror, or use an alternate download directory, you can do so by supplying
16+the appropriate options to ``use_setuptools()``.
17+
18+This file can also be run as a script to install or upgrade setuptools.
19+"""
20+import sys
21+DEFAULT_VERSION = "0.6c7"
22+DEFAULT_URL     = "http://pypi.python.org/packages/%s/s/setuptools/" % sys.version[:3]
23+
24+md5_data = {
25+    'setuptools-0.6b1-py2.3.egg': '8822caf901250d848b996b7f25c6e6ca',
26+    'setuptools-0.6b1-py2.4.egg': 'b79a8a403e4502fbb85ee3f1941735cb',
27+    'setuptools-0.6b2-py2.3.egg': '5657759d8a6d8fc44070a9d07272d99b',
28+    'setuptools-0.6b2-py2.4.egg': '4996a8d169d2be661fa32a6e52e4f82a',
29+    'setuptools-0.6b3-py2.3.egg': 'bb31c0fc7399a63579975cad9f5a0618',
30+    'setuptools-0.6b3-py2.4.egg': '38a8c6b3d6ecd22247f179f7da669fac',
31+    'setuptools-0.6b4-py2.3.egg': '62045a24ed4e1ebc77fe039aa4e6f7e5',
32+    'setuptools-0.6b4-py2.4.egg': '4cb2a185d228dacffb2d17f103b3b1c4',
33+    'setuptools-0.6c1-py2.3.egg': 'b3f2b5539d65cb7f74ad79127f1a908c',
34+    'setuptools-0.6c1-py2.4.egg': 'b45adeda0667d2d2ffe14009364f2a4b',
35+    'setuptools-0.6c2-py2.3.egg': 'f0064bf6aa2b7d0f3ba0b43f20817c27',
36+    'setuptools-0.6c2-py2.4.egg': '616192eec35f47e8ea16cd6a122b7277',
37+    'setuptools-0.6c3-py2.3.egg': 'f181fa125dfe85a259c9cd6f1d7b78fa',
38+    'setuptools-0.6c3-py2.4.egg': 'e0ed74682c998bfb73bf803a50e7b71e',
39+    'setuptools-0.6c3-py2.5.egg': 'abef16fdd61955514841c7c6bd98965e',
40+    'setuptools-0.6c4-py2.3.egg': 'b0b9131acab32022bfac7f44c5d7971f',
41+    'setuptools-0.6c4-py2.4.egg': '2a1f9656d4fbf3c97bf946c0a124e6e2',
42+    'setuptools-0.6c4-py2.5.egg': '8f5a052e32cdb9c72bcf4b5526f28afc',
43+    'setuptools-0.6c5-py2.3.egg': 'ee9fd80965da04f2f3e6b3576e9d8167',
44+    'setuptools-0.6c5-py2.4.egg': 'afe2adf1c01701ee841761f5bcd8aa64',
45+    'setuptools-0.6c5-py2.5.egg': 'a8d3f61494ccaa8714dfed37bccd3d5d',
46+    'setuptools-0.6c6-py2.3.egg': '35686b78116a668847237b69d549ec20',
47+    'setuptools-0.6c6-py2.4.egg': '3c56af57be3225019260a644430065ab',
48+    'setuptools-0.6c6-py2.5.egg': 'b2f8a7520709a5b34f80946de5f02f53',
49+    'setuptools-0.6c7-py2.3.egg': '209fdf9adc3a615e5115b725658e13e2',
50+    'setuptools-0.6c7-py2.4.egg': '5a8f954807d46a0fb67cf1f26c55a82e',
51+    'setuptools-0.6c7-py2.5.egg': '45d2ad28f9750e7434111fde831e8372',
52+    'setuptools-0.6c8-py2.3.egg': '50759d29b349db8cfd807ba8303f1902',
53+    'setuptools-0.6c8-py2.4.egg': 'cba38d74f7d483c06e9daa6070cce6de',
54+    'setuptools-0.6c8-py2.5.egg': '1721747ee329dc150590a58b3e1ac95b',
55+    'setuptools-0.6c9-py2.3.egg': 'a83c4020414807b496e4cfbe08507c03',
56+    'setuptools-0.6c9-py2.4.egg': '260a2be2e5388d66bdaee06abec6342a',
57+    'setuptools-0.6c9-py2.5.egg': 'fe67c3e5a17b12c0e7c541b7ea43a8e6',
58+    'setuptools-0.6c9-py2.6.egg': 'ca37b1ff16fa2ede6e19383e7b59245a',
59+}
60+
61+import sys, os
62+try: from hashlib import md5
63+except ImportError: from md5 import md5
64+
65+def _validate_md5(egg_name, data):
66+    if egg_name in md5_data:
67+        digest = md5(data).hexdigest()
68+        if digest != md5_data[egg_name]:
69+            print >>sys.stderr, (
70+                "md5 validation of %s failed!  (Possible download problem?)"
71+                % egg_name
72+            )
73+            sys.exit(2)
74+    return data
75+
76+def use_setuptools(
77+    version=DEFAULT_VERSION, download_base=DEFAULT_URL, to_dir=os.curdir,
78+    download_delay=15
79+):
80+    """Automatically find/download setuptools and make it available on sys.path
81+
82+    `version` should be a valid setuptools version number that is available
83+    as an egg for download under the `download_base` URL (which should end with
84+    a '/').  `to_dir` is the directory where setuptools will be downloaded, if
85+    it is not already available.  If `download_delay` is specified, it should
86+    be the number of seconds that will be paused before initiating a download,
87+    should one be required.  If an older version of setuptools is installed,
88+    this routine will print a message to ``sys.stderr`` and raise SystemExit in
89+    an attempt to abort the calling script.
90+    """
91+    was_imported = 'pkg_resources' in sys.modules or 'setuptools' in sys.modules
92+    def do_download():
93+        egg = download_setuptools(version, download_base, to_dir, download_delay)
94+        sys.path.insert(0, egg)
95+        import setuptools; setuptools.bootstrap_install_from = egg
96+    try:
97+        import pkg_resources
98+    except ImportError:
99+        return do_download()       
100+    try:
101+        pkg_resources.require("setuptools>="+version); return
102+    except pkg_resources.VersionConflict, e:
103+        if was_imported:
104+            print >>sys.stderr, (
105+            "The required version of setuptools (>=%s) is not available, and\n"
106+            "can't be installed while this script is running. Please install\n"
107+            " a more recent version first, using 'easy_install -U setuptools'."
108+            "\n\n(Currently using %r)"
109+            ) % (version, e.args[0])
110+            sys.exit(2)
111+        else:
112+            del pkg_resources, sys.modules['pkg_resources']    # reload ok
113+            return do_download()
114+    except pkg_resources.DistributionNotFound:
115+        return do_download()
116+
117+def download_setuptools(
118+    version=DEFAULT_VERSION, download_base=DEFAULT_URL, to_dir=os.curdir,
119+    delay = 15
120+):
121+    """Download setuptools from a specified location and return its filename
122+
123+    `version` should be a valid setuptools version number that is available
124+    as an egg for download under the `download_base` URL (which should end
125+    with a '/'). `to_dir` is the directory where the egg will be downloaded.
126+    `delay` is the number of seconds to pause before an actual download attempt.
127+    """
128+    import urllib2, shutil
129+    egg_name = "setuptools-%s-py%s.egg" % (version,sys.version[:3])
130+    url = download_base + egg_name
131+    saveto = os.path.join(to_dir, egg_name)
132+    src = dst = None
133+    if not os.path.exists(saveto):  # Avoid repeated downloads
134+        try:
135+            from distutils import log
136+            if delay:
137+                log.warn("""
138+---------------------------------------------------------------------------
139+This script requires setuptools version %s to run (even to display
140+help).  I will attempt to download it for you (from
141+%s), but
142+you may need to enable firewall access for this script first.
143+I will start the download in %d seconds.
144+
145+(Note: if this machine does not have network access, please obtain the file
146+
147+   %s
148+
149+and place it in this directory before rerunning this script.)
150+---------------------------------------------------------------------------""",
151+                    version, download_base, delay, url
152+                ); from time import sleep; sleep(delay)
153+            log.warn("Downloading %s", url)
154+            src = urllib2.urlopen(url)
155+            # Read/write all in one block, so we don't create a corrupt file
156+            # if the download is interrupted.
157+            data = _validate_md5(egg_name, src.read())
158+            dst = open(saveto,"wb"); dst.write(data)
159+        finally:
160+            if src: src.close()
161+            if dst: dst.close()
162+    return os.path.realpath(saveto)
163+
164+
165+
166+
167+
168+
169+
170+
171+
172+
173+
174+
175+
176+
177+
178+
179+
180+
181+
182+
183+
184+
185+
186+
187+
188+
189+
190+
191+
192+
193+
194+
195+
196+
197+
198+
199+def main(argv, version=DEFAULT_VERSION):
200+    """Install or upgrade setuptools and EasyInstall"""
201+    try:
202+        import setuptools
203+    except ImportError:
204+        egg = None
205+        try:
206+            egg = download_setuptools(version, delay=0)
207+            sys.path.insert(0,egg)
208+            from setuptools.command.easy_install import main
209+            return main(list(argv)+[egg])   # we're done here
210+        finally:
211+            if egg and os.path.exists(egg):
212+                os.unlink(egg)
213+    else:
214+        if setuptools.__version__ == '0.0.1':
215+            print >>sys.stderr, (
216+            "You have an obsolete version of setuptools installed.  Please\n"
217+            "remove it from your system entirely before rerunning this script."
218+            )
219+            sys.exit(2)
220+
221+    req = "setuptools>="+version
222+    import pkg_resources
223+    try:
224+        pkg_resources.require(req)
225+    except pkg_resources.VersionConflict:
226+        try:
227+            from setuptools.command.easy_install import main
228+        except ImportError:
229+            from easy_install import main
230+        main(list(argv)+[download_setuptools(delay=0)])
231+        sys.exit(0) # try to force an exit
232+    else:
233+        if argv:
234+            from setuptools.command.easy_install import main
235+            main(argv)
236+        else:
237+            print "Setuptools version",version,"or greater has been installed."
238+            print '(Run "ez_setup.py -U setuptools" to reinstall or upgrade.)'
239+
240+def update_md5(filenames):
241+    """Update our built-in md5 registry"""
242+
243+    import re
244+
245+    for name in filenames:
246+        base = os.path.basename(name)
247+        f = open(name,'rb')
248+        md5_data[base] = md5(f.read()).hexdigest()
249+        f.close()
250+
251+    data = ["    %r: %r,\n" % it for it in md5_data.items()]
252+    data.sort()
253+    repl = "".join(data)
254+
255+    import inspect
256+    srcfile = inspect.getsourcefile(sys.modules[__name__])
257+    f = open(srcfile, 'rb'); src = f.read(); f.close()
258+
259+    match = re.search("\nmd5_data = {\n([^}]+)}", src)
260+    if not match:
261+        print >>sys.stderr, "Internal error!"
262+        sys.exit(2)
263+
264+    src = src[:match.start(1)] + repl + src[match.end(1):]
265+    f = open(srcfile,'w')
266+    f.write(src)
267+    f.close()
268+
269+
270+if __name__=='__main__':
271+    if len(sys.argv)>2 and sys.argv[1]=='--md5update':
272+        update_md5(sys.argv[2:])
273+    else:
274+        main(sys.argv[1:])
275+
276+
277+
278+
279+
280+
281diff -r 97f6606f42b7 django/trunk/setup.py
282--- a/django/trunk/setup.py     Wed May 06 07:37:43 2009 +0000
283+++ b/django/trunk/setup.py     Thu May 07 12:24:59 2009 +0200
284@@ -1,50 +1,19 @@
285-from distutils.core import setup
286-from distutils.command.install_data import install_data
287-from distutils.command.install import INSTALL_SCHEMES
288+#!/usr/bin/env python
289+# -*- coding: utf-8 -*-
290+
291+try:
292+    from setuptools import setup, find_packages
293+except ImportError:
294+    import ez_setup
295+    ez_setup.use_setuptools()
296+    from setuptools import setup, find_packages
297+
298 import os
299 import sys
300 
301-class osx_install_data(install_data):
302-    # On MacOS, the platform-specific lib dir is /System/Library/Framework/Python/.../
303-    # which is wrong. Python 2.5 supplied with MacOS 10.5 has an Apple-specific fix
304-    # for this in distutils.command.install_data#306. It fixes install_lib but not
305-    # install_data, which is why we roll our own install_data class.
306-
307-    def finalize_options(self):
308-        # By the time finalize_options is called, install.install_lib is set to the
309-        # fixed directory, so we set the installdir to install_lib. The
310-        # install_data class uses ('install_data', 'install_dir') instead.
311-        self.set_undefined_options('install', ('install_lib', 'install_dir'))
312-        install_data.finalize_options(self)
313-
314-if sys.platform == "darwin":
315-    cmdclasses = {'install_data': osx_install_data}
316-else:
317-    cmdclasses = {'install_data': install_data}
318-
319-def fullsplit(path, result=None):
320-    """
321-    Split a pathname into components (the opposite of os.path.join) in a
322-    platform-neutral way.
323-    """
324-    if result is None:
325-        result = []
326-    head, tail = os.path.split(path)
327-    if head == '':
328-        return [tail] + result
329-    if head == path:
330-        return result
331-    return fullsplit(head, [tail] + result)
332-
333-# Tell distutils to put the data_files in platform-specific installation
334-# locations. See here for an explanation:
335-# http://groups.google.com/group/comp.lang.python/browse_thread/thread/35ec7b2fed36eaec/2105ee4d9e8042cb
336-for scheme in INSTALL_SCHEMES.values():
337-    scheme['data'] = scheme['purelib']
338-
339 # Compile the list of packages available, because distutils doesn't have
340 # an easy way to do this.
341-packages, data_files = [], []
342+data_files = []
343 root_dir = os.path.dirname(__file__)
344 if root_dir != '':
345     os.chdir(root_dir)
346@@ -54,16 +23,9 @@
347     # Ignore dirnames that start with '.'
348     for i, dirname in enumerate(dirnames):
349         if dirname.startswith('.'): del dirnames[i]
350-    if '__init__.py' in filenames:
351-        packages.append('.'.join(fullsplit(dirpath)))
352-    elif filenames:
353+    if filenames:
354         data_files.append([dirpath, [os.path.join(dirpath, f) for f in filenames]])
355 
356-# Small hack for working with bdist_wininst.
357-# See http://mail.python.org/pipermail/distutils-sig/2004-August/004134.html
358-if len(sys.argv) > 1 and sys.argv[1] == 'bdist_wininst':
359-    for file_info in data_files:
360-        file_info[0] = '\\PURELIB\\%s' % file_info[0]
361 
362 # Dynamically calculate the version based on django.VERSION.
363 version = __import__('django').get_version()
364@@ -78,9 +40,11 @@
365     author = 'Django Software Foundation',
366     author_email = 'foundation@djangoproject.com',
367     description = 'A high-level Python Web framework that encourages rapid development and clean, pragmatic design.',
368-    packages = packages,
369-    cmdclass = cmdclasses,
370+    platforms = ['any'],
371+    zip_safe = False,
372+    packages=find_packages(),
373     data_files = data_files,
374+    include_package_data = True,
375     scripts = ['django/bin/django-admin.py'],
376     classifiers = ['Development Status :: 3 - Alpha',
377                    'Environment :: Web Environment',