mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-20 01:24:42 +04:00
Merge pull request #648 from pre-commit/no_more_manifest_class
Remove Manifest, no longer a useful abstraction
This commit is contained in:
commit
9e193f7fc8
6 changed files with 38 additions and 90 deletions
|
|
@ -57,7 +57,7 @@ def _update_repo(repo_config, runner, tags_only):
|
||||||
|
|
||||||
# See if any of our hooks were deleted with the new commits
|
# See if any of our hooks were deleted with the new commits
|
||||||
hooks = {hook['id'] for hook in repo.repo_config['hooks']}
|
hooks = {hook['id'] for hook in repo.repo_config['hooks']}
|
||||||
hooks_missing = hooks - (hooks & set(new_repo.manifest.hooks))
|
hooks_missing = hooks - (hooks & set(new_repo.manifest_hooks))
|
||||||
if hooks_missing:
|
if hooks_missing:
|
||||||
raise RepositoryCannotBeUpdatedError(
|
raise RepositoryCannotBeUpdatedError(
|
||||||
'Cannot update because the tip of master is missing these hooks:\n'
|
'Cannot update because the tip of master is missing these hooks:\n'
|
||||||
|
|
|
||||||
|
|
@ -9,8 +9,8 @@ from aspy.yaml import ordered_dump
|
||||||
import pre_commit.constants as C
|
import pre_commit.constants as C
|
||||||
from pre_commit import git
|
from pre_commit import git
|
||||||
from pre_commit import output
|
from pre_commit import output
|
||||||
|
from pre_commit.clientlib import load_manifest
|
||||||
from pre_commit.commands.run import run
|
from pre_commit.commands.run import run
|
||||||
from pre_commit.manifest import Manifest
|
|
||||||
from pre_commit.runner import Runner
|
from pre_commit.runner import Runner
|
||||||
from pre_commit.store import Store
|
from pre_commit.store import Store
|
||||||
from pre_commit.util import tmpdir
|
from pre_commit.util import tmpdir
|
||||||
|
|
@ -23,8 +23,10 @@ def try_repo(args):
|
||||||
if args.hook:
|
if args.hook:
|
||||||
hooks = [{'id': args.hook}]
|
hooks = [{'id': args.hook}]
|
||||||
else:
|
else:
|
||||||
manifest = Manifest(Store(tempdir).clone(args.repo, ref))
|
repo_path = Store(tempdir).clone(args.repo, ref)
|
||||||
hooks = [{'id': hook_id} for hook_id in sorted(manifest.hooks)]
|
manifest = load_manifest(os.path.join(repo_path, C.MANIFEST_FILE))
|
||||||
|
manifest = sorted(manifest, key=lambda hook: hook['id'])
|
||||||
|
hooks = [{'id': hook['id']} for hook in manifest]
|
||||||
|
|
||||||
items = (('repo', args.repo), ('sha', ref), ('hooks', hooks))
|
items = (('repo', args.repo), ('sha', ref), ('hooks', hooks))
|
||||||
config = {'repos': [collections.OrderedDict(items)]}
|
config = {'repos': [collections.OrderedDict(items)]}
|
||||||
|
|
|
||||||
|
|
@ -1,21 +0,0 @@
|
||||||
from __future__ import unicode_literals
|
|
||||||
|
|
||||||
import os.path
|
|
||||||
|
|
||||||
from cached_property import cached_property
|
|
||||||
|
|
||||||
import pre_commit.constants as C
|
|
||||||
from pre_commit.clientlib import load_manifest
|
|
||||||
|
|
||||||
|
|
||||||
class Manifest(object):
|
|
||||||
def __init__(self, repo_path):
|
|
||||||
self.repo_path = repo_path
|
|
||||||
|
|
||||||
@cached_property
|
|
||||||
def manifest_contents(self):
|
|
||||||
return load_manifest(os.path.join(self.repo_path, C.MANIFEST_FILE))
|
|
||||||
|
|
||||||
@cached_property
|
|
||||||
def hooks(self):
|
|
||||||
return {hook['id']: hook for hook in self.manifest_contents}
|
|
||||||
|
|
@ -14,10 +14,10 @@ import pre_commit.constants as C
|
||||||
from pre_commit import five
|
from pre_commit import five
|
||||||
from pre_commit import git
|
from pre_commit import git
|
||||||
from pre_commit.clientlib import is_local_repo
|
from pre_commit.clientlib import is_local_repo
|
||||||
|
from pre_commit.clientlib import load_manifest
|
||||||
from pre_commit.clientlib import MANIFEST_HOOK_DICT
|
from pre_commit.clientlib import MANIFEST_HOOK_DICT
|
||||||
from pre_commit.languages.all import languages
|
from pre_commit.languages.all import languages
|
||||||
from pre_commit.languages.helpers import environment_dir
|
from pre_commit.languages.helpers import environment_dir
|
||||||
from pre_commit.manifest import Manifest
|
|
||||||
from pre_commit.prefixed_command_runner import PrefixedCommandRunner
|
from pre_commit.prefixed_command_runner import PrefixedCommandRunner
|
||||||
from pre_commit.schema import apply_defaults
|
from pre_commit.schema import apply_defaults
|
||||||
from pre_commit.schema import validate
|
from pre_commit.schema import validate
|
||||||
|
|
@ -152,13 +152,14 @@ class Repository(object):
|
||||||
return self._cmd_runner
|
return self._cmd_runner
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def manifest(self):
|
def manifest_hooks(self):
|
||||||
return Manifest(self._repo_path)
|
manifest_path = os.path.join(self._repo_path, C.MANIFEST_FILE)
|
||||||
|
return {hook['id']: hook for hook in load_manifest(manifest_path)}
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def hooks(self):
|
def hooks(self):
|
||||||
for hook in self.repo_config['hooks']:
|
for hook in self.repo_config['hooks']:
|
||||||
if hook['id'] not in self.manifest.hooks:
|
if hook['id'] not in self.manifest_hooks:
|
||||||
logger.error(
|
logger.error(
|
||||||
'`{}` is not present in repository {}. '
|
'`{}` is not present in repository {}. '
|
||||||
'Typo? Perhaps it is introduced in a newer version? '
|
'Typo? Perhaps it is introduced in a newer version? '
|
||||||
|
|
@ -169,7 +170,7 @@ class Repository(object):
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
return tuple(
|
return tuple(
|
||||||
(hook['id'], _hook(self.manifest.hooks[hook['id']], hook))
|
(hook['id'], _hook(self.manifest_hooks[hook['id']], hook))
|
||||||
for hook in self.repo_config['hooks']
|
for hook in self.repo_config['hooks']
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,60 +0,0 @@
|
||||||
from __future__ import absolute_import
|
|
||||||
from __future__ import unicode_literals
|
|
||||||
|
|
||||||
import pytest
|
|
||||||
|
|
||||||
from pre_commit import git
|
|
||||||
from pre_commit.manifest import Manifest
|
|
||||||
from testing.fixtures import make_repo
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.yield_fixture
|
|
||||||
def manifest(store, tempdir_factory):
|
|
||||||
path = make_repo(tempdir_factory, 'script_hooks_repo')
|
|
||||||
repo_path = store.clone(path, git.head_sha(path))
|
|
||||||
yield Manifest(repo_path)
|
|
||||||
|
|
||||||
|
|
||||||
def test_manifest_contents(manifest):
|
|
||||||
# Should just retrieve the manifest contents
|
|
||||||
assert manifest.manifest_contents == [{
|
|
||||||
'always_run': False,
|
|
||||||
'additional_dependencies': [],
|
|
||||||
'args': [],
|
|
||||||
'description': '',
|
|
||||||
'entry': 'bin/hook.sh',
|
|
||||||
'exclude': '^$',
|
|
||||||
'files': '',
|
|
||||||
'id': 'bash_hook',
|
|
||||||
'language': 'script',
|
|
||||||
'language_version': 'default',
|
|
||||||
'log_file': '',
|
|
||||||
'minimum_pre_commit_version': '0',
|
|
||||||
'name': 'Bash hook',
|
|
||||||
'pass_filenames': True,
|
|
||||||
'stages': [],
|
|
||||||
'types': ['file'],
|
|
||||||
'exclude_types': [],
|
|
||||||
}]
|
|
||||||
|
|
||||||
|
|
||||||
def test_hooks(manifest):
|
|
||||||
assert manifest.hooks['bash_hook'] == {
|
|
||||||
'always_run': False,
|
|
||||||
'additional_dependencies': [],
|
|
||||||
'args': [],
|
|
||||||
'description': '',
|
|
||||||
'entry': 'bin/hook.sh',
|
|
||||||
'exclude': '^$',
|
|
||||||
'files': '',
|
|
||||||
'id': 'bash_hook',
|
|
||||||
'language': 'script',
|
|
||||||
'language_version': 'default',
|
|
||||||
'log_file': '',
|
|
||||||
'minimum_pre_commit_version': '0',
|
|
||||||
'name': 'Bash hook',
|
|
||||||
'pass_filenames': True,
|
|
||||||
'stages': [],
|
|
||||||
'types': ['file'],
|
|
||||||
'exclude_types': [],
|
|
||||||
}
|
|
||||||
|
|
@ -746,3 +746,29 @@ def test_versions_ok(tempdir_factory, store, version):
|
||||||
config = make_config_from_repo(path)
|
config = make_config_from_repo(path)
|
||||||
# Should succeed
|
# Should succeed
|
||||||
Repository.create(config, store).require_installed()
|
Repository.create(config, store).require_installed()
|
||||||
|
|
||||||
|
|
||||||
|
def test_manifest_hooks(tempdir_factory, store):
|
||||||
|
path = make_repo(tempdir_factory, 'script_hooks_repo')
|
||||||
|
config = make_config_from_repo(path)
|
||||||
|
repo = Repository.create(config, store)
|
||||||
|
|
||||||
|
assert repo.manifest_hooks['bash_hook'] == {
|
||||||
|
'always_run': False,
|
||||||
|
'additional_dependencies': [],
|
||||||
|
'args': [],
|
||||||
|
'description': '',
|
||||||
|
'entry': 'bin/hook.sh',
|
||||||
|
'exclude': '^$',
|
||||||
|
'files': '',
|
||||||
|
'id': 'bash_hook',
|
||||||
|
'language': 'script',
|
||||||
|
'language_version': 'default',
|
||||||
|
'log_file': '',
|
||||||
|
'minimum_pre_commit_version': '0',
|
||||||
|
'name': 'Bash hook',
|
||||||
|
'pass_filenames': True,
|
||||||
|
'stages': [],
|
||||||
|
'types': ['file'],
|
||||||
|
'exclude_types': [],
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue