dev.py 2.59 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
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')

29 30 31 32 33 34 35 36 37
######################################################################
# Make sure we have a relatively clean environment
try:
    import pkg_resources, setuptools
except ImportError:
    pass
else:
    raise SystemError(
        "Buildout development with a pre-installed setuptools or "
38
        "distribute is not supported.")
Jim Fulton's avatar
Jim Fulton committed
39 40 41 42

######################################################################
# Install distribute
ez = {}
43 44 45 46 47 48

try:
    from urllib.request import urlopen
except ImportError:
    from urllib2 import urlopen

49
# XXX use a more permanent ez_setup.py URL when available.
50
exec(urlopen('https://bootstrap.pypa.io/ez_setup.py').read(), ez)
Jim Fulton's avatar
Jim Fulton committed
51 52
ez['use_setuptools'](to_dir='eggs', download_delay=0)

53 54
import pkg_resources, setuptools
setuptools_path = os.path.dirname(os.path.dirname(setuptools.__file__))
Jim Fulton's avatar
Jim Fulton committed
55 56 57 58

######################################################################
# Install buildout
if subprocess.call(
59 60
    [sys.executable] +
    ['setup.py', '-q', 'develop', '-m', '-x', '-d', 'develop-eggs'],
61
    env=dict(os.environ, PYTHONPATH=setuptools_path)):
Jim Fulton's avatar
Jim Fulton committed
62
    raise RuntimeError("buildout build failed.")
63

64
pkg_resources.working_set.add_entry('src')
65

66 67 68
import zc.buildout.easy_install
zc.buildout.easy_install.scripts(
    ['zc.buildout'], pkg_resources.working_set , sys.executable, 'bin')
69 70

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

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

Jim Fulton's avatar
Jim Fulton committed
76 77
if sys.version_info < (2, 6):
    bin_buildout = [bin_buildout, '-c2.4.cfg']
78
sys.exit(subprocess.Popen(bin_buildout).wait())