~sambuddhabasu1/mailman/fix_mailman_run_error

« back to all changes in this revision

Viewing changes to bootstrap.py

  • Committer: Barry Warsaw
  • Date: 2009-11-24 03:20:48 UTC
  • Revision ID: barry@python.org-20091124032048-wi6uoch11nlyksb7
* Switch to distribute from setuptools.
* Remove the dependency on setuptools_bzr and use a MANIFEST.in instead

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
##############################################################################
2
2
#
3
 
# Copyright (c) 2006 Zope Foundation and Contributors.
 
3
# Copyright (c) 2006 Zope Corporation and Contributors.
4
4
# All Rights Reserved.
5
5
#
6
6
# This software is subject to the provisions of the Zope Public License,
16
16
Simply run this script in a directory containing a buildout.cfg.
17
17
The script accepts buildout command-line options, so you can
18
18
use the -c option to specify an alternate configuration file.
 
19
 
 
20
$Id$
19
21
"""
20
22
 
21
 
import os, shutil, sys, tempfile
22
 
from optparse import OptionParser
 
23
import os, shutil, sys, tempfile, urllib2
23
24
 
24
25
tmpeggs = tempfile.mkdtemp()
25
26
 
26
 
usage = '''\
27
 
[DESIRED PYTHON FOR BUILDOUT] bootstrap.py [options]
28
 
 
29
 
Bootstraps a buildout-based project.
30
 
 
31
 
Simply run this script in a directory containing a buildout.cfg, using the
32
 
Python that you want bin/buildout to use.
33
 
 
34
 
Note that by using --setup-source and --download-base to point to
35
 
local resources, you can keep this script from going over the network.
36
 
'''
37
 
 
38
 
parser = OptionParser(usage=usage)
39
 
parser.add_option("-v", "--version", help="use a specific zc.buildout version")
40
 
 
41
 
parser.add_option("-t", "--accept-buildout-test-releases",
42
 
                  dest='accept_buildout_test_releases',
43
 
                  action="store_true", default=False,
44
 
                  help=("Normally, if you do not specify a --version, the "
45
 
                        "bootstrap script and buildout gets the newest "
46
 
                        "*final* versions of zc.buildout and its recipes and "
47
 
                        "extensions for you.  If you use this flag, "
48
 
                        "bootstrap and buildout will get the newest releases "
49
 
                        "even if they are alphas or betas."))
50
 
parser.add_option("-c", "--config-file",
51
 
                   help=("Specify the path to the buildout configuration "
52
 
                         "file to be used."))
53
 
parser.add_option("-f", "--find-links",
54
 
                   help=("Specify a URL to search for buildout releases"))
55
 
 
56
 
 
57
 
options, args = parser.parse_args()
58
 
 
59
 
######################################################################
60
 
# load/install distribute
61
 
 
62
 
to_reload = False
 
27
is_jython = sys.platform.startswith('java')
 
28
 
63
29
try:
64
 
    import pkg_resources, setuptools
65
 
    if not hasattr(pkg_resources, '_distribute'):
66
 
        to_reload = True
67
 
        raise ImportError
 
30
    import pkg_resources
68
31
except ImportError:
69
32
    ez = {}
70
 
 
71
 
    try:
72
 
        from urllib.request import urlopen
73
 
    except ImportError:
74
 
        from urllib2 import urlopen
75
 
 
76
 
    exec(urlopen('http://python-distribute.org/distribute_setup.py').read(), ez)
77
 
    setup_args = dict(to_dir=tmpeggs, download_delay=0, no_fake=True)
78
 
    ez['use_setuptools'](**setup_args)
79
 
 
80
 
    if to_reload:
81
 
        reload(pkg_resources)
 
33
    exec urllib2.urlopen('http://peak.telecommunity.com/dist/ez_setup.py'
 
34
                         ).read() in ez
 
35
    ez['use_setuptools'](to_dir=tmpeggs, download_delay=0)
 
36
 
82
37
    import pkg_resources
83
 
    # This does not (always?) update the default working set.  We will
84
 
    # do it.
85
 
    for path in sys.path:
86
 
        if path not in pkg_resources.working_set.entries:
87
 
            pkg_resources.working_set.add_entry(path)
88
 
 
89
 
######################################################################
90
 
# Install buildout
91
 
 
 
38
 
 
39
if sys.platform == 'win32':
 
40
    def quote(c):
 
41
        if ' ' in c:
 
42
            return '"%s"' % c # work around spawn lamosity on windows
 
43
        else:
 
44
            return c
 
45
else:
 
46
    def quote (c):
 
47
        return c
 
48
 
 
49
cmd = 'from setuptools.command.easy_install import main; main()'
92
50
ws  = pkg_resources.working_set
93
51
 
94
 
cmd = [sys.executable, '-c',
95
 
       'from setuptools.command.easy_install import main; main()',
96
 
       '-mZqNxd', tmpeggs]
97
 
 
98
 
find_links = os.environ.get(
99
 
    'bootstrap-testing-find-links',
100
 
    options.find_links or
101
 
    ('http://downloads.buildout.org/'
102
 
     if options.accept_buildout_test_releases else None)
103
 
    )
104
 
if find_links:
105
 
    cmd.extend(['-f', find_links])
106
 
 
107
 
distribute_path = ws.find(
108
 
    pkg_resources.Requirement.parse('distribute')).location
109
 
 
110
 
requirement = 'zc.buildout'
111
 
version = options.version
112
 
if version is None and not options.accept_buildout_test_releases:
113
 
    # Figure out the most recent final version of zc.buildout.
114
 
    import setuptools.package_index
115
 
    _final_parts = '*final-', '*final'
116
 
    def _final_version(parsed_version):
117
 
        for part in parsed_version:
118
 
            if (part[:1] == '*') and (part not in _final_parts):
119
 
                return False
120
 
        return True
121
 
    index = setuptools.package_index.PackageIndex(
122
 
        search_path=[distribute_path])
123
 
    if find_links:
124
 
        index.add_find_links((find_links,))
125
 
    req = pkg_resources.Requirement.parse(requirement)
126
 
    if index.obtain(req) is not None:
127
 
        best = []
128
 
        bestv = None
129
 
        for dist in index[req.project_name]:
130
 
            distv = dist.parsed_version
131
 
            if _final_version(distv):
132
 
                if bestv is None or distv > bestv:
133
 
                    best = [dist]
134
 
                    bestv = distv
135
 
                elif distv == bestv:
136
 
                    best.append(dist)
137
 
        if best:
138
 
            best.sort()
139
 
            version = best[-1].version
140
 
if version:
141
 
    requirement = '=='.join((requirement, version))
142
 
cmd.append(requirement)
143
 
 
144
 
import subprocess
145
 
if subprocess.call(cmd, env=dict(os.environ, PYTHONPATH=distribute_path)) != 0:
146
 
    raise Exception(
147
 
        "Failed to execute command:\n%s",
148
 
        repr(cmd)[1:-1])
149
 
 
150
 
######################################################################
151
 
# Import and run buildout
 
52
if is_jython:
 
53
    import subprocess
 
54
    
 
55
    assert subprocess.Popen([sys.executable] + ['-c', quote(cmd), '-mqNxd', 
 
56
           quote(tmpeggs), 'zc.buildout'], 
 
57
           env=dict(os.environ,
 
58
               PYTHONPATH=
 
59
               ws.find(pkg_resources.Requirement.parse('setuptools')).location
 
60
               ),
 
61
           ).wait() == 0
 
62
 
 
63
else:
 
64
    assert os.spawnle(
 
65
        os.P_WAIT, sys.executable, quote (sys.executable),
 
66
        '-c', quote (cmd), '-mqNxd', quote (tmpeggs), 'zc.buildout',
 
67
        dict(os.environ,
 
68
            PYTHONPATH=
 
69
            ws.find(pkg_resources.Requirement.parse('setuptools')).location
 
70
            ),
 
71
        ) == 0
152
72
 
153
73
ws.add_entry(tmpeggs)
154
 
ws.require(requirement)
 
74
ws.require('zc.buildout')
155
75
import zc.buildout.buildout
156
 
 
157
 
if not [a for a in args if '=' not in a]:
158
 
    args.append('bootstrap')
159
 
 
160
 
# if -c was provided, we push it back into args for buildout' main function
161
 
if options.config_file is not None:
162
 
    args[0:0] = ['-c', options.config_file]
163
 
 
164
 
zc.buildout.buildout.main(args)
 
76
zc.buildout.buildout.main(sys.argv[1:] + ['bootstrap'])
165
77
shutil.rmtree(tmpeggs)