Skip to content

Commit 0fc0497

Browse files
committed
Fix install-local.py Resolves #52
1 parent 00df256 commit 0fc0497

File tree

7 files changed

+123
-93
lines changed

7 files changed

+123
-93
lines changed

.gitignore

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55
.idea
66
.project
77
.pydevproject
8-
all-hooks.json
9-
bower_components
10-
build
11-
install-local.py
12-
node_env
13-
py_env
8+
/all-hooks.json
9+
/bower_components
10+
/build
11+
/nenv
12+
/venv

.pre-commit-config.yaml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
- repo: git@github.com:pre-commit/mirrors-scss-lint
2-
sha: 3eb13b9647543ad4d6a62c8be8a9131e3b99b96a
2+
sha: f840ac610d8d9d76b666062416241f2156b3f388
33
hooks:
44
- id: scss-lint
55
language_version: 1.9.3-p547
66
- repo: git@github.com:pre-commit/pre-commit-hooks
7-
sha: 516cc9fa72ad09699f2c03ffbd0aa7f60d75b59a
7+
sha: 97b88d9610bcc03982ddac33caba98bb2b751f5f
88
hooks:
99
- id: trailing-whitespace
1010
- id: end-of-file-fixer
1111
- id: autopep8-wrapper
1212
- id: check-yaml
1313
- id: debug-statements
1414
- id: flake8
15+
- repo: https://github.com/asottile/reorder_python_imports.git
16+
sha: 50e0be95e292cac913cc3c6fd44b3d6b51d104c5
17+
hooks:
18+
- id: reorder-python-imports
19+
language_version: python2.7

Makefile

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,34 @@
11
# To build scss continuously I use `watch -n 0.1 make build/main.css`
22

3-
all: install_pre_commit build/main.css all-hooks.json index.html hooks.html install-local.py
3+
all: install-hooks build/main.css all-hooks.json index.html hooks.html
44

5-
.PHONY: install_pre_commit
6-
install_pre_commit: py_env
7-
. py_env/bin/activate && pre-commit install
5+
.PHONY: install-hooks
6+
install-hooks: venv
7+
venv/bin/pre-commit install
88

9-
build/main.css: node_env build scss/main.scss scss/_variables.scss
10-
. py_env/bin/activate && sassc -s compressed scss/main.scss build/main.css
9+
build/main.css: nenv build scss/main.scss scss/_variables.scss
10+
venv/bin/sassc -s compressed scss/main.scss build/main.css
1111

12-
all-hooks.json: py_env make_all_hooks.py all-repos.yaml
13-
. py_env/bin/activate && python make_all_hooks.py
12+
all-hooks.json: venv make_all_hooks.py all-repos.yaml
13+
venv/bin/python make_all_hooks.py
1414

15-
index.html hooks.html: py_env all-hooks.json base.mako index.mako hooks.mako make_templates.py
16-
. py_env/bin/activate && python make_templates.py
15+
index.html hooks.html: venv all-hooks.json base.mako index.mako hooks.mako make_templates.py
16+
venv/bin/python make_templates.py
1717

18-
install-local.py: py_env make_bootstrap.py
19-
. py_env/bin/activate && python make_bootstrap.py
18+
venv: requirements-dev.txt
19+
rm -rf venv
20+
virtualenv venv
21+
venv/bin/pip install -r requirements-dev.txt
2022

21-
py_env: requirements-dev.txt
22-
rm -rf py_env
23-
virtualenv py_env
24-
. py_env/bin/activate && pip install -r requirements-dev.txt
25-
26-
node_env: py_env
27-
rm -rf node_env
28-
. py_env/bin/activate && \
29-
nodeenv node_env --prebuilt && \
30-
. node_env/bin/activate && \
23+
nenv: venv
24+
rm -rf nenv
25+
venv/bin/nodeenv nenv --prebuilt && \
26+
. nenv/bin/activate && \
3127
npm install -g bower && \
3228
bower install
3329

3430
clean:
35-
rm -rf py_env node_env build bower_components *.html install-local.py all-hooks.json
31+
rm -rf venv nenv build bower_components *.html all-hooks.json
3632

3733
build:
3834
mkdir -p build

install-local.py

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#!/usr/bin/env python
2+
from __future__ import absolute_import
3+
from __future__ import unicode_literals
4+
5+
import contextlib
6+
import distutils.spawn
7+
import io
8+
import os.path
9+
import shutil
10+
import subprocess
11+
import sys
12+
import tarfile
13+
14+
15+
if str is bytes:
16+
from urllib import urlopen
17+
else:
18+
from urllib.request import urlopen
19+
20+
21+
TGZ = (
22+
'https://pypi.python.org/packages/source/v/virtualenv/'
23+
'virtualenv-1.11.6.tar.gz'
24+
)
25+
PKG_PATH = '/tmp/.virtualenv-pkg'
26+
27+
28+
def clean():
29+
if os.path.exists(PKG_PATH):
30+
shutil.rmtree(PKG_PATH)
31+
32+
33+
@contextlib.contextmanager
34+
def clean_path():
35+
try:
36+
yield
37+
finally:
38+
clean()
39+
40+
41+
def virtualenv(path):
42+
clean()
43+
44+
print('Downloading ' + TGZ)
45+
tar_contents = io.BytesIO(urlopen(TGZ).read())
46+
with contextlib.closing(tarfile.open(fileobj=tar_contents)) as tarfile_obj:
47+
# Chop off the first path segment to avoid having the version in
48+
# the path
49+
for member in tarfile_obj.getmembers():
50+
_, _, member.name = member.name.partition('/')
51+
if member.name:
52+
tarfile_obj.extract(member, PKG_PATH)
53+
print('Done.')
54+
55+
with clean_path():
56+
return subprocess.call((
57+
sys.executable, os.path.join(PKG_PATH, 'virtualenv.py'), path,
58+
))
59+
60+
61+
def main():
62+
venv_path = os.path.join(os.environ['HOME'], '.pre-commit-venv')
63+
virtualenv(venv_path)
64+
65+
subprocess.check_call((
66+
os.path.join(venv_path, 'bin', 'pip'), 'install', 'pre-commit',
67+
))
68+
69+
bin_dir = os.path.join(os.environ['HOME'], 'bin')
70+
script_src = os.path.join(venv_path, 'bin', 'pre-commit')
71+
script_dest = os.path.join(bin_dir, 'pre-commit')
72+
print('*' * 79)
73+
print('Installing pre-commit to {0}'.format(script_dest))
74+
print('*' * 79)
75+
76+
if not os.path.exists(bin_dir):
77+
os.mkdir(bin_dir)
78+
79+
# os.symlink is not idempotent
80+
if os.path.exists(script_dest):
81+
os.remove(script_dest)
82+
83+
os.symlink(script_src, script_dest)
84+
85+
if not distutils.spawn.find_executable('pre-commit'):
86+
print('It looks like {0} is not on your path'.format(bin_dir))
87+
print('You may want to add it.')
88+
print('Often this does the trick: source ~/.profile')
89+
90+
91+
if __name__ == '__main__':
92+
exit(main())

make_bootstrap.py

Lines changed: 0 additions & 57 deletions
This file was deleted.

requirements-dev.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
aspy.yaml
2-
flake8
32
mako
43
libsass
54
nodeenv
65
pre-commit
7-
virtualenv

setup.cfg

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)