You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Something has changed within loads function as now with 3.0.0 it is impossible to parse tf files in recursive functions.
from pathlib import Path, PosixPath
from typing import Iterable, Union, Any, Optional
from hcl2 import loads
def __get_submodules(
module: Path,
accumulator: dict[Union[Path, str], Optional[dict[Union[Path, str], Any]]]
) -> dict[Union[Path, str], Optional[dict[Union[Path, str], Any]]]:
modules_tf:Path=module /"modules.tf"
accumulator[module] = {} if modules_tf.is_file() else None
if not modules_tf.is_file():
return accumulator
submodules:set[str] = set(map(
lambda submodule:next(iter(submodule.values()))["source"][0],
loads(modules_tf.read_text())["module"]
))
submodules: Iterable[Union[str, Path]] = map(
lambda item: (module / item).resolve() if item.startswith(".") else item,
submodules
)
for submodule in submodules:
if isinstance(submodule, PosixPath):
accumulator[module] |= __get_submodules(submodule, accumulator[module])
else:
accumulator[module] |= {submodule: None}
return accumulator
__get_submodules(Path("path to module with submodules multiple levels downstream"), {})
Traceback (most recent call last):
File "/home/xxx/Documents/Projects/infra-terraform/./run.py", line 5, in <module>
show_cli("skeleton")
File "/home/xxx/Documents/Projects/infra-terraform/lib/python/cli/show_cli.py", line 30, in show_cli
load_module(selected_command)
File "/home/xxx/Documents/Projects/infra-terraform/lib/python/utils/python/load_module.py", line 7, in load_module
run_module(module_fqn, {}, "__main__")
File "/usr/lib/python3.10/runpy.py", line 227, in run_module
return _run_code(code, {}, init_globals, run_name, mod_spec)
File "/usr/lib/python3.10/runpy.py", line 86, in _run_code
exec(code, run_globals)
File "/home/xxx/Documents/Projects/infra-terraform/lib/python/cli/commands/any/validate_providers.py", line 90, in <module>
validate_providers()
File "/home/xxx/Documents/Projects/infra-terraform/lib/python/cli/commands/any/validate_providers.py", line 69, in validate_providers
modules_tree: dict[Union[Path, str], Optional[dict[Union[Path, str], Any]]] = get_all_submodules_tree(True)
File "/home/xxx/Documents/Projects/infra-terraform/lib/python/utils/terraform/get_all_submodules_tree.py", line 28, in get_all_submodules_tree
return dict(reduce(
File "/home/xxx/Documents/Projects/infra-terraform/lib/python/utils/terraform/get_all_submodules_tree.py", line 31, in <lambda>
get_submodule_tree(module, is_inversed)
File "/home/xxx/Documents/Projects/infra-terraform/lib/python/utils/terraform/get_submodule_tree.py", line 65, in get_submodule_tree
submodules: dict[Union[Path, str], Optional[dict[Union[Path, str], Any]]] = __get_submodules(module, {})
File "/home/xxx/Documents/Projects/infra-terraform/lib/python/utils/terraform/get_submodule_tree.py", line 41, in __get_submodules
accumulator[module] |= __get_submodules(submodule, accumulator[module])
File "/home/xxx/Documents/Projects/infra-terraform/lib/python/utils/terraform/get_submodule_tree.py", line 41, in __get_submodules
accumulator[module] |= __get_submodules(submodule, accumulator[module])
File "/home/xxx/Documents/Projects/infra-terraform/lib/python/utils/terraform/get_submodule_tree.py", line 41, in __get_submodules
accumulator[module] |= __get_submodules(submodule, accumulator[module])
[Previous line repeated 971 more times]
File "/home/xxx/Documents/Projects/infra-terraform/lib/python/utils/terraform/get_submodule_tree.py", line 33, in __get_submodules
loads(modules_tf.read_text())["module"]
File "/home/xxx/Documents/Projects/infra-terraform/.virtualenv/lib/python3.10/site-packages/hcl2/api.py", line 18, in loads
return hcl2.parse(text + "\n")
File "/home/xxx/Documents/Projects/infra-terraform/.virtualenv/lib/python3.10/site-packages/lark/lark.py", line 464, in parse
return self.parser.parse(text, start=start)
File "/home/xxx/Documents/Projects/infra-terraform/.virtualenv/lib/python3.10/site-packages/lark/parser_frontends.py", line 115, in parse
return self._parse(token_stream, start)
File "/home/xxx/Documents/Projects/infra-terraform/.virtualenv/lib/python3.10/site-packages/lark/parser_frontends.py", line 63, in _parse
return self.parser.parse(input, start, *args)
File "/home/xxx/Documents/Projects/infra-terraform/.virtualenv/lib/python3.10/site-packages/lark/parsers/lalr_parser.py", line 35, in parse
return self.parser.parse(*args)
File "/home/xxx/Documents/Projects/infra-terraform/.virtualenv/lib/python3.10/site-packages/lark/parsers/lalr_parser.py", line 97, in parse
reduce(arg)
File "/home/xxx/Documents/Projects/infra-terraform/.virtualenv/lib/python3.10/site-packages/lark/parsers/lalr_parser.py", line 77, in reduce
value = self.callbacks[rule](s)
File "/home/xxx/Documents/Projects/infra-terraform/.virtualenv/lib/python3.10/site-packages/lark/parse_tree_builder.py", line 127, in __call__
return self.node_builder(filtered)
File "/home/xxx/Documents/Projects/infra-terraform/.virtualenv/lib/python3.10/site-packages/hcl2/transformer.py", line 67, in tuple
return [self.to_string_dollar(arg) for arg in self.strip_new_line_tokens(args)]
File "/home/xxx/Documents/Projects/infra-terraform/.virtualenv/lib/python3.10/site-packages/hcl2/transformer.py", line 243, in strip_new_line_tokens
return [arg for arg in args if arg != "\n" and not isinstance(arg, Discard)]
File "/home/xxx/Documents/Projects/infra-terraform/.virtualenv/lib/python3.10/site-packages/hcl2/transformer.py", line 243, in <listcomp>
return [arg for arg in args if arg != "\n" and not isinstance(arg, Discard)]
RecursionError: maximum recursion depth exceeded while calling a Python object
The text was updated successfully, but these errors were encountered:
Something has changed within
loads
function as now with 3.0.0 it is impossible to parse tf files in recursive functions.The text was updated successfully, but these errors were encountered: