Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 84b1ba5

Browse files
committed
Remove Manifest, no longer a useful abstraction
1 parent 7182227 commit 84b1ba5

6 files changed

Lines changed: 38 additions & 90 deletions

File tree

pre_commit/commands/autoupdate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def _update_repo(repo_config, runner, tags_only):
5757

5858
# See if any of our hooks were deleted with the new commits
5959
hooks = {hook['id'] for hook in repo.repo_config['hooks']}
60-
hooks_missing = hooks - (hooks & set(new_repo.manifest.hooks))
60+
hooks_missing = hooks - (hooks & set(new_repo.manifest_hooks))
6161
if hooks_missing:
6262
raise RepositoryCannotBeUpdatedError(
6363
'Cannot update because the tip of master is missing these hooks:\n'

pre_commit/commands/try_repo.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
import pre_commit.constants as C
1010
from pre_commit import git
1111
from pre_commit import output
12+
from pre_commit.clientlib import load_manifest
1213
from pre_commit.commands.run import run
13-
from pre_commit.manifest import Manifest
1414
from pre_commit.runner import Runner
1515
from pre_commit.store import Store
1616
from pre_commit.util import tmpdir
@@ -23,8 +23,10 @@ def try_repo(args):
2323
if args.hook:
2424
hooks = [{'id': args.hook}]
2525
else:
26-
manifest = Manifest(Store(tempdir).clone(args.repo, ref))
27-
hooks = [{'id': hook_id} for hook_id in sorted(manifest.hooks)]
26+
repo_path = Store(tempdir).clone(args.repo, ref)
27+
manifest = load_manifest(os.path.join(repo_path, C.MANIFEST_FILE))
28+
manifest = sorted(manifest, key=lambda hook: hook['id'])
29+
hooks = [{'id': hook['id']} for hook in manifest]
2830

2931
items = (('repo', args.repo), ('sha', ref), ('hooks', hooks))
3032
config = {'repos': [collections.OrderedDict(items)]}

pre_commit/manifest.py

Lines changed: 0 additions & 21 deletions
This file was deleted.

pre_commit/repository.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
from pre_commit import five
1515
from pre_commit import git
1616
from pre_commit.clientlib import is_local_repo
17+
from pre_commit.clientlib import load_manifest
1718
from pre_commit.clientlib import MANIFEST_HOOK_DICT
1819
from pre_commit.languages.all import languages
1920
from pre_commit.languages.helpers import environment_dir
20-
from pre_commit.manifest import Manifest
2121
from pre_commit.prefixed_command_runner import PrefixedCommandRunner
2222
from pre_commit.schema import apply_defaults
2323
from pre_commit.schema import validate
@@ -152,13 +152,14 @@ def _cmd_runner_from_deps(self, language_name, deps):
152152
return self._cmd_runner
153153

154154
@cached_property
155-
def manifest(self):
156-
return Manifest(self._repo_path)
155+
def manifest_hooks(self):
156+
manifest_path = os.path.join(self._repo_path, C.MANIFEST_FILE)
157+
return {hook['id']: hook for hook in load_manifest(manifest_path)}
157158

158159
@cached_property
159160
def hooks(self):
160161
for hook in self.repo_config['hooks']:
161-
if hook['id'] not in self.manifest.hooks:
162+
if hook['id'] not in self.manifest_hooks:
162163
logger.error(
163164
'`{}` is not present in repository {}. '
164165
'Typo? Perhaps it is introduced in a newer version? '
@@ -169,7 +170,7 @@ def hooks(self):
169170
exit(1)
170171

171172
return tuple(
172-
(hook['id'], _hook(self.manifest.hooks[hook['id']], hook))
173+
(hook['id'], _hook(self.manifest_hooks[hook['id']], hook))
173174
for hook in self.repo_config['hooks']
174175
)
175176

tests/manifest_test.py

Lines changed: 0 additions & 60 deletions
This file was deleted.

tests/repository_test.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -746,3 +746,29 @@ def test_versions_ok(tempdir_factory, store, version):
746746
config = make_config_from_repo(path)
747747
# Should succeed
748748
Repository.create(config, store).require_installed()
749+
750+
751+
def test_manifest_hooks(tempdir_factory, store):
752+
path = make_repo(tempdir_factory, 'script_hooks_repo')
753+
config = make_config_from_repo(path)
754+
repo = Repository.create(config, store)
755+
756+
assert repo.manifest_hooks['bash_hook'] == {
757+
'always_run': False,
758+
'additional_dependencies': [],
759+
'args': [],
760+
'description': '',
761+
'entry': 'bin/hook.sh',
762+
'exclude': '^$',
763+
'files': '',
764+
'id': 'bash_hook',
765+
'language': 'script',
766+
'language_version': 'default',
767+
'log_file': '',
768+
'minimum_pre_commit_version': '0',
769+
'name': 'Bash hook',
770+
'pass_filenames': True,
771+
'stages': [],
772+
'types': ['file'],
773+
'exclude_types': [],
774+
}

0 commit comments

Comments
 (0)