diff --git a/README.rst b/README.rst index 7e95101..e0925d4 100644 --- a/README.rst +++ b/README.rst @@ -127,15 +127,22 @@ max_concurrent Global Options -------------- -The following options applies to all checkers. +The following options apply to all checkers. prefix - Strip the prefix string if the version string starts with it. + Strip the prefix string if the version string starts with it. Otherwise the + version string is returned as-is. from_pattern, to_pattern Both are Python-compatible regular expressions. If ``from_pattern`` is found in the version string, it will be replaced with ``to_pattern``. +If both ``prefix`` and ``from_pattern``/``to_pattern`` are used, +``from_pattern``/``to_pattern`` are ignored. If you want to strip the prefix +and then do something special, just use ``from_pattern```/``to_pattern``. For +example, the transformation of ``v1_1_0`` => ``1.1.0`` can be achieved with +``from_pattern = v(\d+)_(\d+)_(\d+)`` and ``to_pattern = \1.\2.\3``. + Search in a Webpage ------------------- Search through a specific webpage for the version string. This type of version finding has these fields: diff --git a/nvchecker/get_version.py b/nvchecker/get_version.py index d0d8489..b4668a8 100644 --- a/nvchecker/get_version.py +++ b/nvchecker/get_version.py @@ -17,16 +17,7 @@ handler_precedence = ( def substitute_version(version, name, conf): ''' Substitute the version string via defined rules in the configuration file. - Accepted rules are: - - * from_pattern, to_pattern: Both should be Python regular expressions. - `from_pattern` found in the version string will be substituted to - `to_pattern`. - * prefix: If the version string starts with `prefix`, the prefix is removed. - Otherwise the version string is returned as-is. - - If both prefix and from_pattern/to_pattern are used, from_pattern/to_pattern - are ignored. + See README.rst#global-options for details. ''' prefix = conf.get('prefix') if prefix: diff --git a/tests/test_substitute.py b/tests/test_substitute.py index d1f8af7..1b033ec 100644 --- a/tests/test_substitute.py +++ b/tests/test_substitute.py @@ -15,3 +15,6 @@ async def test_substitute_regex(get_version): async def test_substitute_regex_missing_ok(get_version): assert await get_version("example", {"manual": "r15", "from_pattern": r"r(\d+)([a-z])", "to_pattern": r"r\1.\2"}) == "r15" + +async def test_substitute_prefix_has_higher_priority(get_version): + assert await get_version("example", {"manual": "r15", "prefix": "r", "from_pattern": "r(\d+)", "to_pattern": "R\1"}) == "15"