diff options
-rwxr-xr-x | bootstrap.py | 123 | ||||
-rw-r--r-- | requirements.txt | 18 |
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 | ||
2 | from __future__ import absolute_import, print_function, unicode_literals | ||
3 | |||
4 | import os | ||
5 | import subprocess | ||
6 | import sys | ||
7 | |||
8 | |||
9 | def warning(*objs): | ||
10 | print("WARNING: ", *objs, file=sys.stderr) | ||
11 | |||
12 | |||
13 | def fail(message): | ||
14 | sys.exit("Error: {message}".format(message=message)) | ||
15 | |||
16 | |||
17 | def 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 | |||
27 | def 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 | |||
66 | project_dir = os.path.dirname(os.path.realpath(__file__)) | ||
67 | env_dir = os.path.join(project_dir, '.venv') | ||
68 | pip_bin = os.path.join(env_dir, 'bin', 'pip') | ||
69 | python_bin = os.path.join(env_dir, 'bin', 'python') | ||
70 | virtualenv_bin = which('virtualenv', throw=False) | ||
71 | virtualenv_exists = os.path.exists(env_dir) and os.path.isfile(python_bin) | ||
72 | sphinx_requirements_filepath = os.path.join( | ||
73 | project_dir, 'requirements.txt') | ||
74 | |||
75 | |||
76 | try: | ||
77 | import virtualenv # NOQA | ||
78 | except 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 | |||
87 | try: | ||
88 | import pip # NOQA | ||
89 | except 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 | |||
98 | def 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 | |||
122 | if __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 @@ | |||
1 | alabaster==0.7.10 | ||
2 | alagitpull==0.0.14 | ||
3 | Babel==2.5.1 | ||
4 | certifi==2017.11.5 | ||
5 | chardet==3.0.4 | ||
6 | docutils==0.14 | ||
7 | idna==2.6 | ||
8 | imagesize==0.7.1 | ||
9 | Jinja2==2.10 | ||
10 | MarkupSafe==1.0 | ||
11 | Pygments==2.2.0 | ||
12 | pytz==2017.3 | ||
13 | requests==2.18.4 | ||
14 | six==1.11.0 | ||
15 | snowballstemmer==1.2.1 | ||
16 | Sphinx==1.6.6 | ||
17 | sphinxcontrib-websupport==1.0.1 | ||
18 | urllib3==1.22 | ||