Skip to content

Commit

Permalink
Allow to expand macros from external integrations
Browse files Browse the repository at this point in the history
Allow to expand macros used in variables when the variable functions
are called outside the project.

Signed-off-by: Marcus Burghardt <maburgha@redhat.com>
  • Loading branch information
marcusburghardt committed Jan 13, 2025
1 parent 293aca9 commit 2567a19
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 2 additions & 2 deletions ssg/variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from collections import defaultdict
from .constants import BENCHMARKS
from .profiles import get_profiles_from_products
from .yaml import open_and_macro_expand
from .yaml import open_and_macro_expand_from_dir


if sys.version_info >= (3, 9):
Expand Down Expand Up @@ -82,7 +82,7 @@ def _get_variables_content(content_dir: str) -> dict_type:

for var_file in get_variable_files(content_dir):
try:
yaml_content = open_and_macro_expand(var_file)
yaml_content = open_and_macro_expand_from_dir(var_file, content_dir)
except Exception as e:
print(f"Error processing file {var_file}: {e}")
continue
Expand Down
6 changes: 5 additions & 1 deletion tests/unit/ssg-module/test_variables.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
import pytest

from ssg.constants import BENCHMARKS
from ssg.variables import (
Expand All @@ -22,6 +21,10 @@ def setup_test_files(base_dir, benchmark_dirs, create_txt_file=False):
benchmark_dirs (list[str]): List of benchmark folder paths to create.
create_txt_file (bool): Whether to create an additional .txt file in each benchmark.
"""
# Ensures the shared/macros directory exists even if in this case the testing example does
# not use Jinja2 macros.
os.makedirs(base_dir / "shared" / "macros", exist_ok=True)

for benchmark_dir in benchmark_dirs:
path = base_dir / benchmark_dir
os.makedirs(path, exist_ok=True)
Expand Down Expand Up @@ -119,6 +122,7 @@ def __init__(self, product_id, profile_id, variables):
result = get_variables_from_profiles(profiles)
assert result == expected_result


def test_get_variable_property(tmp_path):
content_dir = tmp_path / "content"
benchmark_dirs = ["app", "app/rules"]
Expand Down

0 comments on commit 2567a19

Please sign in to comment.