Repository: pypa/pip

Issue:
Egg name on git URLs is not checked for accuracy
In a requirements file, I have a package that is installed like this:

```
-e git+https://github.com/pmitros/django-pyfs.git@d175715e0fe3367ec0f1ee429c242d603f6e8b10#egg=djpyfs
```

This installs fine, but is wrong: the kit name is "django-pyfs", not "djpyfs".  Once installed, I cannot uninstall it with "pip uninstall -r requirements.txt" because of the incorrect name.  Pip should refuse to install the package if the name is given incorrectly.



Discussion:
ned, if it could do that, then it wouldn't need you to tell it the name....

@tritium21 I know it doesn't know that before the installation, but it knows it after the installation.  If it can error on "pip uninstall" then it can error at the very end of "pip install".

So looking this up, it's only ever used for dependency resolution, if the docs are to be believed.  I think you found an edge case where you would provide a name, but not have other packages depend on it?

@tritium21 This is the case: I have a requirements.txt file that lists github repos I need, and they are not mentioned elsewhere.


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
@@ -30,7 +30,7 @@
     display_path, rmtree, ask_path_exists, backup_dir, is_installable_dir,
     dist_in_usersite, dist_in_site_packages, egg_link_path,
     call_subprocess, read_text_file, FakeFile, _make_build_dir, ensure_dir,
-    get_installed_version
+    get_installed_version, canonicalize_name
 )
 from pip.utils.logging import indent_log
 from pip.req.req_uninstall import UninstallPathSet
@@ -421,6 +421,14 @@ def run_egg_info(self):
                     self.pkg_info()["Version"],
                 ]))
             self._correct_build_location()
+        else:
+            metadata_name = canonicalize_name(self.pkg_info()["Name"])
+            if canonicalize_name(self.req.project_name) != metadata_name:
+                raise InstallationError(
+                    'Running setup.py (path:%s) egg_info for package %s '
+                    'produced metadata for project name %s' % (
+                        self.setup_py, self.name, metadata_name)
+                )
 
     # FIXME: This is a lame hack, entirely for PasteScript which has
     # a self-provided entry point that causes this awkwardness


Test patch:
diff --git a/tests/functional/test_install.py b/tests/functional/test_install.py
--- a/tests/functional/test_install.py
+++ b/tests/functional/test_install.py
@@ -775,3 +775,18 @@ def test_install_no_binary_disables_cached_wheels(script, data):
     assert "Running setup.py bdist_wheel for upper" not in str(res), str(res)
     # Must have used source, not a cached wheel to install upper.
     assert "Running setup.py install for upper" in str(res), str(res)
+
+
+def test_install_editable_with_wrong_egg_name(script):
+    script.scratch_path.join("pkga").mkdir()
+    pkga_path = script.scratch_path / 'pkga'
+    pkga_path.join("setup.py").write(textwrap.dedent("""
+        from setuptools import setup
+        setup(name='pkga',
+              version='0.1')
+    """))
+    result = script.pip(
+        'install', '--editable', 'file://%s#egg=pkgb' % pkga_path,
+        expect_error=True)
+    assert ("egg_info for package pkgb produced metadata "
+            "for project name pkga") in result.stderr