moved the installing code to its own package

This commit is contained in:
Ken Struys 2014-03-13 17:31:58 -07:00
parent 320bb0a679
commit 1d8af9ce50
7 changed files with 167 additions and 152 deletions

View file

@ -1,6 +1,5 @@
import os
import pkg_resources
import contextlib
import pre_commit.constants as C
from plumbum import local
@ -9,7 +8,6 @@ from plumbum import local
def get_root():
return local['git']['rev-parse', '--show-toplevel']().strip()
def get_pre_commit_path():
return os.path.join(get_root(), '.git/hooks/pre-commit')
@ -30,40 +28,4 @@ def remove_pre_commit():
local.path(get_pre_commit_path()).delete()
class PreCommitProject(object):
def __init__(self, git_repo_path, sha):
self.git_repo_path = git_repo_path
self.sha = sha
@contextlib.contextmanager
def in_checkout(self):
with local.cwd(get_pre_commit_dir_path()):
with local.cwd(self.sha):
yield
def create(self):
create_pre_commit_package_dir()
with local.cwd(get_pre_commit_dir_path()):
local['git']['clone', self.git_repo_path, self.sha]()
with self.in_checkout():
local['git']['checkout', self.sha]()
def install(self):
with self.in_checkout():
if local.path('setup.py').exists():
local['virtualenv']['py_env']()
local['bash']['-c', 'source py_env/bin/activate && pip install .']()
print local.cwd.getpath()
def create_repo_in_env(git_repo_path, sha):
project = PreCommitProject(git_repo_path, sha)
project.create()
def install_pre_commit(git_repo_path, sha):
project = PreCommitProject(git_repo_path, sha)
project.create()
project.install()

View file

View file

@ -0,0 +1,44 @@
import contextlib
from plumbum import local
from pre_commit import git
class RepoInstaller(object):
def __init__(self, git_repo_path, sha):
self.git_repo_path = git_repo_path
self.sha = sha
@contextlib.contextmanager
def in_checkout(self):
with local.cwd(git.get_pre_commit_dir_path()):
with local.cwd(self.sha):
yield
def create(self):
git.create_pre_commit_package_dir()
with local.cwd(git.get_pre_commit_dir_path()):
if local.path(self.sha).exists():
# Project already exists, no reason to re-create it
return
local['git']['clone', self.git_repo_path, self.sha]()
with self.in_checkout():
local['git']['checkout', self.sha]()
def install(self):
with self.in_checkout():
if local.path('setup.py').exists():
local['virtualenv']['py_env']()
local['bash']['-c', 'source py_env/bin/activate && pip install .']()
def create_repo_in_env(git_repo_path, sha):
project = RepoInstaller(git_repo_path, sha)
project.create()
def install_pre_commit(git_repo_path, sha):
project = RepoInstaller(git_repo_path, sha)
project.create()
project.install()