[Python-checkins] distutils2: Removed the trailing zero wiping (#14264)
tarek.ziade
python-checkins at python.org
Mon Mar 12 22:07:13 CET 2012
http://hg.python.org/distutils2/rev/1e0ca4594a2a
changeset: 1293:1e0ca4594a2a
user: Tarek Ziade <tarek at ziade.org>
date: Mon Mar 12 14:06:59 2012 -0700
summary:
Removed the trailing zero wiping (#14264)
files:
distutils2/pypi/simple.py | 4 ++--
distutils2/tests/test_version.py | 10 ++++++++--
distutils2/version.py | 18 ++++++++++--------
3 files changed, 20 insertions(+), 12 deletions(-)
diff --git a/distutils2/pypi/simple.py b/distutils2/pypi/simple.py
--- a/distutils2/pypi/simple.py
+++ b/distutils2/pypi/simple.py
@@ -198,8 +198,8 @@
def get_release(self, requirements, prefer_final=None):
"""Return only one release that fulfill the given requirements"""
predicate = get_version_predicate(requirements)
- release = self.get_releases(predicate, prefer_final)\
- .get_last(predicate)
+ releases = self.get_releases(predicate, prefer_final)
+ release = releases.get_last(predicate)
if not release:
raise ReleaseNotFound("No release matches the given criterias")
return release
diff --git a/distutils2/tests/test_version.py b/distutils2/tests/test_version.py
--- a/distutils2/tests/test_version.py
+++ b/distutils2/tests/test_version.py
@@ -18,8 +18,8 @@
(V('1.2c4'), '1.2c4'),
(V('4.17rc2'), '4.17rc2'),
(V('1.2.3.4'), '1.2.3.4'),
- (V('1.2.3.4.0b3'), '1.2.3.4b3'),
- (V('1.2.0.0.0'), '1.2'),
+ (V('1.2.3.4.0b3', drop_trailing_zeros=True), '1.2.3.4b3'),
+ (V('1.2.0.0.0', drop_trailing_zeros=True), '1.2'),
(V('1.0.dev345'), '1.0.dev345'),
(V('1.0.post456.dev623'), '1.0.post456.dev623'))
@@ -249,6 +249,12 @@
for version in other_versions:
self.assertFalse(V(version).is_final)
+ def test_micro_predicate(self):
+ self.assertNotEqual(V('3.4.0'), V('3.4'))
+ predicate = VersionPredicate('zope.event (3.4.0)')
+ self.assertTrue(predicate.match('3.4.0'))
+ self.assertFalse(predicate.match('3.4.1'))
+
class VersionWhiteBoxTestCase(unittest.TestCase):
diff --git a/distutils2/version.py b/distutils2/version.py
--- a/distutils2/version.py
+++ b/distutils2/version.py
@@ -57,7 +57,8 @@
1.2a # release level must have a release serial
1.2.3b
"""
- def __init__(self, s, error_on_huge_major_num=True):
+ def __init__(self, s, error_on_huge_major_num=True,
+ drop_trailing_zeros=False):
"""Create a NormalizedVersion instance from a version string.
@param s {str} The version string.
@@ -74,8 +75,12 @@
and, e.g. downstream Linux package managers, will forever remove
the possibility of using a version number like "1.0" (i.e.
where the major number is less than that huge major number).
+ @param drop_trailing_zeros {bool} Whether to drop trailing zeros
+
+ from the returned list. Default True.
"""
self.is_final = True # by default, consider a version as final.
+ self.drop_trailing_zeros = drop_trailing_zeros
self._parse(s, error_on_huge_major_num)
@classmethod
@@ -93,7 +98,7 @@
parts = []
# main version
- block = self._parse_numdots(groups['version'], s, False, 2)
+ block = self._parse_numdots(groups['version'], s, 2)
extraversion = groups.get('extraversion')
if extraversion not in ('', None):
block += self._parse_numdots(extraversion[1:], s)
@@ -130,16 +135,13 @@
raise HugeMajorVersionNumError("huge major version number, %r, "
"which might cause future problems: %r" % (self.parts[0][0], s))
- def _parse_numdots(self, s, full_ver_str, drop_trailing_zeros=True,
- pad_zeros_length=0):
+ def _parse_numdots(self, s, full_ver_str, pad_zeros_length=0):
"""Parse 'N.N.N' sequences, return a list of ints.
@param s {str} 'N.N.N...' sequence to be parsed
@param full_ver_str {str} The full version string from which this
comes. Used for error strings.
- @param drop_trailing_zeros {bool} Whether to drop trailing zeros
- from the returned list. Default True.
- @param pad_zeros_length {int} The length to which to pad the
+ @param pad_zeros_length {int} The length to which to pad the
returned list with zeros, if necessary. Default 0.
"""
nums = []
@@ -148,7 +150,7 @@
raise IrrationalVersionError("cannot have leading zero in "
"version number segment: '%s' in %r" % (n, full_ver_str))
nums.append(int(n))
- if drop_trailing_zeros:
+ if self.drop_trailing_zeros:
while nums and nums[-1] == 0:
nums.pop()
while len(nums) < pad_zeros_length:
--
Repository URL: http://hg.python.org/distutils2
More information about the Python-checkins
mailing list