bless yappi
This commit is contained in:
parent
fb58941ff5
commit
72eeb4443f
6 changed files with 27 additions and 37 deletions
|
|
@ -180,7 +180,7 @@ class Preset(_PresetShell):
|
||||||
return added_variables
|
return added_variables
|
||||||
|
|
||||||
@functools.cached_property
|
@functools.cached_property
|
||||||
def _cached_script_builder(self) -> ScriptBuilder:
|
def _script_builder(self) -> ScriptBuilder:
|
||||||
# Set the formatter variables to be the overrides
|
# Set the formatter variables to be the overrides
|
||||||
script = ScriptBuilder(
|
script = ScriptBuilder(
|
||||||
Scriptable.add_sanitized_variables(self.overrides.dict_with_format_strings)
|
Scriptable.add_sanitized_variables(self.overrides.dict_with_format_strings)
|
||||||
|
|
@ -194,28 +194,16 @@ class Preset(_PresetShell):
|
||||||
_ = script.partial_build()
|
_ = script.partial_build()
|
||||||
return script
|
return script
|
||||||
|
|
||||||
@property
|
|
||||||
def _script_builder(self) -> ScriptBuilder:
|
|
||||||
return copy.deepcopy(self._cached_script_builder)
|
|
||||||
|
|
||||||
@functools.cached_property
|
@functools.cached_property
|
||||||
def _script_builder_with_added_variables(self) -> ScriptBuilder:
|
def _script(self) -> Script:
|
||||||
|
"""
|
||||||
|
Contains actualized script which should hold all Override variables
|
||||||
|
"""
|
||||||
return self._script_builder.add(
|
return self._script_builder.add(
|
||||||
Scriptable.add_sanitized_variables(
|
Scriptable.add_sanitized_variables(
|
||||||
{source_var: "dummy_string" for source_var in self._added_variables}
|
{source_var: "dummy_string" for source_var in self._added_variables}
|
||||||
)
|
)
|
||||||
)
|
).partial_build()
|
||||||
|
|
||||||
@functools.cached_property
|
|
||||||
def _cached_script(self) -> Script:
|
|
||||||
"""
|
|
||||||
Contains actualized script which should hold all Override variables
|
|
||||||
"""
|
|
||||||
return self._script_builder_with_added_variables.partial_build()
|
|
||||||
|
|
||||||
@property
|
|
||||||
def _script(self) -> Script:
|
|
||||||
return copy.deepcopy(self._cached_script)
|
|
||||||
|
|
||||||
def __validate_and_get_plugins(self) -> PresetPlugins:
|
def __validate_and_get_plugins(self) -> PresetPlugins:
|
||||||
preset_plugins = PresetPlugins()
|
preset_plugins = PresetPlugins()
|
||||||
|
|
@ -232,8 +220,8 @@ class Preset(_PresetShell):
|
||||||
return preset_plugins
|
return preset_plugins
|
||||||
|
|
||||||
def __validate_added_variables(self):
|
def __validate_added_variables(self):
|
||||||
script_builder = self._script_builder
|
script_builder = copy.deepcopy(self._script_builder)
|
||||||
self.downloader_options.validate_with_variables(script=copy.deepcopy(script_builder))
|
self.downloader_options.validate_with_variables(script=script_builder.partial_build())
|
||||||
script_builder.add(
|
script_builder.add(
|
||||||
Scriptable.add_sanitized_variables(
|
Scriptable.add_sanitized_variables(
|
||||||
{name: "dummy_string" for name in self.downloader_options.added_source_variables()}
|
{name: "dummy_string" for name in self.downloader_options.added_source_variables()}
|
||||||
|
|
@ -244,7 +232,7 @@ class Preset(_PresetShell):
|
||||||
self.plugins.zipped(), key=lambda pl: pl[0].priority.modify_entry
|
self.plugins.zipped(), key=lambda pl: pl[0].priority.modify_entry
|
||||||
):
|
):
|
||||||
# Validate current plugin using source + added plugin variables
|
# Validate current plugin using source + added plugin variables
|
||||||
plugin_options.validate_with_variables(script=copy.deepcopy(script_builder))
|
plugin_options.validate_with_variables(script=script_builder.partial_build())
|
||||||
script_builder.add(
|
script_builder.add(
|
||||||
Scriptable.add_sanitized_variables(
|
Scriptable.add_sanitized_variables(
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,7 @@ class OptionsValidator(Validator, ABC):
|
||||||
"""
|
"""
|
||||||
return []
|
return []
|
||||||
|
|
||||||
def validate_with_variables(self, script: ScriptBuilder) -> None:
|
def validate_with_variables(self, script: Script) -> None:
|
||||||
"""
|
"""
|
||||||
Optional validation after init with the session's source and override variables.
|
Optional validation after init with the session's source and override variables.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -253,21 +253,19 @@ class MultiUrlValidator(OptionsValidator):
|
||||||
"""
|
"""
|
||||||
return list(self._urls.list[0].variables.keys)
|
return list(self._urls.list[0].variables.keys)
|
||||||
|
|
||||||
def validate_with_variables(self, script: ScriptBuilder) -> None:
|
def validate_with_variables(self, script: Script) -> None:
|
||||||
"""
|
"""
|
||||||
Ensures new variables added are not existing variables
|
Ensures new variables added are not existing variables
|
||||||
"""
|
"""
|
||||||
# Apply formatting to each new source variable, ensure it resolves
|
# Apply formatting to each new source variable, ensure it resolves
|
||||||
for collection_url in self.urls.list:
|
for collection_url in self.urls.list:
|
||||||
script.add(collection_url.variables.dict_with_format_strings)
|
for name, definition in collection_url.variables.dict_with_format_strings.items():
|
||||||
|
script.is_resolvable(variable_name=name, variable_definition=definition)
|
||||||
resolved_script = script.partial_build()
|
|
||||||
|
|
||||||
# Ensure at least URL is non-empty
|
# Ensure at least URL is non-empty
|
||||||
has_non_empty_url = False
|
has_non_empty_url = False
|
||||||
for url_validator in self.urls.list:
|
for url_validator in self.urls.list:
|
||||||
resolved_script.add({"tmp_var_url": url_validator.url.format_string})
|
has_non_empty_url |= bool(str(script.is_resolvable(url_validator.url.format_string)))
|
||||||
has_non_empty_url |= bool(str(resolved_script.resolve().get_native("tmp_var_url")))
|
|
||||||
|
|
||||||
if not has_non_empty_url:
|
if not has_non_empty_url:
|
||||||
raise self._validation_exception("Must contain at least one url that is non-empty")
|
raise self._validation_exception("Must contain at least one url that is non-empty")
|
||||||
|
|
|
||||||
|
|
@ -212,7 +212,7 @@ class RegexOptions(OptionsDictValidator):
|
||||||
"""
|
"""
|
||||||
return self._skip_if_match_fails
|
return self._skip_if_match_fails
|
||||||
|
|
||||||
def validate_with_variables(self, script: ScriptBuilder) -> None:
|
def validate_with_variables(self, script: Script) -> None:
|
||||||
for key, regex_options in self.source_variable_capture_dict.items():
|
for key, regex_options in self.source_variable_capture_dict.items():
|
||||||
# Ensure each variable getting captured is a source variable
|
# Ensure each variable getting captured is a source variable
|
||||||
if key not in script._variables:
|
if key not in script._variables:
|
||||||
|
|
|
||||||
|
|
@ -281,14 +281,13 @@ class Script:
|
||||||
)
|
)
|
||||||
|
|
||||||
unresolvable: Set[Variable] = {Variable(name) for name in (unresolvable or {})}
|
unresolvable: Set[Variable] = {Variable(name) for name in (unresolvable or {})}
|
||||||
|
unresolved_filter = set(resolved.keys()).union(unresolvable)
|
||||||
unresolved: Dict[Variable, SyntaxTree] = {
|
unresolved: Dict[Variable, SyntaxTree] = {
|
||||||
Variable(name): ast
|
Variable(name): ast
|
||||||
for name, ast in self._variables.items()
|
for name, ast in self._variables.items()
|
||||||
if Variable(name) not in set(resolved.keys()).union(unresolvable)
|
if Variable(name) not in unresolved_filter
|
||||||
}
|
}
|
||||||
|
|
||||||
tmp = 0
|
|
||||||
|
|
||||||
while unresolved:
|
while unresolved:
|
||||||
unresolved_count: int = len(unresolved)
|
unresolved_count: int = len(unresolved)
|
||||||
|
|
||||||
|
|
@ -354,17 +353,19 @@ class Script:
|
||||||
def is_resolvable(
|
def is_resolvable(
|
||||||
self,
|
self,
|
||||||
variable_definition: str,
|
variable_definition: str,
|
||||||
|
variable_name: Optional[str] = None,
|
||||||
resolved: Optional[Dict[str, Resolvable]] = None,
|
resolved: Optional[Dict[str, Resolvable]] = None,
|
||||||
unresolvable: Optional[Set[str]] = None,
|
unresolvable: Optional[Set[str]] = None,
|
||||||
) -> Resolvable:
|
) -> Resolvable:
|
||||||
|
var_name = variable_name if variable_name else "tmp_var"
|
||||||
try:
|
try:
|
||||||
self.add({"tmp_var": variable_definition})
|
self.add({var_name: variable_definition})
|
||||||
return self._resolve(
|
return self._resolve(
|
||||||
resolved=resolved, unresolvable=unresolvable, output_filter={"tmp_var"}
|
resolved=resolved, unresolvable=unresolvable, output_filter={var_name}
|
||||||
).get("tmp_var")
|
).get(var_name)
|
||||||
finally:
|
finally:
|
||||||
if "tmp_var" in self._variables:
|
if var_name in self._variables:
|
||||||
del self._variables["tmp_var"]
|
del self._variables[var_name]
|
||||||
|
|
||||||
def get(self, variable_name: str) -> Resolvable:
|
def get(self, variable_name: str) -> Resolvable:
|
||||||
if variable_name not in self._variables:
|
if variable_name not in self._variables:
|
||||||
|
|
|
||||||
|
|
@ -66,6 +66,8 @@ class TestPrebuiltTVShowPresets:
|
||||||
media_player_preset: str,
|
media_player_preset: str,
|
||||||
tv_show_structure_preset: str,
|
tv_show_structure_preset: str,
|
||||||
):
|
):
|
||||||
|
# yappi.set_clock_type("cpu") # Use set_clock_type("wall") for wall time
|
||||||
|
# yappi.start()
|
||||||
parent_presets = _tv_show_by_date_parent_presets(
|
parent_presets = _tv_show_by_date_parent_presets(
|
||||||
all_in_one_preset, media_player_preset, tv_show_structure_preset
|
all_in_one_preset, media_player_preset, tv_show_structure_preset
|
||||||
)
|
)
|
||||||
|
|
@ -82,6 +84,7 @@ class TestPrebuiltTVShowPresets:
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
# yappi.get_func_stats().print_all()
|
||||||
|
|
||||||
def test_compilation_many_urls(
|
def test_compilation_many_urls(
|
||||||
self,
|
self,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue