We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Extras not propagated into requirements.txt after insertion
Extras, in this context, are specific functional extensions to a particular package.

This is similar to #154 but differs because this triggers when adding an extra to an existing requirement.

The cached result appears to prevent appropriate detection that the extra was added.

##### Steps to replicate

1. Create a `requirements.in` as follows:
  ```text
pip-tools
hypothesis
   ```
2. Run `pip-compile` from the command line.
3. Edit the requirements.in file to the following:
  ```text
pip-tools
hypothesis[django]
  ```
4. Re-run `pip-compile` from the command line.
3. Examine `requirements.txt`

##### Expected result

```text
#
# This file is autogenerated by pip-compile
# To update, run:
#
#    pip-compile --output-file reqs.txt reqs.in
#
click==6.6                # via pip-tools
django==1.10.3            # via hypothesis
fake-factory==0.7.2       # via hypothesis
first==2.0.1              # via pip-tools
hypothesis[django]==3.6.0
pip-tools==1.7.0
python-dateutil==2.6.0    # via fake-factory
pytz==2016.7              # via hypothesis
six==1.10.0               # via fake-factory, pip-tools, python-dateutil
```

##### Actual result

```text
#
# This file is autogenerated by pip-compile
# To update, run:
#
#    pip-compile --output-file reqs.txt reqs.in
#
click==6.6                # via pip-tools
first==2.0.1              # via pip-tools
hypothesis==3.6.0
pip-tools==1.7.0
six==1.10.0               # via pip-tools
```

##### Workaround

Simply deleting the existing `requirements.txt` file and installing from scratch appears to work, but shouldn't be a necessary part of the pip-tools workflow.

--- 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/repositories/local.py`
Content:
```
1 # coding: utf-8
2 from __future__ import (absolute_import, division, print_function,
3                         unicode_literals)
4 
5 from piptools.utils import key_from_req
6 from .base import BaseRepository
7 
8 
9 def ireq_satisfied_by_existing_pin(ireq, existing_pin):
10     """
11     Return True if the given InstallationRequirement is satisfied by the
12     previously encountered version pin.
13     """
14     if hasattr(existing_pin.req, 'specs'):
15         # pip < 8.1.2
16         version = existing_pin.req.specs[0][1]
17         return version in ireq.req
18     else:
19         # pip >= 8.1.2
20         version = next(iter(existing_pin.req.specifier)).version
21         return version in ireq.req.specifier
22 
23 
24 class LocalRequirementsRepository(BaseRepository):
25     """
26     The LocalRequirementsRepository proxied the _real_ repository by first
27     checking if a requirement can be satisfied by existing pins (i.e. the
28     result of a previous compile step).
29 
30     In effect, if a requirement can be satisfied with a version pinned in the
31     requirements file, we prefer that version over the best match found in
32     PyPI.  This keeps updates to the requirements.txt down to a minimum.
33     """
34     def __init__(self, existing_pins, proxied_repository):
35         self.repository = proxied_repository
36         self.existing_pins = existing_pins
37 
38     @property
39     def finder(self):
40         return self.repository.finder
41 
42     @property
43     def session(self):
44         return self.repository.session
45 
46     @property
47     def DEFAULT_INDEX_URL(self):
48         return self.repository.DEFAULT_INDEX_URL
49 
50     def clear_caches(self):
51         self.repository.clear_caches()
52 
53     def freshen_build_caches(self):
54         self.repository.freshen_build_caches()
55 
56     def find_best_match(self, ireq, prereleases=None):
57         key = key_from_req(ireq.req)
58         existing_pin = self.existing_pins.get(key)
59         if existing_pin and ireq_satisfied_by_existing_pin(ireq, existing_pin):
60             return existing_pin
61         else:
62             return self.repository.find_best_match(ireq, prereleases)
63 
64     def get_dependencies(self, ireq):
65         return self.repository.get_dependencies(ireq)
66
```
--- 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()

```

diff --git a/piptools/repositories/local.py b/piptools/repositories/local.py
--- a/piptools/repositories/local.py
+++ b/piptools/repositories/local.py
@@ -2,7 +2,7 @@
 from __future__ import (absolute_import, division, print_function,
                         unicode_literals)
 
-from piptools.utils import key_from_req
+from piptools.utils import as_tuple, key_from_req, make_install_requirement
 from .base import BaseRepository
 
 
@@ -57,7 +57,10 @@
         key = key_from_req(ireq.req)
         existing_pin = self.existing_pins.get(key)
         if existing_pin and ireq_satisfied_by_existing_pin(ireq, existing_pin):
-            return existing_pin
+            project, version, _ = as_tuple(existing_pin)
+            return make_install_requirement(
+                project, version, ireq.extras
+            )
         else:
             return self.repository.find_best_match(ireq, prereleases)

{"golden_diff": "diff --git a/piptools/repositories/local.py b/piptools/repositories/local.py\n--- a/piptools/repositories/local.py\n+++ b/piptools/repositories/local.py\n@@ -2,7 +2,7 @@\n from __future__ import (absolute_import, division, print_function,\n                         unicode_literals)\n \n-from piptools.utils import key_from_req\n+from piptools.utils import as_tuple, key_from_req, make_install_requirement\n from .base import BaseRepository\n \n \n@@ -57,7 +57,10 @@\n         key = key_from_req(ireq.req)\n         existing_pin = self.existing_pins.get(key)\n         if existing_pin and ireq_satisfied_by_existing_pin(ireq, existing_pin):\n-            return existing_pin\n+            project, version, _ = as_tuple(existing_pin)\n+            return make_install_requirement(\n+                project, version, ireq.extras\n+            )\n         else:\n             return self.repository.find_best_match(ireq, prereleases)\n", "issue": "Extras not propagated into requirements.txt after insertion\nExtras, in this context, are specific functional extensions to a particular package.\r\n\r\nThis is similar to #154 but differs because this triggers when adding an extra to an existing requirement.\r\n\r\nThe cached result appears to prevent appropriate detection that the extra was added.\r\n\r\n##### Steps to replicate\r\n\r\n1. Create a `requirements.in` as follows:\r\n  ```text\r\npip-tools\r\nhypothesis\r\n   ```\r\n2. Run `pip-compile` from the command line.\r\n3. Edit the requirements.in file to the following:\r\n  ```text\r\npip-tools\r\nhypothesis[django]\r\n  ```\r\n4. Re-run `pip-compile` from the command line.\r\n3. Examine `requirements.txt`\r\n\r\n##### Expected result\r\n\r\n```text\r\n#\r\n# This file is autogenerated by pip-compile\r\n# To update, run:\r\n#\r\n#    pip-compile --output-file reqs.txt reqs.in\r\n#\r\nclick==6.6                # via pip-tools\r\ndjango==1.10.3            # via hypothesis\r\nfake-factory==0.7.2       # via hypothesis\r\nfirst==2.0.1              # via pip-tools\r\nhypothesis[django]==3.6.0\r\npip-tools==1.7.0\r\npython-dateutil==2.6.0    # via fake-factory\r\npytz==2016.7              # via hypothesis\r\nsix==1.10.0               # via fake-factory, pip-tools, python-dateutil\r\n```\r\n\r\n##### Actual result\r\n\r\n```text\r\n#\r\n# This file is autogenerated by pip-compile\r\n# To update, run:\r\n#\r\n#    pip-compile --output-file reqs.txt reqs.in\r\n#\r\nclick==6.6                # via pip-tools\r\nfirst==2.0.1              # via pip-tools\r\nhypothesis==3.6.0\r\npip-tools==1.7.0\r\nsix==1.10.0               # via pip-tools\r\n```\r\n\r\n##### Workaround\r\n\r\nSimply deleting the existing `requirements.txt` file and installing from scratch appears to work, but shouldn't be a necessary part of the pip-tools workflow.\n", "before_files": [{"content": "# coding: utf-8\nfrom __future__ import (absolute_import, division, print_function,\n                        unicode_literals)\n\nfrom piptools.utils import key_from_req\nfrom .base import BaseRepository\n\n\ndef ireq_satisfied_by_existing_pin(ireq, existing_pin):\n    \"\"\"\n    Return True if the given InstallationRequirement is satisfied by the\n    previously encountered version pin.\n    \"\"\"\n    if hasattr(existing_pin.req, 'specs'):\n        # pip < 8.1.2\n        version = existing_pin.req.specs[0][1]\n        return version in ireq.req\n    else:\n        # pip >= 8.1.2\n        version = next(iter(existing_pin.req.specifier)).version\n        return version in ireq.req.specifier\n\n\nclass LocalRequirementsRepository(BaseRepository):\n    \"\"\"\n    The LocalRequirementsRepository proxied the _real_ repository by first\n    checking if a requirement can be satisfied by existing pins (i.e. the\n    result of a previous compile step).\n\n    In effect, if a requirement can be satisfied with a version pinned in the\n    requirements file, we prefer that version over the best match found in\n    PyPI.  This keeps updates to the requirements.txt down to a minimum.\n    \"\"\"\n    def __init__(self, existing_pins, proxied_repository):\n        self.repository = proxied_repository\n        self.existing_pins = existing_pins\n\n    @property\n    def finder(self):\n        return self.repository.finder\n\n    @property\n    def session(self):\n        return self.repository.session\n\n    @property\n    def DEFAULT_INDEX_URL(self):\n        return self.repository.DEFAULT_INDEX_URL\n\n    def clear_caches(self):\n        self.repository.clear_caches()\n\n    def freshen_build_caches(self):\n        self.repository.freshen_build_caches()\n\n    def find_best_match(self, ireq, prereleases=None):\n        key = key_from_req(ireq.req)\n        existing_pin = self.existing_pins.get(key)\n        if existing_pin and ireq_satisfied_by_existing_pin(ireq, existing_pin):\n            return existing_pin\n        else:\n            return self.repository.find_best_match(ireq, prereleases)\n\n    def get_dependencies(self, ireq):\n        return self.repository.get_dependencies(ireq)\n", "path": "piptools/repositories/local.py"}], "after_files": [{"content": "# coding: utf-8\nfrom __future__ import (absolute_import, division, print_function,\n                        unicode_literals)\n\nfrom piptools.utils import as_tuple, key_from_req, make_install_requirement\nfrom .base import BaseRepository\n\n\ndef ireq_satisfied_by_existing_pin(ireq, existing_pin):\n    \"\"\"\n    Return True if the given InstallationRequirement is satisfied by the\n    previously encountered version pin.\n    \"\"\"\n    if hasattr(existing_pin.req, 'specs'):\n        # pip < 8.1.2\n        version = existing_pin.req.specs[0][1]\n        return version in ireq.req\n    else:\n        # pip >= 8.1.2\n        version = next(iter(existing_pin.req.specifier)).version\n        return version in ireq.req.specifier\n\n\nclass LocalRequirementsRepository(BaseRepository):\n    \"\"\"\n    The LocalRequirementsRepository proxied the _real_ repository by first\n    checking if a requirement can be satisfied by existing pins (i.e. the\n    result of a previous compile step).\n\n    In effect, if a requirement can be satisfied with a version pinned in the\n    requirements file, we prefer that version over the best match found in\n    PyPI.  This keeps updates to the requirements.txt down to a minimum.\n    \"\"\"\n    def __init__(self, existing_pins, proxied_repository):\n        self.repository = proxied_repository\n        self.existing_pins = existing_pins\n\n    @property\n    def finder(self):\n        return self.repository.finder\n\n    @property\n    def session(self):\n        return self.repository.session\n\n    @property\n    def DEFAULT_INDEX_URL(self):\n        return self.repository.DEFAULT_INDEX_URL\n\n    def clear_caches(self):\n        self.repository.clear_caches()\n\n    def freshen_build_caches(self):\n        self.repository.freshen_build_caches()\n\n    def find_best_match(self, ireq, prereleases=None):\n        key = key_from_req(ireq.req)\n        existing_pin = self.existing_pins.get(key)\n        if existing_pin and ireq_satisfied_by_existing_pin(ireq, existing_pin):\n            project, version, _ = as_tuple(existing_pin)\n            return make_install_requirement(\n                project, version, ireq.extras\n            )\n        else:\n            return self.repository.find_best_match(ireq, prereleases)\n\n    def get_dependencies(self, ireq):\n        return self.repository.get_dependencies(ireq)\n", "path": "piptools/repositories/local.py"}]}