forked from pre-commit/pre-commit.com
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix install-local.py Resolves pre-commit#52
- Loading branch information
Showing
7 changed files
with
123 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,19 @@ | ||
- repo: git@github.com:pre-commit/mirrors-scss-lint | ||
sha: 3eb13b9647543ad4d6a62c8be8a9131e3b99b96a | ||
sha: f840ac610d8d9d76b666062416241f2156b3f388 | ||
hooks: | ||
- id: scss-lint | ||
language_version: 1.9.3-p547 | ||
- repo: git@github.com:pre-commit/pre-commit-hooks | ||
sha: 516cc9fa72ad09699f2c03ffbd0aa7f60d75b59a | ||
sha: 97b88d9610bcc03982ddac33caba98bb2b751f5f | ||
hooks: | ||
- id: trailing-whitespace | ||
- id: end-of-file-fixer | ||
- id: autopep8-wrapper | ||
- id: check-yaml | ||
- id: debug-statements | ||
- id: flake8 | ||
- repo: https://github.com/asottile/reorder_python_imports.git | ||
sha: 50e0be95e292cac913cc3c6fd44b3d6b51d104c5 | ||
hooks: | ||
- id: reorder-python-imports | ||
language_version: python2.7 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
#!/usr/bin/env python | ||
from __future__ import absolute_import | ||
from __future__ import unicode_literals | ||
|
||
import contextlib | ||
import distutils.spawn | ||
import io | ||
import os.path | ||
import shutil | ||
import subprocess | ||
import sys | ||
import tarfile | ||
|
||
|
||
if str is bytes: | ||
from urllib import urlopen | ||
else: | ||
from urllib.request import urlopen | ||
|
||
|
||
TGZ = ( | ||
'https://pypi.python.org/packages/source/v/virtualenv/' | ||
'virtualenv-1.11.6.tar.gz' | ||
) | ||
PKG_PATH = '/tmp/.virtualenv-pkg' | ||
|
||
|
||
def clean(): | ||
if os.path.exists(PKG_PATH): | ||
shutil.rmtree(PKG_PATH) | ||
|
||
|
||
@contextlib.contextmanager | ||
def clean_path(): | ||
try: | ||
yield | ||
finally: | ||
clean() | ||
|
||
|
||
def virtualenv(path): | ||
clean() | ||
|
||
print('Downloading ' + TGZ) | ||
tar_contents = io.BytesIO(urlopen(TGZ).read()) | ||
with contextlib.closing(tarfile.open(fileobj=tar_contents)) as tarfile_obj: | ||
# Chop off the first path segment to avoid having the version in | ||
# the path | ||
for member in tarfile_obj.getmembers(): | ||
_, _, member.name = member.name.partition('/') | ||
if member.name: | ||
tarfile_obj.extract(member, PKG_PATH) | ||
print('Done.') | ||
|
||
with clean_path(): | ||
return subprocess.call(( | ||
sys.executable, os.path.join(PKG_PATH, 'virtualenv.py'), path, | ||
)) | ||
|
||
|
||
def main(): | ||
venv_path = os.path.join(os.environ['HOME'], '.pre-commit-venv') | ||
virtualenv(venv_path) | ||
|
||
subprocess.check_call(( | ||
os.path.join(venv_path, 'bin', 'pip'), 'install', 'pre-commit', | ||
)) | ||
|
||
bin_dir = os.path.join(os.environ['HOME'], 'bin') | ||
script_src = os.path.join(venv_path, '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') | ||
|
||
|
||
if __name__ == '__main__': | ||
exit(main()) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
aspy.yaml | ||
flake8 | ||
mako | ||
libsass | ||
nodeenv | ||
pre-commit | ||
virtualenv |