Coverage for jinjazzle/ext/version.py: 100%
10 statements
« prev ^ index » next coverage.py v7.6.10, created at 2025-01-24 22:03 +0000
« prev ^ index » next coverage.py v7.6.10, created at 2025-01-24 22:03 +0000
1"""
2Description
3-----------
5VersionExtension provides the capability to handle semver version strings.
8.. autoclass:: VersionExtension
11.. py:function:: revpkg(lhs, separator1=".", separator2=".")
13 Take a version, and reverse it in the most simplistic way not taking into
14 account anything that would constitute "pre-release" or "build" information in the
15 context of semver.
17 Available as a function and a filter. For the latter case, *lhs* is automatically specified as the left hand side of the filter.
19 .. code-block:: jinja
21 # Returns 3.2.1
22 {{ revpkg("1.2.3") }}
24"""
26from jinja2.ext import Extension
29def _revpkg(lhs, separator1=".", separator2="."):
30 lhss = lhs.split(separator1)
31 lhss = reversed(lhss)
32 return separator2.join(lhss)
35# pylint: disable=abstract-method
36class VersionExtension(Extension):
37 """
38 Jinja2 extension for version manipulation.
39 """
41 def __init__(self, environment):
42 """
43 Jinja2 Extension constructor.
44 """
45 super().__init__(environment)
47 environment.filters["revpkg"] = _revpkg
48 environment.globals.update(revpkg=_revpkg)