mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Repository now parses languages and manifests
This commit is contained in:
parent
d77d01cd22
commit
5ca8f4ffa8
8 changed files with 114 additions and 23 deletions
|
|
@ -2,24 +2,50 @@
|
|||
import contextlib
|
||||
from plumbum import local
|
||||
|
||||
import pre_commit.constants as C
|
||||
from pre_commit.clientlib.validate_manifest import validate_manifest
|
||||
from pre_commit.hooks_workspace import in_hooks_workspace
|
||||
from pre_commit.util import cached_property
|
||||
|
||||
|
||||
class Repository(object):
|
||||
def __init__(self, repo_config):
|
||||
self.repo_config = repo_config
|
||||
|
||||
@property
|
||||
@cached_property
|
||||
def repo_url(self):
|
||||
return self.repo_config['repo']
|
||||
|
||||
@property
|
||||
@cached_property
|
||||
def sha(self):
|
||||
return self.repo_config['sha']
|
||||
|
||||
@cached_property
|
||||
def languages(self):
|
||||
return set(filter(None, (
|
||||
hook.get('language') for hook in self.hooks.values()
|
||||
)))
|
||||
|
||||
@cached_property
|
||||
def hooks(self):
|
||||
return dict(
|
||||
(hook['id'], dict(hook, **self.manifest[hook['id']]))
|
||||
for hook in self.repo_config['hooks']
|
||||
)
|
||||
|
||||
@cached_property
|
||||
def manifest(self):
|
||||
with self.in_checkout():
|
||||
return dict(
|
||||
(hook['id'], hook)
|
||||
for hook in validate_manifest(C.MANIFEST_FILE)
|
||||
)
|
||||
|
||||
@contextlib.contextmanager
|
||||
def in_checkout(self):
|
||||
with in_hooks_workspace():
|
||||
# SMELL:
|
||||
self.create()
|
||||
with local.cwd(self.sha):
|
||||
yield
|
||||
|
||||
|
|
@ -33,6 +59,19 @@ class Repository(object):
|
|||
with self.in_checkout():
|
||||
local['git']['checkout', self.sha]()
|
||||
|
||||
# TODO: make this shit polymorphic
|
||||
|
||||
def _install_python(self):
|
||||
assert local.path('setup.py').exists()
|
||||
local['virtualenv']['py_env']()
|
||||
local['bash']['-c', 'source py_env/bin/activate && pip install .']()
|
||||
|
||||
def _install_ruby(self):
|
||||
raise NotImplementedError
|
||||
|
||||
def _install_node(self):
|
||||
raise NotImplementedError
|
||||
|
||||
def install(self):
|
||||
# Create if we have not already
|
||||
self.create()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue