optimize
This commit is contained in:
parent
69b1157c13
commit
fb8c65b653
2 changed files with 24 additions and 16 deletions
|
|
@ -77,8 +77,8 @@ class Script:
|
||||||
deps=deps + [dep.name],
|
deps=deps + [dep.name],
|
||||||
)
|
)
|
||||||
|
|
||||||
def _ensure_no_variable_cycles(self):
|
def _ensure_no_variable_cycles(self, variables: Dict[str, SyntaxTree]):
|
||||||
for variable_name, variable_definition in self._variables.items():
|
for variable_name, variable_definition in variables.items():
|
||||||
self._traverse_variable_dependencies(
|
self._traverse_variable_dependencies(
|
||||||
variable_name=variable_name,
|
variable_name=variable_name,
|
||||||
variable_dependency=variable_definition,
|
variable_dependency=variable_definition,
|
||||||
|
|
@ -193,15 +193,24 @@ class Script:
|
||||||
f"receive {lambda_type.num_input_args()}."
|
f"receive {lambda_type.num_input_args()}."
|
||||||
)
|
)
|
||||||
|
|
||||||
def _validate(self) -> None:
|
def _validate(self, added_variables: Optional[Set[str]] = None) -> None:
|
||||||
self._ensure_no_custom_function_cycles()
|
variables = self._variables
|
||||||
self._ensure_custom_function_arguments_valid()
|
if added_variables is not None:
|
||||||
self._ensure_no_variable_cycles()
|
variables = {
|
||||||
|
name: ast for name, ast in self._variables.items() if name in added_variables
|
||||||
|
}
|
||||||
|
|
||||||
for prefix, definitions in (
|
if added_variables is None:
|
||||||
("Variable ", self._variables),
|
self._ensure_no_custom_function_cycles()
|
||||||
("Custom function %", self._functions),
|
self._ensure_custom_function_arguments_valid()
|
||||||
):
|
|
||||||
|
self._ensure_no_variable_cycles(variables)
|
||||||
|
|
||||||
|
to_validate = [("Variable ", variables)]
|
||||||
|
if added_variables is None:
|
||||||
|
to_validate.append(("Custom function %", self._functions))
|
||||||
|
|
||||||
|
for prefix, definitions in to_validate:
|
||||||
self._ensure_custom_function_usage_num_input_arguments_valid(
|
self._ensure_custom_function_usage_num_input_arguments_valid(
|
||||||
prefix=prefix, definitions=definitions
|
prefix=prefix, definitions=definitions
|
||||||
)
|
)
|
||||||
|
|
@ -348,11 +357,10 @@ class Script:
|
||||||
custom_function_names=set(self._functions.keys()),
|
custom_function_names=set(self._functions.keys()),
|
||||||
variable_names=set(self._variables.keys()).union(variables.keys()),
|
variable_names=set(self._variables.keys()).union(variables.keys()),
|
||||||
)
|
)
|
||||||
all_resolvable |= self._variables[variable_name].resolvable is not None
|
all_resolvable &= self._variables[variable_name].resolvable is not None
|
||||||
|
|
||||||
if not all_resolvable:
|
if not all_resolvable:
|
||||||
# TODO: is this ever possible?
|
self._validate(added_variables=set(list(variables.keys())))
|
||||||
self._validate()
|
|
||||||
|
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -153,9 +153,6 @@ class TestPrebuiltTVShowPresets:
|
||||||
is_youtube_channel: bool,
|
is_youtube_channel: bool,
|
||||||
is_many_urls: bool,
|
is_many_urls: bool,
|
||||||
):
|
):
|
||||||
# yappi.set_clock_type("wall") # Use set_clock_type("wall") for wall time
|
|
||||||
# yappi.start()
|
|
||||||
|
|
||||||
expected_summary_name = "unit/{}/{}/is_yt_{}{}".format(
|
expected_summary_name = "unit/{}/{}/is_yt_{}{}".format(
|
||||||
media_player_preset,
|
media_player_preset,
|
||||||
tv_show_structure_preset,
|
tv_show_structure_preset,
|
||||||
|
|
@ -183,6 +180,9 @@ class TestPrebuiltTVShowPresets:
|
||||||
preset_dict=preset_dict,
|
preset_dict=preset_dict,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# yappi.set_clock_type("wall") # Use set_clock_type("wall") for wall time
|
||||||
|
# yappi.start()
|
||||||
|
|
||||||
with mock_download_collection_entries(
|
with mock_download_collection_entries(
|
||||||
is_youtube_channel=is_youtube_channel, num_urls=2 if is_many_urls else 1
|
is_youtube_channel=is_youtube_channel, num_urls=2 if is_many_urls else 1
|
||||||
):
|
):
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue