mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-20 09:34:42 +04:00
Made env generation polymorphic
This commit is contained in:
parent
5ca8f4ffa8
commit
47bad120e4
2 changed files with 53 additions and 20 deletions
|
|
@ -8,6 +8,27 @@ from pre_commit.hooks_workspace import in_hooks_workspace
|
||||||
from pre_commit.util import cached_property
|
from pre_commit.util import cached_property
|
||||||
|
|
||||||
|
|
||||||
|
def install_python(repo):
|
||||||
|
assert local.path('setup.py').exists()
|
||||||
|
local['virtualenv']['py_env']()
|
||||||
|
local['bash']['-c', 'source py_env/bin/activate && pip install .']()
|
||||||
|
|
||||||
|
|
||||||
|
def install_ruby(repo):
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
|
|
||||||
|
def install_node(repo):
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
|
|
||||||
|
language_to_repo_setup_strategy = {
|
||||||
|
'python': install_python,
|
||||||
|
'ruby': install_ruby,
|
||||||
|
'node': install_node,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class Repository(object):
|
class Repository(object):
|
||||||
def __init__(self, repo_config):
|
def __init__(self, repo_config):
|
||||||
self.repo_config = repo_config
|
self.repo_config = repo_config
|
||||||
|
|
@ -59,25 +80,8 @@ class Repository(object):
|
||||||
with self.in_checkout():
|
with self.in_checkout():
|
||||||
local['git']['checkout', self.sha]()
|
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):
|
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():
|
with self.in_checkout():
|
||||||
if local.path('setup.py').exists():
|
for language in C.SUPPORTED_LANGUAGES:
|
||||||
local['virtualenv']['py_env']()
|
if language in self.languages:
|
||||||
local['bash']['-c', 'source py_env/bin/activate && pip install .']()
|
language_to_repo_setup_strategy[language](self)
|
||||||
29
tests/util_test.py
Normal file
29
tests/util_test.py
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
import time
|
||||||
|
|
||||||
|
from pre_commit.util import cached_property
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def class_with_cached_property():
|
||||||
|
class Foo(object):
|
||||||
|
@cached_property
|
||||||
|
def foo(self):
|
||||||
|
return "Foo" + str(time.time())
|
||||||
|
|
||||||
|
return Foo
|
||||||
|
|
||||||
|
|
||||||
|
def test_cached_property(class_with_cached_property):
|
||||||
|
instance = class_with_cached_property()
|
||||||
|
val = instance.foo
|
||||||
|
val2 = instance.foo
|
||||||
|
assert val is val2
|
||||||
|
|
||||||
|
|
||||||
|
def test_unbound_cached_property(class_with_cached_property):
|
||||||
|
# Make sure we don't blow up when accessing the property unbound
|
||||||
|
prop = class_with_cached_property.foo
|
||||||
|
assert isinstance(prop, cached_property)
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue