prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Improve error message when attempting to run non-existent hook
  Hook id in `/.pre-commit-config.yaml` doesn't exist in the included repository
  
  (From https://github.com/pre-commit/pre-commit-hooks/issues/37)
  
  It should probably suggest updating hooks or checking the spelling of the hookid
  
  
  </issue>
  <code>
  [start of pre_commit/repository.py]
  1 from __future__ import unicode_literals
  2 
  3 import logging
  4 import shutil
  5 from collections import defaultdict
  6 
  7 from cached_property import cached_property
  8 
  9 from pre_commit import git
  10 from pre_commit.clientlib.validate_config import is_local_hooks
  11 from pre_commit.clientlib.validate_manifest import MANIFEST_JSON_SCHEMA
  12 from pre_commit.jsonschema_extensions import apply_defaults
  13 from pre_commit.languages.all import languages
  14 from pre_commit.languages.helpers import environment_dir
  15 from pre_commit.manifest import Manifest
  16 from pre_commit.prefixed_command_runner import PrefixedCommandRunner
  17 
  18 
  19 logger = logging.getLogger('pre_commit')
  20 
  21 
  22 class Repository(object):
  23     def __init__(self, repo_config, repo_path_getter):
  24         self.repo_config = repo_config
  25         self.repo_path_getter = repo_path_getter
  26         self.__installed = False
  27 
  28     @classmethod
  29     def create(cls, config, store):
  30         if is_local_hooks(config):
  31             return LocalRepository(config)
  32         else:
  33             repo_path_getter = store.get_repo_path_getter(
  34                 config['repo'], config['sha']
  35             )
  36             return cls(config, repo_path_getter)
  37 
  38     @cached_property
  39     def repo_url(self):
  40         return self.repo_config['repo']
  41 
  42     @cached_property
  43     def sha(self):
  44         return self.repo_config['sha']
  45 
  46     @cached_property
  47     def languages(self):
  48         return set(
  49             (hook['language'], hook['language_version'])
  50             for _, hook in self.hooks
  51         )
  52 
  53     @cached_property
  54     def additional_dependencies(self):
  55         dep_dict = defaultdict(lambda: defaultdict(set))
  56         for _, hook in self.hooks:
  57             dep_dict[hook['language']][hook['language_version']].update(
  58                 hook.get('additional_dependencies', []),
  59             )
  60         return dep_dict
  61 
  62     @cached_property
  63     def hooks(self):
  64         # TODO: merging in manifest dicts is a smell imo
  65         return tuple(
  66             (hook['id'], dict(self.manifest.hooks[hook['id']], **hook))
  67             for hook in self.repo_config['hooks']
  68         )
  69 
  70     @cached_property
  71     def manifest(self):
  72         return Manifest(self.repo_path_getter)
  73 
  74     @cached_property
  75     def cmd_runner(self):
  76         return PrefixedCommandRunner(self.repo_path_getter.repo_path)
  77 
  78     def require_installed(self):
  79         if self.__installed:
  80             return
  81 
  82         self.install()
  83         self.__installed = True
  84 
  85     def install(self):
  86         """Install the hook repository."""
  87         def language_is_installed(language_name, language_version):
  88             language = languages[language_name]
  89             directory = environment_dir(
  90                 language.ENVIRONMENT_DIR, language_version,
  91             )
  92             return (
  93                 directory is None or
  94                 self.cmd_runner.exists(directory, '.installed')
  95             )
  96 
  97         if not all(
  98             language_is_installed(language_name, language_version)
  99             for language_name, language_version in self.languages
  100         ):
  101             logger.info(
  102                 'Installing environment for {0}.'.format(self.repo_url)
  103             )
  104             logger.info('Once installed this environment will be reused.')
  105             logger.info('This may take a few minutes...')
  106 
  107         for language_name, language_version in self.languages:
  108             language = languages[language_name]
  109             if language_is_installed(language_name, language_version):
  110                 continue
  111 
  112             directory = environment_dir(
  113                 language.ENVIRONMENT_DIR, language_version,
  114             )
  115             # There's potentially incomplete cleanup from previous runs
  116             # Clean it up!
  117             if self.cmd_runner.exists(directory):
  118                 shutil.rmtree(self.cmd_runner.path(directory))
  119 
  120             language.install_environment(
  121                 self.cmd_runner, language_version,
  122                 self.additional_dependencies[language_name][language_version],
  123             )
  124             # Touch the .installed file (atomic) to indicate we've installed
  125             open(self.cmd_runner.path(directory, '.installed'), 'w').close()
  126 
  127     def run_hook(self, hook, file_args):
  128         """Run a hook.
  129 
  130         Args:
  131             hook - Hook dictionary
  132             file_args - List of files to run
  133         """
  134         self.require_installed()
  135         return languages[hook['language']].run_hook(
  136             self.cmd_runner, hook, file_args,
  137         )
  138 
  139 
  140 class LocalRepository(Repository):
  141     def __init__(self, repo_config):
  142         super(LocalRepository, self).__init__(repo_config, None)
  143 
  144     @cached_property
  145     def hooks(self):
  146         return tuple(
  147             (hook['id'], apply_defaults(hook, MANIFEST_JSON_SCHEMA['items']))
  148             for hook in self.repo_config['hooks']
  149         )
  150 
  151     @cached_property
  152     def cmd_runner(self):
  153         return PrefixedCommandRunner(git.get_root())
  154 
  155     @cached_property
  156     def sha(self):
  157         raise NotImplementedError
  158 
  159     @cached_property
  160     def manifest(self):
  161         raise NotImplementedError
  162
  [end of pre_commit/repository.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/pre_commit/repository.py b/pre_commit/repository.py
  --- a/pre_commit/repository.py
  +++ b/pre_commit/repository.py
  @@ -61,7 +61,16 @@
   
       @cached_property
       def hooks(self):
  -        # TODO: merging in manifest dicts is a smell imo
  +        for hook in self.repo_config['hooks']:
  +            if hook['id'] not in self.manifest.hooks:
  +                logger.error(
  +                    '`{0}` is not present in repository {1}.  '
  +                    'Typo? Perhaps it is introduced in a newer version?  '
  +                    'Often `pre-commit autoupdate` fixes this.'.format(
  +                        hook['id'], self.repo_config['repo'],
  +                    )
  +                )
  +                exit(1)
           return tuple(
               (hook['id'], dict(self.manifest.hooks[hook['id']], **hook))
               for hook in self.repo_config['hooks']
  
verification_info: {"golden_diff": "diff --git a/pre_commit/repository.py b/pre_commit/repository.py\n--- a/pre_commit/repository.py\n+++ b/pre_commit/repository.py\n@@ -61,7 +61,16 @@\n \n     @cached_property\n     def hooks(self):\n-        # TODO: merging in manifest dicts is a smell imo\n+        for hook in self.repo_config['hooks']:\n+            if hook['id'] not in self.manifest.hooks:\n+                logger.error(\n+                    '`{0}` is not present in repository {1}.  '\n+                    'Typo? Perhaps it is introduced in a newer version?  '\n+                    'Often `pre-commit autoupdate` fixes this.'.format(\n+                        hook['id'], self.repo_config['repo'],\n+                    )\n+                )\n+                exit(1)\n         return tuple(\n             (hook['id'], dict(self.manifest.hooks[hook['id']], **hook))\n             for hook in self.repo_config['hooks']\n", "issue": "Improve error message when attempting to run non-existent hook\nHook id in `/.pre-commit-config.yaml` doesn't exist in the included repository\n\n(From https://github.com/pre-commit/pre-commit-hooks/issues/37)\n\nIt should probably suggest updating hooks or checking the spelling of the hookid\n\n", "before_files": [{"content": "from __future__ import unicode_literals\n\nimport logging\nimport shutil\nfrom collections import defaultdict\n\nfrom cached_property import cached_property\n\nfrom pre_commit import git\nfrom pre_commit.clientlib.validate_config import is_local_hooks\nfrom pre_commit.clientlib.validate_manifest import MANIFEST_JSON_SCHEMA\nfrom pre_commit.jsonschema_extensions import apply_defaults\nfrom pre_commit.languages.all import languages\nfrom pre_commit.languages.helpers import environment_dir\nfrom pre_commit.manifest import Manifest\nfrom pre_commit.prefixed_command_runner import PrefixedCommandRunner\n\n\nlogger = logging.getLogger('pre_commit')\n\n\nclass Repository(object):\n    def __init__(self, repo_config, repo_path_getter):\n        self.repo_config = repo_config\n        self.repo_path_getter = repo_path_getter\n        self.__installed = False\n\n    @classmethod\n    def create(cls, config, store):\n        if is_local_hooks(config):\n            return LocalRepository(config)\n        else:\n            repo_path_getter = store.get_repo_path_getter(\n                config['repo'], config['sha']\n            )\n            return cls(config, repo_path_getter)\n\n    @cached_property\n    def repo_url(self):\n        return self.repo_config['repo']\n\n    @cached_property\n    def sha(self):\n        return self.repo_config['sha']\n\n    @cached_property\n    def languages(self):\n        return set(\n            (hook['language'], hook['language_version'])\n            for _, hook in self.hooks\n        )\n\n    @cached_property\n    def additional_dependencies(self):\n        dep_dict = defaultdict(lambda: defaultdict(set))\n        for _, hook in self.hooks:\n            dep_dict[hook['language']][hook['language_version']].update(\n                hook.get('additional_dependencies', []),\n            )\n        return dep_dict\n\n    @cached_property\n    def hooks(self):\n        # TODO: merging in manifest dicts is a smell imo\n        return tuple(\n            (hook['id'], dict(self.manifest.hooks[hook['id']], **hook))\n            for hook in self.repo_config['hooks']\n        )\n\n    @cached_property\n    def manifest(self):\n        return Manifest(self.repo_path_getter)\n\n    @cached_property\n    def cmd_runner(self):\n        return PrefixedCommandRunner(self.repo_path_getter.repo_path)\n\n    def require_installed(self):\n        if self.__installed:\n            return\n\n        self.install()\n        self.__installed = True\n\n    def install(self):\n        \"\"\"Install the hook repository.\"\"\"\n        def language_is_installed(language_name, language_version):\n            language = languages[language_name]\n            directory = environment_dir(\n                language.ENVIRONMENT_DIR, language_version,\n            )\n            return (\n                directory is None or\n                self.cmd_runner.exists(directory, '.installed')\n            )\n\n        if not all(\n            language_is_installed(language_name, language_version)\n            for language_name, language_version in self.languages\n        ):\n            logger.info(\n                'Installing environment for {0}.'.format(self.repo_url)\n            )\n            logger.info('Once installed this environment will be reused.')\n            logger.info('This may take a few minutes...')\n\n        for language_name, language_version in self.languages:\n            language = languages[language_name]\n            if language_is_installed(language_name, language_version):\n                continue\n\n            directory = environment_dir(\n                language.ENVIRONMENT_DIR, language_version,\n            )\n            # There's potentially incomplete cleanup from previous runs\n            # Clean it up!\n            if self.cmd_runner.exists(directory):\n                shutil.rmtree(self.cmd_runner.path(directory))\n\n            language.install_environment(\n                self.cmd_runner, language_version,\n                self.additional_dependencies[language_name][language_version],\n            )\n            # Touch the .installed file (atomic) to indicate we've installed\n            open(self.cmd_runner.path(directory, '.installed'), 'w').close()\n\n    def run_hook(self, hook, file_args):\n        \"\"\"Run a hook.\n\n        Args:\n            hook - Hook dictionary\n            file_args - List of files to run\n        \"\"\"\n        self.require_installed()\n        return languages[hook['language']].run_hook(\n            self.cmd_runner, hook, file_args,\n        )\n\n\nclass LocalRepository(Repository):\n    def __init__(self, repo_config):\n        super(LocalRepository, self).__init__(repo_config, None)\n\n    @cached_property\n    def hooks(self):\n        return tuple(\n            (hook['id'], apply_defaults(hook, MANIFEST_JSON_SCHEMA['items']))\n            for hook in self.repo_config['hooks']\n        )\n\n    @cached_property\n    def cmd_runner(self):\n        return PrefixedCommandRunner(git.get_root())\n\n    @cached_property\n    def sha(self):\n        raise NotImplementedError\n\n    @cached_property\n    def manifest(self):\n        raise NotImplementedError\n", "path": "pre_commit/repository.py"}]}