mirror of
https://github.com/lilydjwg/nvchecker
synced 2024-12-27 09:02:19 +00:00
Refine docs of substitution options and add a test for option priority
This commit is contained in:
parent
78fef9d34d
commit
05b604530c
11
README.rst
11
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:
|
||||
|
@ -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:
|
||||
|
@ -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"
|
||||
|
Loading…
Reference in New Issue
Block a user