Repository: pypa/pip

Issue:
query installed requirements for extras
Fixes an issue where egg_info('requires.txt') does not exist for packages installed from wheels.

Affected use case:

```
pip install pkg (from wheel)
pip install pkg[extra]
```

Included test fails prior to this PR.

Closes #1885



Discussion:

Resolving patch:
diff --git a/pip/req/req_install.py b/pip/req/req_install.py
--- a/pip/req/req_install.py
+++ b/pip/req/req_install.py
@@ -451,6 +451,10 @@ def pkg_info(self):
     _requirements_section_re = re.compile(r'\[(.*?)\]')
 
     def requirements(self, extras=()):
+        if self.satisfied_by:
+            for r in self.satisfied_by.requires(extras):
+                yield str(r)
+            return
         in_extra = None
         for line in self.egg_info_lines('requires.txt'):
             match = self._requirements_section_re.match(line.lower())


Test patch:
diff --git a/tests/data/packages/README.txt b/tests/data/packages/README.txt
--- a/tests/data/packages/README.txt
+++ b/tests/data/packages/README.txt
@@ -84,6 +84,8 @@ meta-1.0-py2.py3-none-any.whl
 --------------------------------------------------
 Is an empty package which install_requires the simple and simple2 packages.
 
-
+requires_simple_extra-0.1-py2.py3-none-any.whl
+----------------------------------------------
+requires_simple_extra[extra] requires simple==1.0
 
 
diff --git a/tests/data/packages/requires_simple_extra-0.1-py2.py3-none-any.whl b/tests/data/packages/requires_simple_extra-0.1-py2.py3-none-any.whl
new file mode 100644
Binary files /dev/null and b/tests/data/packages/requires_simple_extra-0.1-py2.py3-none-any.whl differ
diff --git a/tests/data/src/requires_simple_extra/requires_simple_extra.py b/tests/data/src/requires_simple_extra/requires_simple_extra.py
new file mode 100644
diff --git a/tests/data/src/requires_simple_extra/setup.cfg b/tests/data/src/requires_simple_extra/setup.cfg
new file mode 100644
--- /dev/null
+++ b/tests/data/src/requires_simple_extra/setup.cfg
@@ -0,0 +1,2 @@
+[wheel]
+universal=1
diff --git a/tests/data/src/requires_simple_extra/setup.py b/tests/data/src/requires_simple_extra/setup.py
new file mode 100644
--- /dev/null
+++ b/tests/data/src/requires_simple_extra/setup.py
@@ -0,0 +1,9 @@
+from setuptools import setup
+
+setup(name='requires_simple_extra',
+      version='0.1',
+      py_modules = ['requires_simple_extra'],
+      extras_require = {
+          'extra' : ['simple==1.0']
+      }
+)
\ No newline at end of file
diff --git a/tests/functional/test_install_extras.py b/tests/functional/test_install_extras.py
--- a/tests/functional/test_install_extras.py
+++ b/tests/functional/test_install_extras.py
@@ -12,6 +12,25 @@ def test_simple_extras_install_from_pypi(script):
     assert initools_folder in result.files_created, result.files_created
 
 
+def test_extras_after_wheel(script, data):
+    """
+    Test installing a package with extras after installing from a wheel.
+    """
+    simple = script.site_packages / 'simple'
+
+    no_extra = script.pip(
+        'install', '--no-index', '-f', data.find_links,
+        'requires_simple_extra', expect_stderr=True,
+    )
+    assert simple not in no_extra.files_created, no_extra.files_created
+
+    extra = script.pip(
+        'install', '--no-index', '-f', data.find_links,
+        'requires_simple_extra[extra]', expect_stderr=True,
+    )
+    assert simple in extra.files_created, extra.files_created
+
+
 def test_no_extras_uninstall(script):
     """
     No extras dependency gets uninstalled when the root package is uninstalled