started, check resolution of episode_file_path
This commit is contained in:
parent
a18a4bcd15
commit
93cfe59330
3 changed files with 35 additions and 6 deletions
|
|
@ -346,7 +346,9 @@ class BuiltInFunction(Function, BuiltInFunctionType):
|
||||||
|
|
||||||
# If the function is conditional, only run if its entirety is resolvable
|
# If the function is conditional, only run if its entirety is resolvable
|
||||||
if conditional_return_args:
|
if conditional_return_args:
|
||||||
if self.is_subset_of(variables=resolved_variables, custom_function_definitions=custom_functions):
|
if self.is_subset_of(
|
||||||
|
variables=resolved_variables, custom_function_definitions=custom_functions
|
||||||
|
):
|
||||||
return self.resolve(
|
return self.resolve(
|
||||||
resolved_variables=resolved_variables,
|
resolved_variables=resolved_variables,
|
||||||
custom_functions=custom_functions,
|
custom_functions=custom_functions,
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ import json
|
||||||
import re
|
import re
|
||||||
from typing import Any
|
from typing import Any
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
from ytdl_sub.script.parser import parse
|
from ytdl_sub.script.parser import parse
|
||||||
from ytdl_sub.script.types.array import UnresolvedArray
|
from ytdl_sub.script.types.array import UnresolvedArray
|
||||||
|
|
@ -155,16 +156,42 @@ class ScriptUtils:
|
||||||
raise UNREACHABLE
|
raise UNREACHABLE
|
||||||
return f"{{ {out} }}" if top_level else out
|
return f"{{ {out} }}" if top_level else out
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _is_top_level_string(cls, tree: SyntaxTree) -> Optional[str]:
|
||||||
|
if not (
|
||||||
|
len(tree.ast) == 1
|
||||||
|
and isinstance(tree.ast[0], BuiltInFunction)
|
||||||
|
and tree.ast[0].name == "concat"
|
||||||
|
):
|
||||||
|
return None
|
||||||
|
|
||||||
|
output = ""
|
||||||
|
for arg in tree.ast[0].args:
|
||||||
|
if isinstance(arg, BuiltInFunction) and arg.name == "string" and len(arg.args) == 1:
|
||||||
|
output += cls._to_script_code(arg.args[0], top_level=True)
|
||||||
|
else:
|
||||||
|
output += cls._to_script_code(arg, top_level=True)
|
||||||
|
|
||||||
|
return output
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _syntax_tree_to_native_script(cls, tree: SyntaxTree) -> str:
|
||||||
|
|
||||||
|
if (output := cls._is_top_level_string(tree)) is not None:
|
||||||
|
return output
|
||||||
|
|
||||||
|
output = ""
|
||||||
|
for arg in tree.ast:
|
||||||
|
output += cls._to_script_code(arg, top_level=True)
|
||||||
|
return output
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def to_native_script(cls, value: Any) -> str:
|
def to_native_script(cls, value: Any) -> str:
|
||||||
"""
|
"""
|
||||||
Converts any JSON-compatible value into equivalent script syntax
|
Converts any JSON-compatible value into equivalent script syntax
|
||||||
"""
|
"""
|
||||||
if isinstance(value, SyntaxTree):
|
if isinstance(value, SyntaxTree):
|
||||||
output = ""
|
return cls._syntax_tree_to_native_script(value)
|
||||||
for arg in value.ast:
|
|
||||||
output += cls._to_script_code(arg, top_level=True)
|
|
||||||
return output
|
|
||||||
|
|
||||||
return cls._to_script_code(cls._to_script_argument(value), top_level=True)
|
return cls._to_script_code(cls._to_script_argument(value), top_level=True)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -617,6 +617,6 @@ def test_default_docker_config_and_subscriptions(
|
||||||
unresolvable.add("sibling_metadata")
|
unresolvable.add("sibling_metadata")
|
||||||
|
|
||||||
out = default_subs[0].overrides.script.resolve_partial(unresolvable=unresolvable)
|
out = default_subs[0].overrides.script.resolve_partial(unresolvable=unresolvable)
|
||||||
prev = ScriptUtils.to_native_script(out._variables['episode_file_name'])
|
prev = ScriptUtils.to_native_script(out._variables["episode_file_name"])
|
||||||
|
|
||||||
print("hi")
|
print("hi")
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue