This repository has been archived by the owner on Jul 5, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
bootstrap.py
121 lines (98 loc) · 4.07 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# -*- coding: utf-8 -*- {{{
# vim: set fenc=utf-8 ft=python ff=unix sw=4 ts=4 sts=4 et:
# APBS -- Adaptive Poisson-Boltzmann Solver
#
# Nathan A. Baker ([email protected])
# Pacific Northwest National Laboratory
#
# Additional contributing authors listed in the code documentation.
#
# Copyright (c) 2010-2016 Battelle Memorial Institute. Developed at the
# Pacific Northwest National Laboratory, operated by Battelle Memorial
# Institute, Pacific Northwest Division for the U.S. Department of Energy.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# Neither the name of the developer nor the names of its contributors may be
# used to endorse or promote products derived from this software without
# specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
# THE POSSIBILITY OF SUCH DAMAGE.
#}}}
import errno
import os
import subprocess
import sys
__author__ = 'Keith T. Star <[email protected]>'
_ENV = 'sphinx-env'
_PACKAGES = 'packages.txt'
def bootstrap(dest = _ENV):
import venv
class EnvBuilder(venv.EnvBuilder):
def __init__(self, *args, **kwargs):
# Not much going on here...yet.
super().__init__(*args, **kwargs)
def post_setup(self, context):
''' Deal with dependencies
Once we have our Python environment we have pip install the packages listed
in packages.txt, and then we do any bootstrapping.
'''
path = os.path.dirname(__file__) or '.'
packages = os.path.join(path, _PACKAGES)
if os.path.exists(packages):
pip = os.path.join(context.bin_path, 'pip')
cmd = [pip, 'install', '-r', packages]
subprocess.check_call(cmd)
python = os.path.join(context.bin_path, 'python')
if os.name == 'nt':
python += '.exe'
cmd = [python, '-m', 'sphinx.bootstrap']
subprocess.check_call(cmd)
sys.stdout.write("Creating Python virtual environment...\n")
if os.name == 'nt':
use_symlinks = False
else:
use_symlinks = True
builder = EnvBuilder(symlinks = use_symlinks, with_pip = True)
builder.create(dest)
def main(argv = sys.argv):
''' Install Python venv and bootstrap Sphinx
This script calls itself to bootstrap Sphinx once the virtual environment
is setup.
'''
# Refuse to run as root
if not getattr(os, 'getuid', lambda: -1)():
sys.stderr.write("{}: error; please don't run as root!\n".format(
os.path.basename(argv[0])))
sys.exit(7)
# We need Python 3.5 for asyncio support
if sys.version_info < (3, 5):
sys.stderr.write("{}: error; Python > 3.5 is required.\n".format(
os.path.basename(argv[0])))
sys.exit(6)
bootstrap()
if __name__ == '__main__':
try:
main()
except KeyboardInterrupt:
pass
except subprocess.CalledProcessError as exc:
sys.exit(exc.returncode)