diff options
author | Wojtek Kosior <koszko@koszko.org> | 2022-10-07 13:03:38 +0200 |
---|---|---|
committer | Wojtek Kosior <koszko@koszko.org> | 2022-10-08 19:08:36 +0200 |
commit | 9ab39cd31422636b4678bcea2363f178a7e298d7 (patch) | |
tree | 8e106ca6bfff856d97f82477202666fa83b78355 /src/hydrilla | |
parent | 6b4de4125e0552292087f443a61518c433981465 (diff) | |
download | haketilo-hydrilla-9ab39cd31422636b4678bcea2363f178a7e298d7.tar.gz haketilo-hydrilla-9ab39cd31422636b4678bcea2363f178a7e298d7.zip |
[builder][server][proxy] make current Haketilo version available to our code as a tuple of integers
Diffstat (limited to 'src/hydrilla')
-rw-r--r-- | src/hydrilla/proxy/policies/payload_resource.py | 6 | ||||
-rw-r--r-- | src/hydrilla/versions.py | 10 |
2 files changed, 12 insertions, 4 deletions
diff --git a/src/hydrilla/proxy/policies/payload_resource.py b/src/hydrilla/proxy/policies/payload_resource.py index 70844e6..7fdc7ac 100644 --- a/src/hydrilla/proxy/policies/payload_resource.py +++ b/src/hydrilla/proxy/policies/payload_resource.py @@ -64,13 +64,12 @@ import json from threading import Lock from base64 import b64encode from urllib.parse import quote, parse_qs, urlparse, urlencode, urljoin -from itertools import takewhile import jinja2 from ...translations import smart_gettext as _ from ...url_patterns import ParsedUrl -from ..._version import version_tuple +from ...versions import haketilo_version from .. import state from .. import http_messages from . import base @@ -281,8 +280,7 @@ class PayloadResourcePolicy(PayloadAwarePolicy): template = jinja_env.get_template('page_init_script.js.jinja') token = self.payload_data.unique_token base_url = self.assets_base_url(request_info.url) - ver = [*takewhile(lambda i: isinstance(i, int), version_tuple)] - ver_str = json.dumps(ver) + ver_str = json.dumps(haketilo_version) js = template.render( unique_token_encoded = encode_string_for_js(token), assets_base_url_encoded = encode_string_for_js(base_url), diff --git a/src/hydrilla/versions.py b/src/hydrilla/versions.py index dcebaa2..065ccca 100644 --- a/src/hydrilla/versions.py +++ b/src/hydrilla/versions.py @@ -35,6 +35,11 @@ from __future__ import annotations import typing as t +from itertools import takewhile + +from . import _version + + VerTuple = t.NewType('VerTuple', 'tuple[int, ...]') def normalize(ver: t.Sequence[int]) -> VerTuple: @@ -66,3 +71,8 @@ def version_string(ver: VerTuple, rev: t.Optional[int] = None) -> str: 1.2.3-5 """ return '.'.join(str(n) for n in ver) + ('' if rev is None else f'-{rev}') + +haketilo_version = normalize(tuple(takewhile( + lambda i: isinstance(i, int), + _version.version_tuple # type: ignore +))) |