22import contextlib
33from plumbum import local
44
5+ import pre_commit .constants as C
6+ from pre_commit .clientlib .validate_manifest import validate_manifest
57from pre_commit .hooks_workspace import in_hooks_workspace
8+ from pre_commit .util import cached_property
69
710
811class Repository (object ):
912 def __init__ (self , repo_config ):
1013 self .repo_config = repo_config
1114
12- @property
15+ @cached_property
1316 def repo_url (self ):
1417 return self .repo_config ['repo' ]
1518
16- @property
19+ @cached_property
1720 def sha (self ):
1821 return self .repo_config ['sha' ]
1922
23+ @cached_property
24+ def languages (self ):
25+ return set (filter (None , (
26+ hook .get ('language' ) for hook in self .hooks .values ()
27+ )))
28+
29+ @cached_property
30+ def hooks (self ):
31+ return dict (
32+ (hook ['id' ], dict (hook , ** self .manifest [hook ['id' ]]))
33+ for hook in self .repo_config ['hooks' ]
34+ )
35+
36+ @cached_property
37+ def manifest (self ):
38+ with self .in_checkout ():
39+ return dict (
40+ (hook ['id' ], hook )
41+ for hook in validate_manifest (C .MANIFEST_FILE )
42+ )
43+
2044 @contextlib .contextmanager
2145 def in_checkout (self ):
2246 with in_hooks_workspace ():
47+ # SMELL:
48+ self .create ()
2349 with local .cwd (self .sha ):
2450 yield
2551
@@ -33,6 +59,19 @@ def create(self):
3359 with self .in_checkout ():
3460 local ['git' ]['checkout' , self .sha ]()
3561
62+ # TODO: make this shit polymorphic
63+
64+ def _install_python (self ):
65+ assert local .path ('setup.py' ).exists ()
66+ local ['virtualenv' ]['py_env' ]()
67+ local ['bash' ]['-c' , 'source py_env/bin/activate && pip install .' ]()
68+
69+ def _install_ruby (self ):
70+ raise NotImplementedError
71+
72+ def _install_node (self ):
73+ raise NotImplementedError
74+
3675 def install (self ):
3776 # Create if we have not already
3877 self .create ()
0 commit comments