mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-01-06 00:50:56 -06:00
45 lines
1.3 KiB
Python
45 lines
1.3 KiB
Python
|
|
import contextlib
|
|
from plumbum import local
|
|
|
|
from pre_commit.hooks_workspace import in_hooks_workspace
|
|
|
|
|
|
class RepoInstaller(object):
|
|
def __init__(self, repo_config):
|
|
self.repo_config = repo_config
|
|
|
|
@property
|
|
def repo_url(self):
|
|
return self.repo_config['repo']
|
|
|
|
@property
|
|
def sha(self):
|
|
return self.repo_config['sha']
|
|
|
|
@contextlib.contextmanager
|
|
def in_checkout(self):
|
|
with in_hooks_workspace():
|
|
with local.cwd(self.sha):
|
|
yield
|
|
|
|
def create(self):
|
|
with in_hooks_workspace():
|
|
if local.path(self.sha).exists():
|
|
# Project already exists, no reason to re-create it
|
|
return
|
|
|
|
local['git']['clone', self.repo_url, self.sha]()
|
|
with self.in_checkout():
|
|
local['git']['checkout', self.sha]()
|
|
|
|
def install(self):
|
|
# Create if we have not already
|
|
self.create()
|
|
# TODO: need to take in the config here and determine if we actually
|
|
# need to run any installers (and what languages to install)
|
|
with self.in_checkout():
|
|
if local.path('setup.py').exists():
|
|
local['virtualenv']['py_env']()
|
|
local['bash']['-c', 'source py_env/bin/activate && pip install .']()
|