mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Rename RepoInstaller to Repository
This commit is contained in:
parent
abea886a3d
commit
d77d01cd22
3 changed files with 43 additions and 63 deletions
44
pre_commit/repository.py
Normal file
44
pre_commit/repository.py
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
|
||||
import contextlib
|
||||
from plumbum import local
|
||||
|
||||
from pre_commit.hooks_workspace import in_hooks_workspace
|
||||
|
||||
|
||||
class Repository(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 .']()
|
||||
Loading…
Add table
Add a link
Reference in a new issue