mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Add Runner interface.
This commit is contained in:
parent
ae1d1681b2
commit
88686d298f
25 changed files with 282 additions and 148 deletions
42
pre_commit/runner.py
Normal file
42
pre_commit/runner.py
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
|
||||
import os
|
||||
import os.path
|
||||
|
||||
import pre_commit.constants as C
|
||||
from pre_commit import git
|
||||
from pre_commit.clientlib.validate_config import load_config
|
||||
from pre_commit.repository import Repository
|
||||
from pre_commit.util import cached_property
|
||||
|
||||
|
||||
class Runner(object):
|
||||
"""A `Runner` represents the execution context of the hooks. Notably the
|
||||
repository under test.
|
||||
"""
|
||||
|
||||
def __init__(self, git_root):
|
||||
self.git_root = git_root
|
||||
|
||||
@classmethod
|
||||
def create(cls):
|
||||
"""Creates a PreCommitRunner by doing the following:
|
||||
- Finds the root of the current git repository
|
||||
- chdirs to that directory
|
||||
"""
|
||||
root = git.get_root()
|
||||
os.chdir(root)
|
||||
return cls(root)
|
||||
|
||||
@cached_property
|
||||
def hooks_workspace_path(self):
|
||||
return os.path.join(self.git_root, C.HOOKS_WORKSPACE)
|
||||
|
||||
@cached_property
|
||||
def config_file_path(self):
|
||||
return os.path.join(self.git_root, C.CONFIG_FILE)
|
||||
|
||||
@cached_property
|
||||
def repositories(self):
|
||||
"""Returns a tuple of the configured repositories."""
|
||||
config = load_config(self.config_file_path)
|
||||
return tuple(map(Repository, config))
|
||||
Loading…
Add table
Add a link
Reference in a new issue