mirror of
https://github.com/lilydjwg/nvchecker.git
synced 2025-03-10 06:14:02 +00:00
Refine docs of substitution options and add a test for option priority
This commit is contained in:
parent
78fef9d34d
commit
05b604530c
3 changed files with 13 additions and 12 deletions
11
README.rst
11
README.rst
|
@ -127,15 +127,22 @@ max_concurrent
|
||||||
|
|
||||||
Global Options
|
Global Options
|
||||||
--------------
|
--------------
|
||||||
The following options applies to all checkers.
|
The following options apply to all checkers.
|
||||||
|
|
||||||
prefix
|
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
|
from_pattern, to_pattern
|
||||||
Both are Python-compatible regular expressions. If ``from_pattern`` is found
|
Both are Python-compatible regular expressions. If ``from_pattern`` is found
|
||||||
in the version string, it will be replaced with ``to_pattern``.
|
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 in a Webpage
|
||||||
-------------------
|
-------------------
|
||||||
Search through a specific webpage for the version string. This type of version finding has these fields:
|
Search through a specific webpage for the version string. This type of version finding has these fields:
|
||||||
|
|
|
@ -17,16 +17,7 @@ handler_precedence = (
|
||||||
def substitute_version(version, name, conf):
|
def substitute_version(version, name, conf):
|
||||||
'''
|
'''
|
||||||
Substitute the version string via defined rules in the configuration file.
|
Substitute the version string via defined rules in the configuration file.
|
||||||
Accepted rules are:
|
See README.rst#global-options for details.
|
||||||
|
|
||||||
* 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.
|
|
||||||
'''
|
'''
|
||||||
prefix = conf.get('prefix')
|
prefix = conf.get('prefix')
|
||||||
if prefix:
|
if prefix:
|
||||||
|
|
|
@ -15,3 +15,6 @@ async def test_substitute_regex(get_version):
|
||||||
|
|
||||||
async def test_substitute_regex_missing_ok(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"
|
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"
|
||||||
|
|
Loading…
Add table
Reference in a new issue