pypa/packaging — pull request #5 by dstufft (2014-09-05 23:41:20+00:00)
Title: Be more forgiving about invalid versions

* Allow sorting ``LegacyVersion`` and ``Version`` instances.
* Allow ``Specifier()`` to match anything, even ``LegacyVersion``s

This PR stems from real world experience trying to integrate with setuptools. While being strict like this works really well when you're attempting to pick a version to install it does not however work when you're trying to apply them to a list of things which are already installed on the filesystem or when you *need* to sort a list of versions and you cannot filter (such as PyPI).

In this PR a ``LegacyVersion`` will *always* sort as less than a ``Version``, no matter what their values are. This will ensure that ``pip install foo`` does not get a non PEP 440 version unless no other options are available.

If someone wishes to filter out instances of ``LegacyVersion`` which previously this library required, they can still do by simply doing:

```python
from packaging.version import Version, LegacyVersion, InvalidVersion

def parse(version):
try:
return Version(version)
except InvalidVersion:
return LegacyVersion(version)

versions = [
v for v in (parse(v) for v in ["dog", "cat", "1.0", "2.0"])
if isinstance(v, Version)
]
```