Skip to content

Commit

Permalink
Fix compatibility issues with older python versions
Browse files Browse the repository at this point in the history
Signed-off-by: Marcus Burghardt <[email protected]>
  • Loading branch information
marcusburghardt committed Dec 13, 2024
1 parent 38f80a0 commit 467a848
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions ssg/variables.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from __future__ import absolute_import
from __future__ import print_function

import os
import glob
import os
import sys
import yaml

from collections import defaultdict
Expand All @@ -15,11 +16,17 @@
)
from .yaml import open_and_macro_expand


if sys.version_info >= (3, 9):
list_type = list # Python 3.9+ supports built-in generics
else:
from typing import List as list_type # Fallback for older versions

# Cache variable files to avoid multiple reads
_var_files_cache = {}


def get_variable_files_in_folder(content_dir: str, subfolder: str) -> list[str]:
def get_variable_files_in_folder(content_dir: str, subfolder: str) -> list_type[str]:
"""
Retrieve a list of variable files within a specified folder in the project.
Expand All @@ -36,7 +43,7 @@ def get_variable_files_in_folder(content_dir: str, subfolder: str) -> list[str]:
return glob.glob(pattern, recursive=True)


def get_variable_files(content_dir: str) -> list[str]:
def get_variable_files(content_dir: str) -> list_type[str]:
"""
Retrieves all variable files from the specified content root directory.
Expand Down Expand Up @@ -296,7 +303,7 @@ def _load_controls_manager(controls_dir: str, product_yaml: dict) -> object:
return control_mgr


def _get_profiles_from_products(content_dir: str, products: list) -> list:
def _get_profiles_from_products(content_dir: str, products: list) -> list_type:
"""
Retrieves profiles with respective variables from the given products.
Expand Down

0 comments on commit 467a848

Please sign in to comment.