Repository: pypa/pip

Issue:
Installing an invalid/legacy version breaks `pip list` and `pip freeze`
Using either pypa pip develop or the branch from pull request #2205.

```
$ pip list
pip (6.0.dev1, /Users/mauritsvanrees/community/pip)
setuptools (8.0.4)
$ pip install -U --trusted-host pypi.zestsoftware.nl -f http://pypi.zestsoftware.nl/public/ Babel==2.0a1.zest.20141021
...
$ pip list
/Users/mauritsvanrees/community/pip/pip/_vendor/pkg_resources.py:2425: RuntimeWarning: 'Babel (2.0a1.zest.20141021)' is being parsed as a legacy, non PEP 440, version. You may find odd behavior and sort order. In particular it will be sorted as less than 0.0. It is recommend to migrate to PEP 440 compatible versions.
  RuntimeWarning,
Exception:
Traceback (most recent call last):
  File "/Users/mauritsvanrees/community/pip/pip/basecommand.py", line 210, in main
    status = self.run(options, args)
  File "/Users/mauritsvanrees/community/pip/pip/commands/list.py", line 100, in run
    self.run_listing(options)
  File "/Users/mauritsvanrees/community/pip/pip/commands/list.py", line 174, in run_listing
    self.output_package_listing(installed_packages)
  File "/Users/mauritsvanrees/community/pip/pip/commands/list.py", line 190, in output_package_listing
    if dist_is_editable(dist):
  File "/Users/mauritsvanrees/community/pip/pip/utils/__init__.py", line 368, in dist_is_editable
    req = FrozenRequirement.from_dist(dist, [])
  File "/Users/mauritsvanrees/community/pip/pip/__init__.py", line 256, in from_dist
    assert len(specs) == 1 and specs[0][0] == '=='
AssertionError
```

The specs here are: `[('===', '2.0a1.zest.20141021')]`.

Same problem with `pip freeze`:

```
$ pip freeze
/Users/mauritsvanrees/community/pip/pip/_vendor/pkg_resources.py:2425: RuntimeWarning: 'Babel (2.0a1.zest.20141021)' is being parsed as a legacy, non PEP 440, version. You may find odd behavior and sort order. In particular it will be sorted as less than 0.0. It is recommend to migrate to PEP 440 compatible versions.
  RuntimeWarning,
Exception:
Traceback (most recent call last):
  File "/Users/mauritsvanrees/community/pip/pip/basecommand.py", line 210, in main
    status = self.run(options, args)
  File "/Users/mauritsvanrees/community/pip/pip/commands/freeze.py", line 104, in run
    find_tags=find_tags,
  File "/Users/mauritsvanrees/community/pip/pip/__init__.py", line 256, in from_dist
    assert len(specs) == 1 and specs[0][0] == '=='
AssertionError
```

Changing the `assert` line like this fixes it for me:

```
            assert len(specs) == 1 and (specs[0][0] == '==' or specs[0][0] == '===')
```

Note: in some cases pip install does not install the exact version that you requested.  When you request version `2.0a1-zest.20141216` (either with `==` or `===`, maybe needing #2205), you actually get the also available version `2.0a1+zest.20141216`.  In that case `pip list` and `pip install` work fine, because that is a valid non-legacy version.



Discussion:

Resolving patch:
diff --git a/pip/__init__.py b/pip/__init__.py
--- a/pip/__init__.py
+++ b/pip/__init__.py
@@ -253,7 +253,7 @@ def from_dist(cls, dist, dependency_links, find_tags=False):
             editable = False
             req = dist.as_requirement()
             specs = req.specs
-            assert len(specs) == 1 and specs[0][0] == '=='
+            assert len(specs) == 1 and specs[0][0] in ["==", "==="]
             version = specs[0][1]
             ver_match = cls._rev_re.search(version)
             date_match = cls._date_re.search(version)


Test patch: