diff --git a/pyproject.toml b/pyproject.toml index d11792a..060f557 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -42,7 +42,7 @@ dependencies = [ "polib>=1.2.0", "pycountry>=26.2.16", "pydantic>=2.11.7", - "python-liquid>=2.2.0", + "python-liquid==2.3.1", ] [project.urls] diff --git a/src/metaglot/__init__.py b/src/metaglot/__init__.py index 8b1c099..e1538cc 100644 --- a/src/metaglot/__init__.py +++ b/src/metaglot/__init__.py @@ -1,10 +1,13 @@ import logging import sys from argparse import ArgumentParser +from . import hack from .cmds import run, register, parse def main() -> None: + hack.relax_liquid_range_literal_boundary() + logging.basicConfig(level=logging.INFO, format="[%(levelname)s] %(message)s") parser = ArgumentParser( diff --git a/src/metaglot/hack.py b/src/metaglot/hack.py new file mode 100644 index 0000000..c9f1472 --- /dev/null +++ b/src/metaglot/hack.py @@ -0,0 +1,25 @@ +"""Runtime hacks over third-party dependencies. + +Each hack should be applied at the very start of ``main`` and +documents why it exists and when it can be dropped. +""" + +import liquid.builtin.expressions.primitive as _primitive + +# TODO: +# When python-liquid relax the boundary of range literal, +# remove this hack. + + +def relax_liquid_range_literal_boundary() -> None: + """Relax python-liquid's range literal bounds. + + python-liquid (pinned to 2.3.1) clamps the endpoints of range literals + such as ``(1000..1028)`` to plus/minus 1024, silently truncating the + loop to 1000..1023. Windows RC string identifiers legitimately go up + to 65535, so templates iterating numeric ID ranges lose entries + without any error. Relax the bounds the library itself defines + to a more large boundary (as its commented) + """ + _primitive.MAX_RANGE = (2**53) - 1 + _primitive.MIN_RANGE = -(2**53) + 1 diff --git a/uv.lock b/uv.lock index a6a4397..059de54 100644 --- a/uv.lock +++ b/uv.lock @@ -108,7 +108,7 @@ requires-dist = [ { name = "polib", specifier = ">=1.2.0" }, { name = "pycountry", specifier = ">=26.2.16" }, { name = "pydantic", specifier = ">=2.11.7" }, - { name = "python-liquid", specifier = ">=2.2.0" }, + { name = "python-liquid", specifier = "==2.3.1" }, ] [[package]]