mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-01-17 22:40:11 -06:00
Introduce .pre-commit-hooks.yaml as a replacement for hooks.yaml
This commit is contained in:
@@ -3,7 +3,9 @@ from __future__ import unicode_literals
|
||||
|
||||
CONFIG_FILE = '.pre-commit-config.yaml'
|
||||
|
||||
MANIFEST_FILE = 'hooks.yaml'
|
||||
# In 0.12.0, the default file was changed to be namespaced
|
||||
MANIFEST_FILE = '.pre-commit-hooks.yaml'
|
||||
MANIFEST_FILE_LEGACY = 'hooks.yaml'
|
||||
|
||||
YAML_DUMP_KWARGS = {
|
||||
'default_flow_style': False,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import logging
|
||||
import os.path
|
||||
|
||||
from cached_property import cached_property
|
||||
@@ -8,16 +9,33 @@ import pre_commit.constants as C
|
||||
from pre_commit.clientlib.validate_manifest import load_manifest
|
||||
|
||||
|
||||
logger = logging.getLogger('pre_commit')
|
||||
|
||||
|
||||
class Manifest(object):
|
||||
def __init__(self, repo_path_getter):
|
||||
def __init__(self, repo_path_getter, repo_url):
|
||||
self.repo_path_getter = repo_path_getter
|
||||
self.repo_url = repo_url
|
||||
|
||||
@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)
|
||||
repo_path = self.repo_path_getter.repo_path
|
||||
default_path = os.path.join(repo_path, C.MANIFEST_FILE)
|
||||
legacy_path = os.path.join(repo_path, C.MANIFEST_FILE_LEGACY)
|
||||
if os.path.exists(default_path):
|
||||
return load_manifest(default_path)
|
||||
else:
|
||||
logger.warning(
|
||||
'{} uses legacy {} to provide hooks.\n'
|
||||
'In newer versions, this file is called {}\n'
|
||||
'This will work in this version of pre-commit but will be '
|
||||
'removed at a later time.\n'
|
||||
'If `pre-commit autoupdate` does not silence this warning '
|
||||
'consider making an issue / pull request.'.format(
|
||||
self.repo_url, C.MANIFEST_FILE_LEGACY, C.MANIFEST_FILE,
|
||||
)
|
||||
)
|
||||
return load_manifest(legacy_path)
|
||||
|
||||
@cached_property
|
||||
def hooks(self):
|
||||
|
||||
@@ -104,7 +104,7 @@ class Repository(object):
|
||||
|
||||
@cached_property
|
||||
def manifest(self):
|
||||
return Manifest(self.repo_path_getter)
|
||||
return Manifest(self.repo_path_getter, self.repo_url)
|
||||
|
||||
@cached_property
|
||||
def cmd_runner(self):
|
||||
|
||||
Reference in New Issue
Block a user