(epoch, release, pre, post, dev, local)
| 434 | |
| 435 | |
| 436 | def _cmpkey(epoch, release, pre, post, dev, local): |
| 437 | # When we compare a release version, we want to compare it with all of the |
| 438 | # trailing zeros removed. So we'll use a reverse the list, drop all the now |
| 439 | # leading zeros until we come to something non-zero, then take the rest, |
| 440 | # re-reverse it back into the correct order, and make it a tuple and use |
| 441 | # that for our sorting key. |
| 442 | release = tuple( |
| 443 | reversed(list( |
| 444 | itertools.dropwhile( |
| 445 | lambda x: x == 0, |
| 446 | reversed(release), |
| 447 | ) |
| 448 | )) |
| 449 | ) |
| 450 | |
| 451 | # We need to "trick" the sorting algorithm to put 1.0.dev0 before 1.0a0. |
| 452 | # We'll do this by abusing the pre-segment, but we _only_ want to do this |
| 453 | # if there is no pre- or a post-segment. If we have one of those, then |
| 454 | # the normal sorting rules will handle this case correctly. |
| 455 | if pre is None and post is None and dev is not None: |
| 456 | pre = -Infinity |
| 457 | # Versions without a pre-release (except as noted above) should sort after |
| 458 | # those with one. |
| 459 | elif pre is None: |
| 460 | pre = Infinity |
| 461 | |
| 462 | # Versions without a post-segment should sort before those with one. |
| 463 | if post is None: |
| 464 | post = -Infinity |
| 465 | |
| 466 | # Versions without a development segment should sort after those with one. |
| 467 | if dev is None: |
| 468 | dev = Infinity |
| 469 | |
| 470 | if local is None: |
| 471 | # Versions without a local segment should sort before those with one. |
| 472 | local = -Infinity |
| 473 | else: |
| 474 | # Versions with a local segment need that segment parsed to implement |
| 475 | # the sorting rules in PEP440. |
| 476 | # - Alphanumeric segments sort before numeric segments |
| 477 | # - Alphanumeric segments sort lexicographically |
| 478 | # - Numeric segments sort numerically |
| 479 | # - Shorter versions sort before longer versions when the prefixes |
| 480 | # match exactly |
| 481 | local = tuple( |
| 482 | (i, "") if isinstance(i, int) else (-Infinity, i) |
| 483 | for i in local |
| 484 | ) |
| 485 | |
| 486 | return epoch, release, pre, post, dev, local |
no outgoing calls
no test coverage detected
searching dependent graphs…