Fix version number recognition heuristics
The regexp was wrong, for example it matched "2.20x" but failed to match "3.1". Some test cases: >>> def f(title): ... version_number = re.search(_version_number_re, title) ... if version_number: ... return not re.search(_incomplete_version_number_re, ... version_number.group(0)) ... else: ... return False ... >>> [(s, f(s.encode('ascii'))) for s in ['foo', 'foo 3', 'foo 3.', 'foo 3.1', 'foo 3.14', 'foo 3.2.1', 'foo 3.2.1alpha', 'foo 3.1.a', 'foo 3.a', 'foo 3.x.1']] [('foo', False), ('foo 3', False), ('foo 3.', False), ('foo 3.1', True), ('foo 3.14', True), ('foo 3.2.1', True), ('foo 3.2.1alpha', True), ('foo 3.1.a', False), ('foo 3.a', False), ('foo 3.x.1', False)]
This commit is contained in:
parent
a26079613a
commit
afc9db8bb7
1 changed files with 9 additions and 4 deletions
|
@ -84,9 +84,10 @@ class ChangeLog:
|
|||
return level, line[level:].strip()
|
||||
|
||||
# Only accept dotted version numbers (e.g. "3.1", not "3").
|
||||
# Refuse ".x" in a version number: this indicates a version that is
|
||||
# not yet released.
|
||||
_version_number_re = re.compile(br'[0-9]\.[0-9][0-9.]+([^.]|\.[^0-9x])')
|
||||
# Refuse ".x" in a version number where x is a letter: this indicates
|
||||
# a version that is not yet released. Something like "3.1a" is accepted.
|
||||
_version_number_re = re.compile(br'[0-9]+\.[0-9A-Za-z.]+')
|
||||
_incomplete_version_number_re = re.compile(br'.*\.[A-Za-z]')
|
||||
|
||||
def section_is_released_version(self, title):
|
||||
"""Whether this section is for a released version.
|
||||
|
@ -98,7 +99,11 @@ class ChangeLog:
|
|||
# that follows a particular pattern. These criteria may be revised
|
||||
# as needed in future versions of this script.
|
||||
version_number = re.search(self._version_number_re, title)
|
||||
return bool(version_number)
|
||||
if version_number:
|
||||
return not re.search(self._incomplete_version_number_re,
|
||||
version_number.group(0))
|
||||
else:
|
||||
return False
|
||||
|
||||
def unreleased_version_title(self):
|
||||
"""The title to use if creating a new section for an unreleased version."""
|
||||
|
|
Loading…
Reference in a new issue