override gen
This commit is contained in:
parent
709395fe4e
commit
1b2c449331
7 changed files with 445 additions and 361 deletions
|
|
@ -8,7 +8,7 @@ import mergedeep
|
|||
from ytdl_sub.entries.entry import Entry
|
||||
from ytdl_sub.entries.script.variable_definitions import VARIABLES
|
||||
from ytdl_sub.entries.variables.override_variables import SUBSCRIPTION_NAME
|
||||
from ytdl_sub.entries.variables.override_variables import OverrideVariables
|
||||
from ytdl_sub.entries.variables.override_variables import OverrideHelpers
|
||||
from ytdl_sub.script.parser import parse
|
||||
from ytdl_sub.script.script import Script
|
||||
from ytdl_sub.script.utils.exceptions import ScriptVariableNotResolved
|
||||
|
|
@ -89,7 +89,7 @@ class Overrides(DictFormatterValidator, Scriptable):
|
|||
"""
|
||||
Ensures the variable name does not collide with any entry variables or built-in functions.
|
||||
"""
|
||||
if not OverrideVariables.is_valid_name(name):
|
||||
if not OverrideHelpers.is_valid_name(name):
|
||||
override_type = "function" if name.startswith("%") else "variable"
|
||||
raise self._validation_exception(
|
||||
f"Override {override_type} with name {name} is invalid. Names must be"
|
||||
|
|
@ -97,14 +97,14 @@ class Overrides(DictFormatterValidator, Scriptable):
|
|||
exception_class=InvalidVariableNameException,
|
||||
)
|
||||
|
||||
if OverrideVariables.is_entry_variable_name(name):
|
||||
if OverrideHelpers.is_entry_variable_name(name):
|
||||
raise self._validation_exception(
|
||||
f"Override variable with name {name} cannot be used since it is a"
|
||||
" built-in ytdl-sub entry variable name.",
|
||||
exception_class=InvalidVariableNameException,
|
||||
)
|
||||
|
||||
if OverrideVariables.is_function_name(name):
|
||||
if OverrideHelpers.is_function_name(name):
|
||||
raise self._validation_exception(
|
||||
f"Override function definition with name {name} cannot be used since it is"
|
||||
" a built-in ytdl-sub function name.",
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -10,15 +10,15 @@ SUBSCRIPTION_ARRAY = "subscription_array"
|
|||
|
||||
|
||||
class OverrideVariables:
|
||||
@classmethod
|
||||
def subscription_name(cls) -> str:
|
||||
@staticmethod
|
||||
def subscription_name() -> str:
|
||||
"""
|
||||
Name of the subscription
|
||||
"""
|
||||
return SUBSCRIPTION_NAME
|
||||
|
||||
@classmethod
|
||||
def subscription_value(cls) -> str:
|
||||
@staticmethod
|
||||
def subscription_value() -> str:
|
||||
"""
|
||||
For subscriptions in the form of
|
||||
|
||||
|
|
@ -30,8 +30,8 @@ class OverrideVariables:
|
|||
"""
|
||||
return SUBSCRIPTION_VALUE
|
||||
|
||||
@classmethod
|
||||
def subscription_indent_i(cls, index: int) -> str:
|
||||
@staticmethod
|
||||
def subscription_indent_i(index: int) -> str:
|
||||
"""
|
||||
For subscriptions in the form of
|
||||
|
||||
|
|
@ -46,8 +46,8 @@ class OverrideVariables:
|
|||
"""
|
||||
return f"subscription_indent_{index + 1}"
|
||||
|
||||
@classmethod
|
||||
def subscription_value_i(cls, index: int) -> str:
|
||||
@staticmethod
|
||||
def subscription_value_i(index: int) -> str:
|
||||
"""
|
||||
For subscriptions in the form of
|
||||
|
||||
|
|
@ -63,6 +63,8 @@ class OverrideVariables:
|
|||
"""
|
||||
return f"subscription_value_{index + 1}"
|
||||
|
||||
|
||||
class OverrideHelpers:
|
||||
@classmethod
|
||||
def is_entry_variable_name(cls, name: str) -> bool:
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -1,14 +1,39 @@
|
|||
from typing import Any
|
||||
from typing import Dict
|
||||
from typing import Type
|
||||
|
||||
from tools.docgen.utils import camel_case_to_human
|
||||
from tools.docgen.utils import get_function_docs
|
||||
from tools.docgen.utils import properties
|
||||
from tools.docgen.utils import section
|
||||
from ytdl_sub.entries.script.variable_definitions import VariableDefinitions
|
||||
|
||||
|
||||
def variable_class_to_name(obj: Type[Any]) -> str:
|
||||
assert "VariableDefinitions" in obj.__name__, f"{obj.__name__} doesnt have VariableDefinitions"
|
||||
return (
|
||||
camel_case_to_human(obj.__name__)
|
||||
.replace("Variable Definitions", "Variables")
|
||||
.replace("Ytdl Sub", "Ytdl-Sub")
|
||||
)
|
||||
|
||||
|
||||
def generate_variable_docs() -> str:
|
||||
docs = section("Entry Variables", level=0)
|
||||
|
||||
for variable_name in properties(VariableDefinitions):
|
||||
docs += get_function_docs(function_name=variable_name, obj=VariableDefinitions, level=1)
|
||||
parent_objs: Dict[str, Type[Any]] = {
|
||||
variable_class_to_name(obj): obj for obj in VariableDefinitions.__bases__
|
||||
}
|
||||
|
||||
for name in sorted(parent_objs.keys()):
|
||||
docs += section(name, level=1)
|
||||
|
||||
for variable_function_name in properties(parent_objs[name]):
|
||||
docs += get_function_docs(
|
||||
function_name=variable_function_name,
|
||||
obj=parent_objs[name],
|
||||
level=2,
|
||||
)
|
||||
|
||||
return docs
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ from typing import Dict
|
|||
from typing import Optional
|
||||
from typing import Type
|
||||
|
||||
from tools.docgen.utils import camel_case_to_human
|
||||
from tools.docgen.utils import get_function_docs
|
||||
from tools.docgen.utils import section
|
||||
from tools.docgen.utils import static_methods
|
||||
|
|
@ -21,7 +22,7 @@ def maybe_get_function_name(function_name: str) -> Optional[str]:
|
|||
|
||||
def function_class_to_name(obj: Type[Any]) -> str:
|
||||
assert "Functions" in obj.__name__
|
||||
return obj.__name__.replace("Functions", " Functions")
|
||||
return camel_case_to_human(obj.__name__)
|
||||
|
||||
|
||||
def generate_function_docs() -> str:
|
||||
|
|
|
|||
20
tools/docgen/override_variables.py
Normal file
20
tools/docgen/override_variables.py
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
from tools.docgen.utils import get_function_docs
|
||||
from tools.docgen.utils import section
|
||||
from tools.docgen.utils import static_methods
|
||||
from ytdl_sub.entries.variables.override_variables import OverrideVariables
|
||||
|
||||
|
||||
def generate_override_docs() -> str:
|
||||
docs = section("Override Variables", level=0)
|
||||
|
||||
for name in static_methods(OverrideVariables):
|
||||
docs += get_function_docs(
|
||||
function_name=name,
|
||||
obj=OverrideVariables,
|
||||
level=1,
|
||||
)
|
||||
|
||||
return docs
|
||||
|
||||
|
||||
print(generate_override_docs())
|
||||
|
|
@ -13,7 +13,7 @@ def section(name: str, level: int) -> str:
|
|||
|
||||
|
||||
def properties(obj: Type[Any]) -> List[str]:
|
||||
return [prop for prop in dir(obj) if isinstance(getattr(obj, prop), property)]
|
||||
return sorted(prop for prop in dir(obj) if isinstance(getattr(obj, prop), property))
|
||||
|
||||
|
||||
def static_methods(obj: Type[Any]) -> List[str]:
|
||||
|
|
@ -22,6 +22,17 @@ def static_methods(obj: Type[Any]) -> List[str]:
|
|||
)
|
||||
|
||||
|
||||
def camel_case_to_human(string: str) -> str:
|
||||
output_str = string[0]
|
||||
for char in string[1:]:
|
||||
if char.islower():
|
||||
output_str += char
|
||||
else:
|
||||
output_str += f" {char}"
|
||||
|
||||
return output_str
|
||||
|
||||
|
||||
def get_function_docs(
|
||||
function_name: str, obj: Any, level: int, display_function_name: Optional[str] = None
|
||||
) -> str:
|
||||
|
|
|
|||
Loading…
Reference in a new issue