diff --git a/CHANGELOG.md b/CHANGELOG.md index 1be71c1..89a483b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ Change log for the little-timmy python module. +## [1.1.2] - 2024/10/13 + +- Fix `jinja2.exceptions.TemplateSyntaxError` when loading templates with custom filters by failing back to basic searching. +- Add `-v` version output. + ## [1.1.1] - 2024/10/05 - Fix erroneous new line in `-g` output. diff --git a/github_action/Dockerfile b/github_action/Dockerfile index efd7698..a26f829 100644 --- a/github_action/Dockerfile +++ b/github_action/Dockerfile @@ -11,7 +11,7 @@ LABEL com.github.actions.name="little-timmy-action" \ org.opencontainers.image.vendor="@hoo29" \ org.opencontainers.image.description="GHA for Little Timmy, an unused Ansible variable finder." -RUN pip3 install little-timmy==1.1.1 +RUN pip3 install little-timmy==1.1.2 COPY entrypoint.sh /entrypoint.sh diff --git a/little_timmy/var_finder.py b/little_timmy/var_finder.py index 95c373e..41f875a 100644 --- a/little_timmy/var_finder.py +++ b/little_timmy/var_finder.py @@ -10,7 +10,7 @@ from ansible.template import JinjaPluginIntercept from dataclasses import dataclass from glob import iglob -from jinja2 import Environment, meta +from jinja2 import Environment, exceptions, meta from typing import Any from .config_loader import Config @@ -227,7 +227,11 @@ def find_unused_vars(directory: str, config: Config) -> dict[str, set[str]]: for path in get_files_in_folder(directory, "**/templates", config, include_ext=True): LOGGER.debug(f"template file {path}") with open(path, "r") as f: - parse_jinja(f.read(), all_referenced_vars, path) + contents = f.read() + try: + parse_jinja(contents, all_referenced_vars, path) + except exceptions.TemplateSyntaxError: + check_raw_file_for_variables(contents, path, context) # playbooks for path in get_files_in_folder(directory, ".", config, f"*playbook*{YAML_FILE_EXTENSION_GLOB}"): diff --git a/pyproject.toml b/pyproject.toml index bfc7a41..8dbedee 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "little-timmy" -version = "1.1.1" +version = "1.1.2" description = "Little Timmy will try their best to find those unused Ansible variables." readme = "README.md" authors = [{ name = "Huw" }]