annotate bootstrap.py @ 236:39b50b763f11

New collections database representation.
author Daniele Nicolodi <daniele@grinta.net>
date Mon, 12 Dec 2011 15:10:28 +0100
parents 66101b35a8c0
children 773d9567dcb2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
c812c3020b63 Initial import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
1 ##############################################################################
c812c3020b63 Initial import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
2 #
11
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
3 # Copyright (c) 2006 Zope Foundation and Contributors.
0
c812c3020b63 Initial import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
4 # All Rights Reserved.
c812c3020b63 Initial import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
5 #
c812c3020b63 Initial import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
6 # This software is subject to the provisions of the Zope Public License,
c812c3020b63 Initial import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
7 # Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
c812c3020b63 Initial import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
8 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
c812c3020b63 Initial import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
9 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
c812c3020b63 Initial import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
10 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
c812c3020b63 Initial import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
11 # FOR A PARTICULAR PURPOSE.
c812c3020b63 Initial import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
12 #
c812c3020b63 Initial import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
13 ##############################################################################
c812c3020b63 Initial import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
14 """Bootstrap a buildout-based project
c812c3020b63 Initial import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
15
c812c3020b63 Initial import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
16 Simply run this script in a directory containing a buildout.cfg.
c812c3020b63 Initial import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
17 The script accepts buildout command-line options, so you can
c812c3020b63 Initial import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
18 use the -c option to specify an alternate configuration file.
c812c3020b63 Initial import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
19 """
c812c3020b63 Initial import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
20
11
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
21 import os, shutil, sys, tempfile, textwrap, urllib, urllib2, subprocess
0
c812c3020b63 Initial import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
22 from optparse import OptionParser
c812c3020b63 Initial import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
23
c812c3020b63 Initial import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
24 if sys.platform == 'win32':
c812c3020b63 Initial import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
25 def quote(c):
c812c3020b63 Initial import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
26 if ' ' in c:
c812c3020b63 Initial import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
27 return '"%s"' % c # work around spawn lamosity on windows
c812c3020b63 Initial import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
28 else:
c812c3020b63 Initial import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
29 return c
c812c3020b63 Initial import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
30 else:
11
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
31 quote = str
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
32
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
33 # See zc.buildout.easy_install._has_broken_dash_S for motivation and comments.
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
34 stdout, stderr = subprocess.Popen(
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
35 [sys.executable, '-Sc',
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
36 'try:\n'
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
37 ' import ConfigParser\n'
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
38 'except ImportError:\n'
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
39 ' print 1\n'
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
40 'else:\n'
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
41 ' print 0\n'],
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
42 stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
43 has_broken_dash_S = bool(int(stdout.strip()))
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
44
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
45 # In order to be more robust in the face of system Pythons, we want to
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
46 # run without site-packages loaded. This is somewhat tricky, in
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
47 # particular because Python 2.6's distutils imports site, so starting
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
48 # with the -S flag is not sufficient. However, we'll start with that:
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
49 if not has_broken_dash_S and 'site' in sys.modules:
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
50 # We will restart with python -S.
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
51 args = sys.argv[:]
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
52 args[0:0] = [sys.executable, '-S']
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
53 args = map(quote, args)
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
54 os.execv(sys.executable, args)
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
55 # Now we are running with -S. We'll get the clean sys.path, import site
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
56 # because distutils will do it later, and then reset the path and clean
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
57 # out any namespace packages from site-packages that might have been
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
58 # loaded by .pth files.
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
59 clean_path = sys.path[:]
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
60 import site
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
61 sys.path[:] = clean_path
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
62 for k, v in sys.modules.items():
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
63 if k in ('setuptools', 'pkg_resources') or (
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
64 hasattr(v, '__path__') and
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
65 len(v.__path__)==1 and
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
66 not os.path.exists(os.path.join(v.__path__[0],'__init__.py'))):
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
67 # This is a namespace package. Remove it.
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
68 sys.modules.pop(k)
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
69
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
70 is_jython = sys.platform.startswith('java')
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
71
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
72 setuptools_source = 'http://peak.telecommunity.com/dist/ez_setup.py'
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
73 distribute_source = 'http://python-distribute.org/distribute_setup.py'
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
74
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
75 # parsing arguments
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
76 def normalize_to_url(option, opt_str, value, parser):
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
77 if value:
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
78 if '://' not in value: # It doesn't smell like a URL.
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
79 value = 'file://%s' % (
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
80 urllib.pathname2url(
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
81 os.path.abspath(os.path.expanduser(value))),)
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
82 if opt_str == '--download-base' and not value.endswith('/'):
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
83 # Download base needs a trailing slash to make the world happy.
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
84 value += '/'
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
85 else:
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
86 value = None
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
87 name = opt_str[2:].replace('-', '_')
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
88 setattr(parser.values, name, value)
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
89
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
90 usage = '''\
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
91 [DESIRED PYTHON FOR BUILDOUT] bootstrap.py [options]
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
92
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
93 Bootstraps a buildout-based project.
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
94
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
95 Simply run this script in a directory containing a buildout.cfg, using the
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
96 Python that you want bin/buildout to use.
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
97
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
98 Note that by using --setup-source and --download-base to point to
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
99 local resources, you can keep this script from going over the network.
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
100 '''
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
101
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
102 parser = OptionParser(usage=usage)
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
103 parser.add_option("-v", "--version", dest="version",
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
104 help="use a specific zc.buildout version")
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
105 parser.add_option("-d", "--distribute",
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
106 action="store_true", dest="use_distribute", default=False,
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
107 help="Use Distribute rather than Setuptools.")
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
108 parser.add_option("--setup-source", action="callback", dest="setup_source",
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
109 callback=normalize_to_url, nargs=1, type="string",
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
110 help=("Specify a URL or file location for the setup file. "
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
111 "If you use Setuptools, this will default to " +
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
112 setuptools_source + "; if you use Distribute, this "
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
113 "will default to " + distribute_source +"."))
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
114 parser.add_option("--download-base", action="callback", dest="download_base",
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
115 callback=normalize_to_url, nargs=1, type="string",
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
116 help=("Specify a URL or directory for downloading "
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
117 "zc.buildout and either Setuptools or Distribute. "
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
118 "Defaults to PyPI."))
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
119 parser.add_option("--eggs",
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
120 help=("Specify a directory for storing eggs. Defaults to "
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
121 "a temporary directory that is deleted when the "
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
122 "bootstrap script completes."))
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
123 parser.add_option("-t", "--accept-buildout-test-releases",
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
124 dest='accept_buildout_test_releases',
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
125 action="store_true", default=False,
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
126 help=("Normally, if you do not specify a --version, the "
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
127 "bootstrap script and buildout gets the newest "
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
128 "*final* versions of zc.buildout and its recipes and "
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
129 "extensions for you. If you use this flag, "
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
130 "bootstrap and buildout will get the newest releases "
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
131 "even if they are alphas or betas."))
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
132 parser.add_option("-c", None, action="store", dest="config_file",
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
133 help=("Specify the path to the buildout configuration "
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
134 "file to be used."))
0
c812c3020b63 Initial import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
135
11
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
136 options, args = parser.parse_args()
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
137
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
138 # if -c was provided, we push it back into args for buildout's main function
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
139 if options.config_file is not None:
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
140 args += ['-c', options.config_file]
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
141
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
142 if options.eggs:
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
143 eggs_dir = os.path.abspath(os.path.expanduser(options.eggs))
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
144 else:
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
145 eggs_dir = tempfile.mkdtemp()
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
146
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
147 if options.setup_source is None:
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
148 if options.use_distribute:
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
149 options.setup_source = distribute_source
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
150 else:
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
151 options.setup_source = setuptools_source
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
152
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
153 if options.accept_buildout_test_releases:
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
154 args.append('buildout:accept-buildout-test-releases=true')
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
155 args.append('bootstrap')
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
156
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
157 try:
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
158 import pkg_resources
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
159 import setuptools # A flag. Sometimes pkg_resources is installed alone.
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
160 if not hasattr(pkg_resources, '_distribute'):
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
161 raise ImportError
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
162 except ImportError:
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
163 ez_code = urllib2.urlopen(
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
164 options.setup_source).read().replace('\r\n', '\n')
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
165 ez = {}
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
166 exec ez_code in ez
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
167 setup_args = dict(to_dir=eggs_dir, download_delay=0)
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
168 if options.download_base:
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
169 setup_args['download_base'] = options.download_base
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
170 if options.use_distribute:
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
171 setup_args['no_fake'] = True
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
172 ez['use_setuptools'](**setup_args)
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
173 if 'pkg_resources' in sys.modules:
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
174 reload(sys.modules['pkg_resources'])
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
175 import pkg_resources
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
176 # This does not (always?) update the default working set. We will
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
177 # do it.
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
178 for path in sys.path:
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
179 if path not in pkg_resources.working_set.entries:
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
180 pkg_resources.working_set.add_entry(path)
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
181
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
182 cmd = [quote(sys.executable),
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
183 '-c',
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
184 quote('from setuptools.command.easy_install import main; main()'),
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
185 '-mqNxd',
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
186 quote(eggs_dir)]
0
c812c3020b63 Initial import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
187
11
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
188 if not has_broken_dash_S:
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
189 cmd.insert(1, '-S')
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
190
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
191 find_links = options.download_base
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
192 if not find_links:
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
193 find_links = os.environ.get('bootstrap-testing-find-links')
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
194 if find_links:
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
195 cmd.extend(['-f', quote(find_links)])
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
196
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
197 if options.use_distribute:
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
198 setup_requirement = 'distribute'
0
c812c3020b63 Initial import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
199 else:
11
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
200 setup_requirement = 'setuptools'
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
201 ws = pkg_resources.working_set
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
202 setup_requirement_path = ws.find(
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
203 pkg_resources.Requirement.parse(setup_requirement)).location
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
204 env = dict(
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
205 os.environ,
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
206 PYTHONPATH=setup_requirement_path)
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
207
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
208 requirement = 'zc.buildout'
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
209 version = options.version
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
210 if version is None and not options.accept_buildout_test_releases:
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
211 # Figure out the most recent final version of zc.buildout.
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
212 import setuptools.package_index
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
213 _final_parts = '*final-', '*final'
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
214 def _final_version(parsed_version):
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
215 for part in parsed_version:
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
216 if (part[:1] == '*') and (part not in _final_parts):
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
217 return False
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
218 return True
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
219 index = setuptools.package_index.PackageIndex(
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
220 search_path=[setup_requirement_path])
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
221 if find_links:
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
222 index.add_find_links((find_links,))
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
223 req = pkg_resources.Requirement.parse(requirement)
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
224 if index.obtain(req) is not None:
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
225 best = []
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
226 bestv = None
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
227 for dist in index[req.project_name]:
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
228 distv = dist.parsed_version
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
229 if _final_version(distv):
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
230 if bestv is None or distv > bestv:
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
231 best = [dist]
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
232 bestv = distv
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
233 elif distv == bestv:
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
234 best.append(dist)
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
235 if best:
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
236 best.sort()
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
237 version = best[-1].version
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
238 if version:
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
239 requirement = '=='.join((requirement, version))
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
240 cmd.append(requirement)
0
c812c3020b63 Initial import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
241
c812c3020b63 Initial import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
242 if is_jython:
c812c3020b63 Initial import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
243 import subprocess
11
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
244 exitcode = subprocess.Popen(cmd, env=env).wait()
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
245 else: # Windows prefers this, apparently; otherwise we would prefer subprocess
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
246 exitcode = os.spawnle(*([os.P_WAIT, sys.executable] + cmd + [env]))
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
247 if exitcode != 0:
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
248 sys.stdout.flush()
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
249 sys.stderr.flush()
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
250 print ("An error occurred when trying to install zc.buildout. "
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
251 "Look above this message for any errors that "
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
252 "were output by easy_install.")
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
253 sys.exit(exitcode)
0
c812c3020b63 Initial import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
254
11
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
255 ws.add_entry(eggs_dir)
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
256 ws.require(requirement)
0
c812c3020b63 Initial import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
257 import zc.buildout.buildout
c812c3020b63 Initial import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
258 zc.buildout.buildout.main(args)
11
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
259 if not options.eggs: # clean up temporary egg directory
66101b35a8c0 Upgrade buildout bootstrap.py to latest version.
Daniele Nicolodi <daniele@grinta.net>
parents: 0
diff changeset
260 shutil.rmtree(eggs_dir)