dev.py 3.08 KB
Newer Older
1 2
##############################################################################
#
3
# Copyright (c) 2005 Zope Foundation and Contributors.
4 5 6 7 8 9 10 11 12 13
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
14 15 16 17
"""Bootstrap the buildout project itself.

This is different from a normal boostrapping process because the
buildout egg itself is installed as a develop egg.
18 19
"""

20
import os, shutil, sys, subprocess, urllib.request, urllib.error, urllib.parse
21

Jim Fulton's avatar
Jim Fulton committed
22
for d in 'eggs', 'develop-eggs', 'bin', 'parts':
23 24 25
    if not os.path.exists(d):
        os.mkdir(d)

26 27 28
if os.path.isdir('build'):
    shutil.rmtree('build')

Jim Fulton's avatar
Jim Fulton committed
29 30 31 32
######################################################################
# handle -S

def normpath(p):
33
    return p[:-1] if p.endswith(os.path.sep) else p
Jim Fulton's avatar
Jim Fulton committed
34 35 36 37 38 39 40 41 42 43 44 45 46

nosite = 'site' not in sys.modules
if nosite:
    # They've asked not to import site.  Cool, but distribute is going to
    # import it anyway, so we're going to have to clean up. :(
    initial_paths = set(map(normpath, sys.path))
    import site
    to_remove = set(map(normpath, sys.path)) - initial_paths
else:
    to_remove = ()

######################################################################
# Make sure we have a relatively clean environment
47
try:
Jim Fulton's avatar
Jim Fulton committed
48
    import pkg_resources, setuptools
49
except ImportError:
Jim Fulton's avatar
Jim Fulton committed
50 51 52 53 54 55 56 57 58 59
    pass
else:
    raise SystemError(
        "Buildout development with a pre-installed setuptools or "
        "distribute is not supported.%s"
        % ('' if nosite else ' Try running with -S option to Python.'))

######################################################################
# Install distribute
ez = {}
60 61
exec(urllib.request.urlopen(
    'http://python-distribute.org/distribute_setup.py').read(), ez)
Jim Fulton's avatar
Jim Fulton committed
62 63 64 65 66 67 68 69 70 71
ez['use_setuptools'](to_dir='eggs', download_delay=0)

import pkg_resources

# Clean up
if nosite and 'site' in sys.modules:
    del sys.modules['site']
    sys.path[:] = [p for p in sys.path[:]
        if normpath(p) not in to_remove
        ]
72

Jim Fulton's avatar
Jim Fulton committed
73 74
######################################################################
# Install buildout
75

Jim Fulton's avatar
Jim Fulton committed
76
if subprocess.call(
77 78
    [sys.executable] +
    ['setup.py', '-q', 'develop', '-m', '-x', '-d', 'develop-eggs'],
Jim Fulton's avatar
Jim Fulton committed
79 80
    env = {'PYTHONPATH': os.path.dirname(pkg_resources.__file__)}):
    raise RuntimeError("buildout build failed.")
81

82
pkg_resources.working_set.add_entry('src')
83

84 85 86
import zc.buildout.easy_install
zc.buildout.easy_install.scripts(
    ['zc.buildout'], pkg_resources.working_set , sys.executable, 'bin')
Jim Fulton's avatar
Jim Fulton committed
87 88

bin_buildout = os.path.join('bin', 'buildout')
89

Jim Fulton's avatar
Jim Fulton committed
90
if sys.platform.startswith('java'):
91 92
    # Jython needs the script to be called twice via sys.executable
    assert subprocess.Popen([sys.executable] + [bin_buildout]).wait() == 0
93

94
sys.exit(subprocess.Popen(bin_buildout).wait())