do not resolve sanitizied using filter
This commit is contained in:
parent
004b45b6f1
commit
219c0204dd
3 changed files with 25 additions and 7 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
from typing import List
|
from typing import List
|
||||||
|
from typing import Set
|
||||||
|
|
||||||
from ytdl_sub.config.overrides import Overrides
|
from ytdl_sub.config.overrides import Overrides
|
||||||
from ytdl_sub.config.plugin.plugin_mapping import PluginMapping
|
from ytdl_sub.config.plugin.plugin_mapping import PluginMapping
|
||||||
|
|
@ -36,14 +37,29 @@ class ResolutionLevel:
|
||||||
|
|
||||||
class VariableValidation:
|
class VariableValidation:
|
||||||
|
|
||||||
|
def _get_resolve_partial_filter(self) -> Set[str]:
|
||||||
|
# Exclude sanitized variables from partial validation. This lessens the work
|
||||||
|
# and prevents double-evaluation, which can lead to bad behavior like double-prints.
|
||||||
|
return {
|
||||||
|
name
|
||||||
|
for name in self.script.variable_names
|
||||||
|
if name not in self.unresolved_variables and not name.endswith("_sanitized")
|
||||||
|
}
|
||||||
|
|
||||||
def _apply_resolution_level(self) -> None:
|
def _apply_resolution_level(self) -> None:
|
||||||
if self._resolution_level == ResolutionLevel.RESOLVE:
|
if self._resolution_level == ResolutionLevel.RESOLVE:
|
||||||
# Partial resolve everything, but not including internal variables
|
# Partial resolve everything, but not including internal variables
|
||||||
self.unresolved_variables |= VARIABLES.variable_names(include_sanitized=True)
|
self.unresolved_variables |= VARIABLES.variable_names(include_sanitized=True)
|
||||||
self.script = self.script.resolve_partial(unresolvable=self.unresolved_variables)
|
self.script = self.script.resolve_partial(
|
||||||
|
unresolvable=self.unresolved_variables,
|
||||||
|
output_filter=self._get_resolve_partial_filter(),
|
||||||
|
)
|
||||||
elif self._resolution_level == ResolutionLevel.INTERNAL:
|
elif self._resolution_level == ResolutionLevel.INTERNAL:
|
||||||
# Partial resolve everything including internal variables
|
# Partial resolve everything including internal variables
|
||||||
self.script = self.script.resolve_partial(unresolvable=self.unresolved_variables)
|
self.script = self.script.resolve_partial(
|
||||||
|
unresolvable=self.unresolved_variables,
|
||||||
|
output_filter=self._get_resolve_partial_filter(),
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
raise ValueError("Invalid resolution level for validation")
|
raise ValueError("Invalid resolution level for validation")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -742,11 +742,10 @@ class Script:
|
||||||
if isinstance(definition, Variable) and definition.name not in unresolvable:
|
if isinstance(definition, Variable) and definition.name not in unresolvable:
|
||||||
if definition in resolved:
|
if definition in resolved:
|
||||||
maybe_resolved = resolved[definition]
|
maybe_resolved = resolved[definition]
|
||||||
|
elif definition in unresolved:
|
||||||
|
maybe_resolved = unresolved[definition]
|
||||||
else:
|
else:
|
||||||
# If it's not in resolved, it must be in unresolved.
|
raise UNREACHABLE
|
||||||
# Do not modify the definition, this avoids duplicate work because it will
|
|
||||||
# wait for the single dependent variable to be resolved.
|
|
||||||
assert definition in unresolved
|
|
||||||
elif isinstance(definition, VariableDependency):
|
elif isinstance(definition, VariableDependency):
|
||||||
maybe_resolved = definition.partial_resolve(
|
maybe_resolved = definition.partial_resolve(
|
||||||
resolved_variables=resolved,
|
resolved_variables=resolved,
|
||||||
|
|
@ -784,8 +783,9 @@ class Script:
|
||||||
def resolve_partial(
|
def resolve_partial(
|
||||||
self,
|
self,
|
||||||
unresolvable: Optional[Set[str]] = None,
|
unresolvable: Optional[Set[str]] = None,
|
||||||
|
output_filter: Optional[Set[str]] = None,
|
||||||
) -> "Script":
|
) -> "Script":
|
||||||
out = self._resolve_partial(unresolvable=unresolvable)
|
out = self._resolve_partial(unresolvable=unresolvable, output_filter=output_filter)
|
||||||
for var_name, definition in out.items():
|
for var_name, definition in out.items():
|
||||||
self._variables[var_name] = definition
|
self._variables[var_name] = definition
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -281,5 +281,7 @@ class VariableDependency(ABC):
|
||||||
elif isinstance(arg, Variable):
|
elif isinstance(arg, Variable):
|
||||||
if arg not in resolved_variables:
|
if arg not in resolved_variables:
|
||||||
is_resolvable = False
|
is_resolvable = False
|
||||||
|
if arg in unresolved_variables:
|
||||||
|
maybe_resolvable_args[-1] = unresolved_variables[arg]
|
||||||
|
|
||||||
return maybe_resolvable_args, is_resolvable
|
return maybe_resolvable_args, is_resolvable
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue