Skip to content

Commit

Permalink
Normalize post releases like pre-releases and development releases
Browse files Browse the repository at this point in the history
  • Loading branch information
dstufft committed Jul 3, 2014
1 parent 8fc910b commit 77eee20
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 10 deletions.
33 changes: 23 additions & 10 deletions packaging/version.py
Expand Up @@ -45,11 +45,15 @@ class Version(object):
(?:(?P<epoch>[0-9]+):)? # epoch
(?P<release>[0-9]+(?:\.[0-9]+)*) # release segment
(?P<pre> # pre release
(?:[-\.])?
[-\.]?
(?P<pre_l>(a|b|c|rc|alpha|beta)) # - pre-release letter
(?P<pre_n>[0-9]+)? # - pre-release number
)?
(?:\.post(?P<post>[0-9]+))? # post release
(?P<post> # post release
[-\.]?
(?P<post_l>post)
(?P<post_n>[0-9]+)?
)?
(?P<dev> # dev release
[-\.]?
(?P<dev_l>dev)
Expand All @@ -72,9 +76,18 @@ def __init__(self, version):
self._version = _Version(
epoch=int(match.group("epoch")) if match.group("epoch") else 0,
release=_parse_release_version(match.group("release")),
pre=_parse_pre_version(match.group("pre_l"), match.group("pre_n")),
post=int(match.group("post")) if match.group("post") else None,
dev=_parse_pre_version(match.group("dev_l"), match.group("dev_n")),
pre=_parse_letter_version(
match.group("pre_l"),
match.group("pre_n"),
),
post=_parse_letter_version(
match.group("post_l"),
match.group("post_n"),
),
dev=_parse_letter_version(
match.group("dev_l"),
match.group("dev_n"),
),
local=_parse_local_version(match.group("local")),
)

Expand Down Expand Up @@ -107,7 +120,7 @@ def __str__(self):

# Post-release
if self._version.post is not None:
parts.append(".post{0}".format(self._version.post))
parts.append(".post{0}".format(self._version.post[1]))

# Development release
if self._version.dev is not None:
Expand Down Expand Up @@ -179,7 +192,7 @@ def _parse_release_version(part):
)


def _parse_pre_version(letter, number):
def _parse_letter_version(letter, number):
if letter:
# We consider there to be an implicit 0 in a pre-release if there is
# not a numeral associated with it.
Expand Down Expand Up @@ -278,7 +291,7 @@ class Specifier(object):
(?:[0-9]+:)? # epoch
[0-9]+(?:\.[0-9]+)* # release
(?:[-\.]?(a|b|c|rc|alpha|beta)[0-9]*)? # pre release
(?:\.post[0-9]+)? # post release
(?:[-\.]?post[0-9]*)? # post release
# You cannot use a wild card and a dev or local version
# together so group them with a | and make them optional.
Expand All @@ -298,7 +311,7 @@ class Specifier(object):
(?:[0-9]+:)? # epoch
[0-9]+(?:\.[0-9]+)+ # release (We have a + instead of a *)
(?:[-\.]?(a|b|c|rc|alpha|beta)[0-9]*)? # pre release
(?:\.post[0-9]+)? # post release
(?:[-\.]?post[0-9]*)? # post release
(?:[-\.]?dev[0-9]*)? # dev release
)
|
Expand All @@ -314,7 +327,7 @@ class Specifier(object):
(?:[0-9]+:)? # epoch
[0-9]+(?:\.[0-9]+)* # release
(?:[-\.]?(a|b|c|rc|alpha|beta)[0-9]*)? # pre release
(?:\.post[0-9]+)? # post release
(?:[-\.]?post[0-9]*)? # post release
(?:[-\.]?dev[0-9]*)? # dev release
)
)
Expand Down
30 changes: 30 additions & 0 deletions tests/test_version.py
Expand Up @@ -153,6 +153,21 @@ def test_invalid_versions(self, version):
("1.0-RC", "1.0c0"),
("1.0-RC1", "1.0c1"),
# Various post release incarnations
("1.0post", "1.0.post0"),
("1.0.post", "1.0.post0"),
("1.0post1", "1.0.post1"),
("1.0post", "1.0.post0"),
("1.0-post", "1.0.post0"),
("1.0-post1", "1.0.post1"),
("1.0POST", "1.0.post0"),
("1.0.POST", "1.0.post0"),
("1.0POST1", "1.0.post1"),
("1.0POST", "1.0.post0"),
("1.0.POST1", "1.0.post1"),
("1.0-POST", "1.0.post0"),
("1.0-POST1", "1.0.post1"),
# Local version case insensitivity
("1.0+AbC", "1.0+abc"),
Expand Down Expand Up @@ -621,6 +636,21 @@ def test_specifiers_invalid(self, specifier):
"1.0-RC",
"1.0-RC1",
# Various post release incarnations
"1.0post",
"1.0.post",
"1.0post1",
"1.0post",
"1.0-post",
"1.0-post1",
"1.0POST",
"1.0.POST",
"1.0POST1",
"1.0POST",
"1.0.POST1",
"1.0-POST",
"1.0-POST1",
# Local version case insensitivity
"1.0+AbC"
Expand Down

0 comments on commit 77eee20

Please sign in to comment.