mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-04-15 10:01:46 +04:00
Support repos without hooks.yaml by reading a local config
If a repo does not have a hooks.yaml any hook ids are then looked for in .pre-commit-hooks-config.yaml in the repo that is under test. It has the same format as a standard hooks.yaml. The purpose of this change is to avoid needing to mirror a linter repo just to call it. Long term, tools could be reference by a URL or other source than a git repo making having a mirror repo even more of a hassle.
This commit is contained in:
parent
b1e6063e12
commit
364da6a0a5
3 changed files with 30 additions and 9 deletions
|
|
@ -8,17 +8,34 @@ import pre_commit.constants as C
|
|||
from pre_commit.clientlib.validate_manifest import load_manifest
|
||||
|
||||
|
||||
class Manifest(object):
|
||||
def __init__(self, repo_path_getter):
|
||||
self.repo_path_getter = repo_path_getter
|
||||
class BaseManifest(object):
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@cached_property
|
||||
def manifest_contents(self):
|
||||
manifest_path = os.path.join(
|
||||
self.repo_path_getter.repo_path, C.MANIFEST_FILE,
|
||||
)
|
||||
return load_manifest(manifest_path)
|
||||
return load_manifest(self.manifest_path)
|
||||
|
||||
@cached_property
|
||||
def hooks(self):
|
||||
return dict((hook['id'], hook) for hook in self.manifest_contents)
|
||||
|
||||
def exists(self):
|
||||
return os.path.isfile(self.manifest_path)
|
||||
|
||||
|
||||
class Manifest(BaseManifest):
|
||||
def __init__(self, repo_path_getter):
|
||||
super(Manifest, self).__init__()
|
||||
|
||||
self.repo_path_getter = repo_path_getter
|
||||
self.manifest_path = os.path.join(
|
||||
self.repo_path_getter.repo_path, C.MANIFEST_FILE,
|
||||
)
|
||||
|
||||
|
||||
class ExternalManifest(BaseManifest):
|
||||
def __init__(self, path):
|
||||
super(ExternalManifest, self).__init__()
|
||||
self.path = path
|
||||
self.manifest_path = os.path.join(path, C.EXTERNAL_MANIFEST_FILE)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue