mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-01-07 01:20:03 -06:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -1,16 +1,23 @@
|
||||
import os
|
||||
import pkg_resources
|
||||
|
||||
import pre_commit.constants as C
|
||||
from plumbum import local
|
||||
|
||||
|
||||
def get_root():
|
||||
return local['git']['rev-parse', '--show-toplevel']().strip()
|
||||
|
||||
|
||||
def get_pre_commit_path():
|
||||
return os.path.join(get_root(), '.git/hooks/pre-commit')
|
||||
|
||||
|
||||
def get_pre_commit_dir_path():
|
||||
return os.path.join(get_root(), C.PRE_COMMIT_DIR)
|
||||
|
||||
def create_pre_commit_package_dir():
|
||||
local.path(get_pre_commit_dir_path()).mkdir()
|
||||
|
||||
def create_pre_commit():
|
||||
path = get_pre_commit_path()
|
||||
pre_commit_file = pkg_resources.resource_filename('pre_commit', 'resources/pre-commit.sh')
|
||||
@@ -22,6 +29,3 @@ def remove_pre_commit():
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
0
pre_commit/installer/__init__.py
Normal file
0
pre_commit/installer/__init__.py
Normal file
44
pre_commit/installer/repo_installer.py
Normal file
44
pre_commit/installer/repo_installer.py
Normal file
@@ -0,0 +1,44 @@
|
||||
import contextlib
|
||||
|
||||
from plumbum import local
|
||||
from pre_commit import git
|
||||
|
||||
class RepoInstaller(object):
|
||||
|
||||
def __init__(self, git_repo_path, sha):
|
||||
self.git_repo_path = git_repo_path
|
||||
self.sha = sha
|
||||
|
||||
@contextlib.contextmanager
|
||||
def in_checkout(self):
|
||||
with local.cwd(git.get_pre_commit_dir_path()):
|
||||
with local.cwd(self.sha):
|
||||
yield
|
||||
|
||||
def create(self):
|
||||
git.create_pre_commit_package_dir()
|
||||
|
||||
with local.cwd(git.get_pre_commit_dir_path()):
|
||||
if local.path(self.sha).exists():
|
||||
# Project already exists, no reason to re-create it
|
||||
return
|
||||
|
||||
local['git']['clone', self.git_repo_path, self.sha]()
|
||||
with self.in_checkout():
|
||||
local['git']['checkout', self.sha]()
|
||||
|
||||
def install(self):
|
||||
with self.in_checkout():
|
||||
if local.path('setup.py').exists():
|
||||
local['virtualenv']['py_env']()
|
||||
local['bash']['-c', 'source py_env/bin/activate && pip install .']()
|
||||
|
||||
|
||||
def create_repo_in_env(git_repo_path, sha):
|
||||
project = RepoInstaller(git_repo_path, sha)
|
||||
project.create()
|
||||
|
||||
def install_pre_commit(git_repo_path, sha):
|
||||
project = RepoInstaller(git_repo_path, sha)
|
||||
project.create()
|
||||
project.install()
|
||||
Reference in New Issue
Block a user