From 0811fca1c435c1477ee1465578580b491cba6c73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Barrois?= Date: Wed, 29 Apr 2020 11:46:24 +0200 Subject: Fix wildcard matching for SimpleSpec. Including docs and tests. Closes #98. --- ChangeLog | 5 ++++- docs/reference.rst | 9 +++++++++ semantic_version/base.py | 2 +- tests/test_base.py | 10 ++++++++++ 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index b7f41c6..7056f1a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,7 +4,10 @@ ChangeLog 2.8.5 (unreleased) ------------------ -- Nothing changed yet. +*Bugfix:* + + * `98 `_: + Properly handle wildcards in ``SimpleSpec`` (e.g. ``==1.2.*``). 2.8.4 (2019-12-21) diff --git a/docs/reference.rst b/docs/reference.rst index da08a22..951bd9a 100644 --- a/docs/reference.rst +++ b/docs/reference.rst @@ -472,6 +472,15 @@ Each of those ``Spec`` classes provides a shared set of methods to work with ver * A clause of ``>0.1.2-rc.3`` will match versions strictly above ``0.1.2-rc.3``, including matching prereleases of ``0.1.2``: ``0.1.2-rc.10`` is included; * A clause of ``>=XXX`` will match versions that match ``>XXX`` or ``==XXX`` + ..rubric:: Wildcards + + * A clause of ``==0.1.*`` is equivalent to ``>=0.1.0,<0.2.0`` + * A clause of ``>=0.1.*`` is equivalent to ``>=0.1.0`` + * A clause of ``==1.*`` or ``==1.*.*`` is equivalent to ``>=1.0.0,<2.0.0`` + * A clause of ``>=1.*`` or ``>=1.*.*`` is equivalent to ``>=1.0.0`` + * A clause of ``==*`` maps to ``>=0.0.0`` + * A clause of ``>=*`` maps to ``>=0.0.0`` + .. rubric:: Extensions Additionnally, python-semanticversion supports extensions from specific packaging platforms: diff --git a/semantic_version/base.py b/semantic_version/base.py index 7fd871e..871ccb0 100644 --- a/semantic_version/base.py +++ b/semantic_version/base.py @@ -1123,7 +1123,7 @@ class SimpleSpec(BaseSpec): elif minor is None: return Range(Range.OP_GTE, target) & Range(Range.OP_LT, target.next_major()) elif patch is None: - return Range(Range.OP_GTE, target) & Range(Range.OP_LT, target.next_patch()) + return Range(Range.OP_GTE, target) & Range(Range.OP_LT, target.next_minor()) elif build == '': return Range(Range.OP_EQ, target, build_policy=Range.BUILD_STRICT) else: diff --git a/tests/test_base.py b/tests/test_base.py index c9770c9..d0a0e81 100755 --- a/tests/test_base.py +++ b/tests/test_base.py @@ -644,6 +644,16 @@ class SpecTestCase(unittest.TestCase): ['0.1.1', '0.1.1+4'], ['0.1.1-alpha', '0.1.2-alpha', '0.1.2', '1.3.4'], ), + # 0.1.x + '==0.1.*': ( + ['0.1.1', '0.1.1+4', '0.1.0', '0.1.99'], + ['0.1.0-alpha', '0.0.1', '0.2.0'], + ), + # 1.x.x + '==1.*': ( + ['1.1.1', '1.1.0+4', '1.1.0', '1.99.99'], + ['1.0.0-alpha', '0.1.0', '2.0.0'], + ), # At least 0.1.0 with pre-releases, less than 0.1.4 excluding pre-releases, # neither 0.1.3-rc1 nor any build of that version, # not 0.1.0+b3 precisely -- cgit v1.2.1