prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  pip-compile looses `via` with pip 8
  ```
  $ echo jinja2 > req
  $ pip-compile --version
  pip-compile, version 1.5
  $ pip --version
  pip 7.1.2 from <snip>lib/python2.7/site-packages (python 2.7)
  
  pip-compile req
  #
  # This file is autogenerated by pip-compile
  # Make changes in req, then run this to update:
  #
  #    pip-compile req
  #
  
  jinja2==2.8
  markupsafe==0.23          # via jinja2
  
  $ pip install -U pip
  <snip>
  
  $ pip --version
  pip 8.0.2 from <snip>lib/python2.7/site-packages (python 2.7)
  
  pip-compile req
  #
  # This file is autogenerated by pip-compile
  # Make changes in req, then run this to update:
  #
  #    pip-compile req
  #
  
  jinja2==2.8
  MarkupSafe==0.23
  ```
  
  note the missing `via jinja2` for pip 8
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `piptools/writer.py`
  Content:
  ```
  1 import os
  2 from os.path import basename
  3 
  4 from ._compat import ExitStack
  5 from .click import unstyle
  6 from .io import AtomicSaver
  7 from .logging import log
  8 from .utils import comment, format_requirement
  9 
  10 
  11 class OutputWriter(object):
  12     def __init__(self, src_file, dst_file, dry_run, emit_header, emit_index, annotate,
  13                  default_index_url, index_urls):
  14         self.src_file = src_file
  15         self.dst_file = dst_file
  16         self.dry_run = dry_run
  17         self.emit_header = emit_header
  18         self.emit_index = emit_index
  19         self.annotate = annotate
  20         self.default_index_url = default_index_url
  21         self.index_urls = index_urls
  22 
  23     def _sort_key(self, ireq):
  24         return (not ireq.editable, str(ireq.req).lower())
  25 
  26     def write_header(self):
  27         if self.emit_header:
  28             yield comment('#')
  29             yield comment('# This file is autogenerated by pip-compile')
  30             yield comment('# Make changes in {}, then run this to update:'.format(basename(self.src_file)))
  31             yield comment('#')
  32             args = ''
  33             if not self.emit_index:
  34                 args += '--no-index '
  35             if not self.annotate:
  36                 args += '--no-annotate '
  37             yield comment('#    pip-compile {args}{filename}'.format(
  38                           args=args,
  39                           filename=basename(self.src_file)))
  40             yield comment('#')
  41 
  42     def write_index_options(self):
  43         if self.emit_index:
  44             emitted = False
  45             for index, index_url in enumerate(self.index_urls):
  46                 if index_url.rstrip('/') == self.default_index_url:
  47                     continue
  48                 flag = '--index-url' if index == 0 else '--extra-index-url'
  49                 yield '{} {}'.format(flag, index_url)
  50                 emitted = True
  51             if emitted:
  52                 yield ''  # extra line of whitespace
  53 
  54     def _iter_lines(self, results, reverse_dependencies, primary_packages):
  55         for line in self.write_header():
  56             yield line
  57         for line in self.write_index_options():
  58             yield line
  59 
  60         UNSAFE_PACKAGES = {'setuptools', 'distribute', 'pip'}
  61         unsafe_packages = {r for r in results if r.name in UNSAFE_PACKAGES}
  62         packages = {r for r in results if r.name not in UNSAFE_PACKAGES}
  63 
  64         packages = sorted(packages, key=self._sort_key)
  65         unsafe_packages = sorted(unsafe_packages, key=self._sort_key)
  66 
  67         for ireq in packages:
  68             line = self._format_requirement(ireq, reverse_dependencies, primary_packages)
  69             yield line
  70 
  71         if unsafe_packages:
  72             yield ''
  73             yield comment('# The following packages are commented out because they are')
  74             yield comment('# considered to be unsafe in a requirements file:')
  75 
  76             for ireq in unsafe_packages:
  77                 line = self._format_requirement(ireq, reverse_dependencies, primary_packages, include_specifier=False)
  78                 yield comment('# ' + line)
  79 
  80     def write(self, results, reverse_dependencies, primary_packages):
  81         with ExitStack() as stack:
  82             f = None
  83             if not self.dry_run:
  84                 f = stack.enter_context(AtomicSaver(self.dst_file))
  85 
  86             for line in self._iter_lines(results, reverse_dependencies, primary_packages):
  87                 log.info(line)
  88                 if f:
  89                     f.write(unstyle(line).encode('utf-8'))
  90                     f.write(os.linesep.encode('utf-8'))
  91 
  92     def _format_requirement(self, ireq, reverse_dependencies, primary_packages, include_specifier=True):
  93         line = format_requirement(ireq, include_specifier=include_specifier)
  94         if not self.annotate or ireq.name in primary_packages:
  95             return line
  96 
  97         # Annotate what packages this package is required by
  98         required_by = reverse_dependencies.get(ireq.name, [])
  99         if required_by:
  100             line = line.ljust(24)
  101             annotation = ', '.join(sorted(required_by))
  102             line += comment('  # via ' + annotation)
  103         return line
  104
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/piptools/writer.py b/piptools/writer.py
  --- a/piptools/writer.py
  +++ b/piptools/writer.py
  @@ -95,7 +95,7 @@
               return line
   
           # Annotate what packages this package is required by
  -        required_by = reverse_dependencies.get(ireq.name, [])
  +        required_by = reverse_dependencies.get(ireq.name.lower(), [])
           if required_by:
               line = line.ljust(24)
               annotation = ', '.join(sorted(required_by))
  
verification_info: {"golden_diff": "diff --git a/piptools/writer.py b/piptools/writer.py\n--- a/piptools/writer.py\n+++ b/piptools/writer.py\n@@ -95,7 +95,7 @@\n             return line\n \n         # Annotate what packages this package is required by\n-        required_by = reverse_dependencies.get(ireq.name, [])\n+        required_by = reverse_dependencies.get(ireq.name.lower(), [])\n         if required_by:\n             line = line.ljust(24)\n             annotation = ', '.join(sorted(required_by))\n", "issue": "pip-compile looses `via` with pip 8\n```\n$ echo jinja2 > req\n$ pip-compile --version\npip-compile, version 1.5\n$ pip --version\npip 7.1.2 from <snip>lib/python2.7/site-packages (python 2.7)\n\npip-compile req\n#\n# This file is autogenerated by pip-compile\n# Make changes in req, then run this to update:\n#\n#    pip-compile req\n#\n\njinja2==2.8\nmarkupsafe==0.23          # via jinja2\n\n$ pip install -U pip\n<snip>\n\n$ pip --version\npip 8.0.2 from <snip>lib/python2.7/site-packages (python 2.7)\n\npip-compile req\n#\n# This file is autogenerated by pip-compile\n# Make changes in req, then run this to update:\n#\n#    pip-compile req\n#\n\njinja2==2.8\nMarkupSafe==0.23\n```\n\nnote the missing `via jinja2` for pip 8\n\n", "before_files": [{"content": "import os\nfrom os.path import basename\n\nfrom ._compat import ExitStack\nfrom .click import unstyle\nfrom .io import AtomicSaver\nfrom .logging import log\nfrom .utils import comment, format_requirement\n\n\nclass OutputWriter(object):\n    def __init__(self, src_file, dst_file, dry_run, emit_header, emit_index, annotate,\n                 default_index_url, index_urls):\n        self.src_file = src_file\n        self.dst_file = dst_file\n        self.dry_run = dry_run\n        self.emit_header = emit_header\n        self.emit_index = emit_index\n        self.annotate = annotate\n        self.default_index_url = default_index_url\n        self.index_urls = index_urls\n\n    def _sort_key(self, ireq):\n        return (not ireq.editable, str(ireq.req).lower())\n\n    def write_header(self):\n        if self.emit_header:\n            yield comment('#')\n            yield comment('# This file is autogenerated by pip-compile')\n            yield comment('# Make changes in {}, then run this to update:'.format(basename(self.src_file)))\n            yield comment('#')\n            args = ''\n            if not self.emit_index:\n                args += '--no-index '\n            if not self.annotate:\n                args += '--no-annotate '\n            yield comment('#    pip-compile {args}{filename}'.format(\n                          args=args,\n                          filename=basename(self.src_file)))\n            yield comment('#')\n\n    def write_index_options(self):\n        if self.emit_index:\n            emitted = False\n            for index, index_url in enumerate(self.index_urls):\n                if index_url.rstrip('/') == self.default_index_url:\n                    continue\n                flag = '--index-url' if index == 0 else '--extra-index-url'\n                yield '{} {}'.format(flag, index_url)\n                emitted = True\n            if emitted:\n                yield ''  # extra line of whitespace\n\n    def _iter_lines(self, results, reverse_dependencies, primary_packages):\n        for line in self.write_header():\n            yield line\n        for line in self.write_index_options():\n            yield line\n\n        UNSAFE_PACKAGES = {'setuptools', 'distribute', 'pip'}\n        unsafe_packages = {r for r in results if r.name in UNSAFE_PACKAGES}\n        packages = {r for r in results if r.name not in UNSAFE_PACKAGES}\n\n        packages = sorted(packages, key=self._sort_key)\n        unsafe_packages = sorted(unsafe_packages, key=self._sort_key)\n\n        for ireq in packages:\n            line = self._format_requirement(ireq, reverse_dependencies, primary_packages)\n            yield line\n\n        if unsafe_packages:\n            yield ''\n            yield comment('# The following packages are commented out because they are')\n            yield comment('# considered to be unsafe in a requirements file:')\n\n            for ireq in unsafe_packages:\n                line = self._format_requirement(ireq, reverse_dependencies, primary_packages, include_specifier=False)\n                yield comment('# ' + line)\n\n    def write(self, results, reverse_dependencies, primary_packages):\n        with ExitStack() as stack:\n            f = None\n            if not self.dry_run:\n                f = stack.enter_context(AtomicSaver(self.dst_file))\n\n            for line in self._iter_lines(results, reverse_dependencies, primary_packages):\n                log.info(line)\n                if f:\n                    f.write(unstyle(line).encode('utf-8'))\n                    f.write(os.linesep.encode('utf-8'))\n\n    def _format_requirement(self, ireq, reverse_dependencies, primary_packages, include_specifier=True):\n        line = format_requirement(ireq, include_specifier=include_specifier)\n        if not self.annotate or ireq.name in primary_packages:\n            return line\n\n        # Annotate what packages this package is required by\n        required_by = reverse_dependencies.get(ireq.name, [])\n        if required_by:\n            line = line.ljust(24)\n            annotation = ', '.join(sorted(required_by))\n            line += comment('  # via ' + annotation)\n        return line\n", "path": "piptools/writer.py"}], "after_files": [{"content": "import os\nfrom os.path import basename\n\nfrom ._compat import ExitStack\nfrom .click import unstyle\nfrom .io import AtomicSaver\nfrom .logging import log\nfrom .utils import comment, format_requirement\n\n\nclass OutputWriter(object):\n    def __init__(self, src_file, dst_file, dry_run, emit_header, emit_index, annotate,\n                 default_index_url, index_urls):\n        self.src_file = src_file\n        self.dst_file = dst_file\n        self.dry_run = dry_run\n        self.emit_header = emit_header\n        self.emit_index = emit_index\n        self.annotate = annotate\n        self.default_index_url = default_index_url\n        self.index_urls = index_urls\n\n    def _sort_key(self, ireq):\n        return (not ireq.editable, str(ireq.req).lower())\n\n    def write_header(self):\n        if self.emit_header:\n            yield comment('#')\n            yield comment('# This file is autogenerated by pip-compile')\n            yield comment('# Make changes in {}, then run this to update:'.format(basename(self.src_file)))\n            yield comment('#')\n            args = ''\n            if not self.emit_index:\n                args += '--no-index '\n            if not self.annotate:\n                args += '--no-annotate '\n            yield comment('#    pip-compile {args}{filename}'.format(\n                          args=args,\n                          filename=basename(self.src_file)))\n            yield comment('#')\n\n    def write_index_options(self):\n        if self.emit_index:\n            emitted = False\n            for index, index_url in enumerate(self.index_urls):\n                if index_url.rstrip('/') == self.default_index_url:\n                    continue\n                flag = '--index-url' if index == 0 else '--extra-index-url'\n                yield '{} {}'.format(flag, index_url)\n                emitted = True\n            if emitted:\n                yield ''  # extra line of whitespace\n\n    def _iter_lines(self, results, reverse_dependencies, primary_packages):\n        for line in self.write_header():\n            yield line\n        for line in self.write_index_options():\n            yield line\n\n        UNSAFE_PACKAGES = {'setuptools', 'distribute', 'pip'}\n        unsafe_packages = {r for r in results if r.name in UNSAFE_PACKAGES}\n        packages = {r for r in results if r.name not in UNSAFE_PACKAGES}\n\n        packages = sorted(packages, key=self._sort_key)\n        unsafe_packages = sorted(unsafe_packages, key=self._sort_key)\n\n        for ireq in packages:\n            line = self._format_requirement(ireq, reverse_dependencies, primary_packages)\n            yield line\n\n        if unsafe_packages:\n            yield ''\n            yield comment('# The following packages are commented out because they are')\n            yield comment('# considered to be unsafe in a requirements file:')\n\n            for ireq in unsafe_packages:\n                line = self._format_requirement(ireq, reverse_dependencies, primary_packages, include_specifier=False)\n                yield comment('# ' + line)\n\n    def write(self, results, reverse_dependencies, primary_packages):\n        with ExitStack() as stack:\n            f = None\n            if not self.dry_run:\n                f = stack.enter_context(AtomicSaver(self.dst_file))\n\n            for line in self._iter_lines(results, reverse_dependencies, primary_packages):\n                log.info(line)\n                if f:\n                    f.write(unstyle(line).encode('utf-8'))\n                    f.write(os.linesep.encode('utf-8'))\n\n    def _format_requirement(self, ireq, reverse_dependencies, primary_packages, include_specifier=True):\n        line = format_requirement(ireq, include_specifier=include_specifier)\n        if not self.annotate or ireq.name in primary_packages:\n            return line\n\n        # Annotate what packages this package is required by\n        required_by = reverse_dependencies.get(ireq.name.lower(), [])\n        if required_by:\n            line = line.ljust(24)\n            annotation = ', '.join(sorted(required_by))\n            line += comment('  # via ' + annotation)\n        return line\n", "path": "piptools/writer.py"}]}