-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap.py
92 lines (75 loc) · 2.72 KB
/
bootstrap.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
##############################################################################
#
# Copyright (c) 2006 Zope Foundation and Contributors.
# 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.
#
##############################################################################
"""Bootstrap a buildout-based project
Simply run this script in a directory containing a buildout.cfg.
"""
import os
import shutil
import subprocess
import sys
import tempfile
BASEURL = 'https://dist.minddistrict.io'
TMPEGGS = tempfile.mkdtemp()
ZCBUILDOUT = '2.11.3'
######################################################################
# load/install setuptools
to_reload = False
try:
import pkg_resources
import setuptools # NOQA
except ImportError:
ez = {}
try:
from urllib.request import urlopen
except ImportError:
from urllib2 import urlopen
exec(urlopen(BASEURL + '/downloads/ez_setup5.py').read(), ez)
# Do not update setuptools version that is the latest working version evar.
setup_args = dict(
to_dir=TMPEGGS,
version='33.1.1',
download_delay=0,
download_base=BASEURL + '/root/pypi/+f/796/3d41d97b94e45/')
ez['use_setuptools'](**setup_args)
if to_reload:
reload(pkg_resources)
import pkg_resources
# This does not (always?) update the default working set. We will
# do it.
for path in sys.path:
if path not in pkg_resources.working_set.entries:
pkg_resources.working_set.add_entry(path)
######################################################################
# Install buildout
ws = pkg_resources.working_set
requirement = '=='.join(('zc.buildout', ZCBUILDOUT))
cmd = [sys.executable, '-c',
'from setuptools.command.easy_install import main; main()',
'-mZqNxd', TMPEGGS,
'-i', BASEURL + '/root/minddistrict/+simple/',
'-H', 'dist.minddistrict.io',
requirement]
setuptools_path = ws.find(
pkg_resources.Requirement.parse('setuptools')).location
if subprocess.call(cmd, env=dict(os.environ, PYTHONPATH=setuptools_path)) != 0:
raise Exception(
"Failed to execute command:\n%s",
repr(cmd)[1:-1])
######################################################################
# Import and run buildout
ws.add_entry(TMPEGGS)
ws.require(requirement)
import zc.buildout.buildout
zc.buildout.buildout.main(['bootstrap'])
shutil.rmtree(TMPEGGS)