closer;
This commit is contained in:
parent
28487c67f8
commit
bca397cd7b
4 changed files with 16 additions and 11 deletions
|
|
@ -1,4 +1,3 @@
|
|||
import copy
|
||||
from typing import Dict
|
||||
|
||||
from ytdl_sub.config.overrides import Overrides
|
||||
|
|
@ -9,7 +8,6 @@ from ytdl_sub.config.preset_options import OutputOptions
|
|||
from ytdl_sub.config.validators.options import OptionsValidator
|
||||
from ytdl_sub.downloaders.url.validators import MultiUrlValidator
|
||||
from ytdl_sub.entries.script.variable_definitions import VARIABLES
|
||||
from ytdl_sub.entries.script.variable_types import Variable
|
||||
from ytdl_sub.script.script import Script
|
||||
from ytdl_sub.utils.script import ScriptUtils
|
||||
from ytdl_sub.validators.string_formatter_validators import validate_formatters
|
||||
|
|
@ -31,9 +29,9 @@ class VariableValidation:
|
|||
pass
|
||||
elif self._resolution_level == ResolutionLevel.RESOLVE:
|
||||
# Partial resolve everything, but not including internal variables
|
||||
self.unresolved_variables |= VARIABLES.variable_names(include_sanitized=True)
|
||||
self.script = self.script.resolve_partial(
|
||||
unresolvable=self.unresolved_variables
|
||||
| VARIABLES.variable_names(include_sanitized=True)
|
||||
)
|
||||
elif self._resolution_level == ResolutionLevel.INTERNAL:
|
||||
# Partial resolve everything including internal variables
|
||||
|
|
|
|||
|
|
@ -734,7 +734,12 @@ class Script:
|
|||
|
||||
maybe_resolved = definition
|
||||
if isinstance(definition, Variable) and definition.name not in unresolvable:
|
||||
maybe_resolved = resolved.get(definition, unresolved[definition])
|
||||
if definition in resolved:
|
||||
maybe_resolved = resolved[definition]
|
||||
elif definition in unresolved:
|
||||
maybe_resolved = unresolved[definition]
|
||||
else:
|
||||
raise UNREACHABLE
|
||||
elif isinstance(definition, VariableDependency):
|
||||
maybe_resolved = definition.partial_resolve(
|
||||
resolved_variables=resolved,
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ from ytdl_sub.script.utils.exceptions import ScriptVariableNotResolved
|
|||
from ytdl_sub.script.utils.exceptions import UserException
|
||||
from ytdl_sub.script.utils.exceptions import UserThrownRuntimeError
|
||||
from ytdl_sub.utils.exceptions import StringFormattingVariableNotFoundException
|
||||
from ytdl_sub.utils.file_handler import get_md5_hash
|
||||
from ytdl_sub.utils.script import ScriptUtils
|
||||
from ytdl_sub.validators.validators import DictValidator
|
||||
from ytdl_sub.validators.validators import ListValidator
|
||||
|
|
@ -250,11 +251,11 @@ def _validate_formatter(
|
|||
variable_names = {var.name for var in parsed.variables}
|
||||
custom_function_names = {f"%{func.name}" for func in parsed.custom_functions}
|
||||
|
||||
# if resolve_partial:
|
||||
# formatter_hash = str(formatter_validator.__hash__())
|
||||
# mock_script.add_parsed(
|
||||
# {formatter_hash: formatter_validator.parsed}
|
||||
# ).resolve_partial(unresolvable=unresolved_variables).definition_of(formatter_hash)
|
||||
if resolve_partial and not is_static_formatter:
|
||||
formatter_hash = get_md5_hash(formatter_validator.format_string)
|
||||
parsed = mock_script.add_parsed(
|
||||
{formatter_hash: formatter_validator.parsed}
|
||||
).resolve_partial(unresolvable=unresolved_variables).definition_of(formatter_hash)
|
||||
|
||||
# Add lambda functions to custom function names, if it's custom
|
||||
for lambda_func in parsed.lambdas:
|
||||
|
|
@ -284,7 +285,7 @@ def _validate_formatter(
|
|||
update=True,
|
||||
)["tmp_var"].native
|
||||
|
||||
return formatter_validator.format_string
|
||||
return ScriptUtils.to_native_script(parsed)
|
||||
except RuntimeException as exc:
|
||||
if isinstance(exc, ScriptVariableNotResolved) and is_static_formatter:
|
||||
raise StringFormattingVariableNotFoundException(
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import pytest
|
|||
import yaml
|
||||
|
||||
from ytdl_sub.config.config_file import ConfigFile
|
||||
from ytdl_sub.config.validators.variable_validation import ResolutionLevel
|
||||
from ytdl_sub.entries.script.variable_definitions import VARIABLES
|
||||
from ytdl_sub.plugins.nfo_tags import NfoTagsOptions
|
||||
from ytdl_sub.subscriptions.subscription import Subscription
|
||||
|
|
@ -942,7 +943,7 @@ def test_default_docker_config_and_subscriptions_resolved_resolution(
|
|||
)
|
||||
assert len(default_subs) == 1
|
||||
|
||||
resolved_yaml_as_json = yaml.safe_load(default_subs[0].resolved_yaml(resolution_level=2))
|
||||
resolved_yaml_as_json = yaml.safe_load(default_subs[0].resolved_yaml(resolution_level=ResolutionLevel.RESOLVE))
|
||||
|
||||
assert resolved_yaml_as_json == {
|
||||
"chapters": {
|
||||
|
|
|
|||
Loading…
Reference in a new issue