aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xbootstrap.py123
-rw-r--r--requirements.txt18
2 files changed, 141 insertions, 0 deletions
diff --git a/bootstrap.py b/bootstrap.py
new file mode 100755
index 0000000..80d9048
--- /dev/null
+++ b/bootstrap.py
@@ -0,0 +1,123 @@
1#!/usr/bin/env python2
2from __future__ import absolute_import, print_function, unicode_literals
3
4import os
5import subprocess
6import sys
7
8
9def warning(*objs):
10 print("WARNING: ", *objs, file=sys.stderr)
11
12
13def fail(message):
14 sys.exit("Error: {message}".format(message=message))
15
16
17def has_module(module_name):
18 try:
19 import imp
20 imp.find_module(module_name)
21 del imp
22 return True
23 except ImportError:
24 return False
25
26
27def which(exe=None, throw=True):
28 """Return path of bin. Python clone of /usr/bin/which.
29
30 from salt.util - https://www.github.com/saltstack/salt - license apache
31
32 :param exe: Application to search PATHs for.
33 :type exe: string
34 :param throw: Raise ``Exception`` if not found in paths
35 :type throw: bool
36 :rtype: string
37
38 """
39 if exe:
40 if os.access(exe, os.X_OK):
41 return exe
42
43 # default path based on busybox's default
44 default_path = '/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin'
45 search_path = os.environ.get('PATH', default_path)
46
47 for path in search_path.split(os.pathsep):
48 full_path = os.path.join(path, exe)
49 if os.access(full_path, os.X_OK):
50 return full_path
51
52 message = (
53 '{0!r} could not be found in the following search '
54 'path: {1!r}'.format(
55 exe, search_path
56 )
57 )
58
59 if throw:
60 raise Exception(message)
61 else:
62 print(message)
63 return None
64
65
66project_dir = os.path.dirname(os.path.realpath(__file__))
67env_dir = os.path.join(project_dir, '.venv')
68pip_bin = os.path.join(env_dir, 'bin', 'pip')
69python_bin = os.path.join(env_dir, 'bin', 'python')
70virtualenv_bin = which('virtualenv', throw=False)
71virtualenv_exists = os.path.exists(env_dir) and os.path.isfile(python_bin)
72sphinx_requirements_filepath = os.path.join(
73 project_dir, 'requirements.txt')
74
75
76try:
77 import virtualenv # NOQA
78except ImportError:
79 message = (
80 'Virtualenv is required for this bootstrap to run.\n'
81 'Install virtualenv via:\n'
82 '\t$ [sudo] pip install virtualenv'
83 )
84 fail(message)
85
86
87try:
88 import pip # NOQA
89except ImportError:
90 message = (
91 'pip is required for this bootstrap to run.\n'
92 'Find instructions on how to install at: %s' %
93 'http://pip.readthedocs.io/en/latest/installing.html'
94 )
95 fail(message)
96
97
98def main():
99 if not which('entr', throw=False):
100 message = (
101 '\nentr(1) is used in this app as a cross platform file watcher.'
102 'You can install it via your package manager on most POSIX '
103 'systems. See the site at http://entrproject.org/\n'
104 )
105 print(message)
106
107 if not virtualenv_exists:
108 virtualenv_bin = which('virtualenv', throw=False)
109
110 subprocess.check_call(
111 [virtualenv_bin, env_dir]
112 )
113
114 if not os.path.isfile(os.path.join(env_dir, 'bin', 'sphinx-quickstart')):
115 subprocess.check_call(
116 [pip_bin, 'install', '-r', sphinx_requirements_filepath]
117 )
118
119 if os.path.exists(os.path.join(env_dir, 'build')):
120 os.removedirs(os.path.join(env_dir, 'build'))
121
122if __name__ == '__main__':
123 main()
diff --git a/requirements.txt b/requirements.txt
new file mode 100644
index 0000000..47b54bf
--- /dev/null
+++ b/requirements.txt
@@ -0,0 +1,18 @@
1alabaster==0.7.10
2alagitpull==0.0.14
3Babel==2.5.1
4certifi==2017.11.5
5chardet==3.0.4
6docutils==0.14
7idna==2.6
8imagesize==0.7.1
9Jinja2==2.10
10MarkupSafe==1.0
11Pygments==2.2.0
12pytz==2017.3
13requests==2.18.4
14six==1.11.0
15snowballstemmer==1.2.1
16Sphinx==1.6.6
17sphinxcontrib-websupport==1.0.1
18urllib3==1.22
Powered by cgit v1.2.3 (git 2.41.0)