forked from pre-commit/pre-commit.com
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmake_bootstrap.py
More file actions
57 lines (44 loc) · 1.66 KB
/
make_bootstrap.py
File metadata and controls
57 lines (44 loc) · 1.66 KB
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
# -*- coding: utf-8 -*-
from __future__ import print_function
from __future__ import unicode_literals
import io
import textwrap
import virtualenv
def main():
contents = virtualenv.create_bootstrap_script(textwrap.dedent(
'''
import distutils.spawn
import os
import os.path
import subprocess
def adjust_options(options, args):
args[:] = [
os.path.join(os.environ['HOME'], '.pre-commit-venv')
]
def after_install(options, home_dir):
subprocess.check_call([
os.path.join(home_dir, 'bin', 'pip'),
'install', 'pre-commit',
])
bin_dir = os.path.join(os.environ['HOME'], 'bin')
script_src = os.path.join(home_dir, 'bin', 'pre-commit')
script_dest = os.path.join(bin_dir, 'pre-commit')
print('*' * 79)
print('Installing pre-commit to {0}'.format(script_dest))
print('*' * 79)
if not os.path.exists(bin_dir):
os.mkdir(bin_dir)
# os.symlink is not idempotent
if os.path.exists(script_dest):
os.remove(script_dest)
os.symlink(script_src, script_dest)
if not distutils.spawn.find_executable('pre-commit'):
print('It looks like {0} is not on your path'.format(bin_dir))
print('You may want to add it.')
print('Often this does the trick: source ~/.profile')
'''
))
with io.open('install-local.py', 'w', encoding='UTF-8') as install_file:
install_file.write(contents)
if __name__ == '__main__':
exit(main())