docker_tag_updater.helpers.regex_rules#

Dictionary object for version parsing using regex.

This module defines the most fundamental object that is used by all other modules of this subpackage.

DefaultRules: RegexRules = {'default': 'v?(?:ersion-)?(?P<major>\\d+)\\.(?P<minor>\\d+)\\.(?P<patch>\\d+).*'}#

The default rule that should work for most standard semantic versions.

This object has the following equivalent aliases: default, docker.io, and docker.

class RegexRules(rules)#

Bases: dict

An aliased dictionary with defined regex rules for version parsing.

Parameters:

rules (dict[str, str]) – A dictionary containing names as keys and regex strings as values.

Examples

The DefaultRules object that is provided in this module is created as follows.

>>> DefaultRules = RegexRules(
...     rules = {
...         "default": r"v?(?:ersion-)?(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+).*",
...     }
... )

Notes

RegexRules objects can be added together to concatenate into a larger RegexRules object. Do take note that a new rule is always prioritised over an existing rule with the same name, i.e., the operation does not always commute.

See also

DefaultRules

For an example of a RegexRules object.

add_alias(main_rule, *aliases)#

Add a number of aliases to the rule.

Parameters:
  • main_rule (str) – The name main rule to add aliases to.

  • aliases (str) – Strings of aliases to the main rule.

Return type:

None

Examples

To add the aliases “docker.io” and “docker” to the rule named “default”, do the following: >>> DefaultRules.add_alias(“default”, “docker.io”, “docker”)

Raises:

NotImplementedError – If there are no aliases to be added.

get(rule)#

Redefine the get function.

Parameters:

rule (str) – The name of the rule or its alias.

Return type:

str

Returns:

A regex raw string.

Examples

>>> rules.get('default')
'v?(?:ersion-)?(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+).*'
has_rule(rule)#

Check if the rule exists or is an alias.

Parameters:

rule (str) – The name of the rule to check its existence of.

Return type:

bool

Returns:

True if the rule exists as either a real rule or an alias in this RegexRules object, and False otherwise.