mirror of
https://github.com/koloideal/Argenta.git
synced 2026-06-10 18:15:28 +03:00
make pre_cycle_setup faster on 4 sec, start implemtnation disable redirect stdout in router
This commit is contained in:
+3
-1
@@ -13,7 +13,7 @@ router = Router()
|
|||||||
for i in range(10000):
|
for i in range(10000):
|
||||||
trigger = f"cmd{i}"
|
trigger = f"cmd{i}"
|
||||||
|
|
||||||
@router.command(Command(trigger, aliases=[f'dfs{i}', f'fds{i}']))
|
@router.command(Command(trigger, aliases=[f'dfs{i}']))
|
||||||
def handler(response: Response):
|
def handler(response: Response):
|
||||||
print(response.status)
|
print(response.status)
|
||||||
|
|
||||||
@@ -30,3 +30,5 @@ print(get_time_of_pre_cycle_setup(app))
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ from argenta.response import Response
|
|||||||
from argenta.router import Router
|
from argenta.router import Router
|
||||||
|
|
||||||
|
|
||||||
work_router: Router = Router(title="Work points:")
|
work_router: Router = Router(title="Work points:", disable_redirect_stdout=True)
|
||||||
|
|
||||||
console = Console()
|
console = Console()
|
||||||
|
|
||||||
@@ -21,6 +21,8 @@ console = Console()
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
def command_help(response: Response):
|
def command_help(response: Response):
|
||||||
|
case = input('test')
|
||||||
|
print(case)
|
||||||
print(response.status)
|
print(response.status)
|
||||||
print(response.undefined_flags.get_flags())
|
print(response.undefined_flags.get_flags())
|
||||||
print(response.valid_flags.get_flags())
|
print(response.valid_flags.get_flags())
|
||||||
|
|||||||
@@ -26,3 +26,8 @@ exclude = [
|
|||||||
requires = ["hatchling"]
|
requires = ["hatchling"]
|
||||||
build-backend = "hatchling.build"
|
build-backend = "hatchling.build"
|
||||||
|
|
||||||
|
[dependency-groups]
|
||||||
|
dev = [
|
||||||
|
"pandas>=2.0.3",
|
||||||
|
]
|
||||||
|
|
||||||
|
|||||||
+22
-11
@@ -302,22 +302,30 @@ class BaseApp:
|
|||||||
self._setup_system_router()
|
self._setup_system_router()
|
||||||
|
|
||||||
for router_entity in self._registered_routers:
|
for router_entity in self._registered_routers:
|
||||||
self._all_registered_triggers_in_default_case.extend(router_entity.get_triggers())
|
router_triggers = router_entity.get_triggers()
|
||||||
self._all_registered_triggers_in_default_case.extend(router_entity.get_aliases())
|
router_aliases = router_entity.get_aliases()
|
||||||
|
combined = router_triggers + router_aliases
|
||||||
|
|
||||||
self._all_registered_triggers_in_lower_case.extend([x.lower() for x in router_entity.get_triggers()])
|
self._all_registered_triggers_in_default_case.extend(combined)
|
||||||
self._all_registered_triggers_in_lower_case.extend([x.lower() for x in router_entity.get_aliases()])
|
|
||||||
|
self._all_registered_triggers_in_lower_case.extend(x.lower() for x in combined)
|
||||||
|
|
||||||
self._autocompleter.initial_setup(self._all_registered_triggers_in_lower_case)
|
self._autocompleter.initial_setup(self._all_registered_triggers_in_lower_case)
|
||||||
|
|
||||||
if self._ignore_command_register:
|
if self._ignore_command_register:
|
||||||
for cmd in set(self._all_registered_triggers_in_lower_case):
|
seen = {}
|
||||||
if self._all_registered_triggers_in_lower_case.count(cmd) != 1:
|
for item in self._all_registered_triggers_in_lower_case:
|
||||||
Console().print(f"\n[b red]WARNING:[/b red] Overlapping trigger or alias: [b blue]{cmd}[/b blue]")
|
if item in seen:
|
||||||
|
Console().print(f"\n[b red]WARNING:[/b red] Overlapping trigger or alias: [b blue]{item}[/b blue]")
|
||||||
else:
|
else:
|
||||||
for cmd in set(self._all_registered_triggers_in_default_case):
|
seen[item] = True
|
||||||
if self._all_registered_triggers_in_default_case.count(cmd) != 1:
|
else:
|
||||||
Console().print(f"\n[b red]WARNING:[/b red] Overlapping trigger or alias: [b blue]{cmd}[/b blue]")
|
seen = {}
|
||||||
|
for item in self._all_registered_triggers_in_default_case:
|
||||||
|
if item in seen:
|
||||||
|
Console().print(f"\n[b red]WARNING:[/b red] Overlapping trigger or alias: [b blue]{item}[/b blue]")
|
||||||
|
else:
|
||||||
|
seen[item] = True
|
||||||
|
|
||||||
if not self._override_system_messages:
|
if not self._override_system_messages:
|
||||||
self._setup_default_view()
|
self._setup_default_view()
|
||||||
@@ -415,8 +423,11 @@ class App(BaseApp):
|
|||||||
self._print_framed_text(res)
|
self._print_framed_text(res)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
with redirect_stdout(io.StringIO()) as f:
|
|
||||||
for registered_router in self._registered_routers:
|
for registered_router in self._registered_routers:
|
||||||
|
if registered_router.disable_redirect_stdout:
|
||||||
|
registered_router.finds_appropriate_handler(input_command)
|
||||||
|
else:
|
||||||
|
with redirect_stdout(io.StringIO()) as f:
|
||||||
registered_router.finds_appropriate_handler(input_command)
|
registered_router.finds_appropriate_handler(input_command)
|
||||||
res: str = f.getvalue()
|
res: str = f.getvalue()
|
||||||
self._print_framed_text(res)
|
self._print_framed_text(res)
|
||||||
|
|||||||
@@ -2,15 +2,15 @@ import io
|
|||||||
from contextlib import redirect_stdout
|
from contextlib import redirect_stdout
|
||||||
from time import time
|
from time import time
|
||||||
|
|
||||||
from argenta.router import Router
|
|
||||||
from argenta.command import Command
|
|
||||||
from argenta.response import Response
|
|
||||||
from argenta.response.status import Status
|
|
||||||
from argenta.command.flag import Flag, Flags
|
|
||||||
from argenta.app import App
|
from argenta.app import App
|
||||||
|
|
||||||
|
|
||||||
def get_time_of_pre_cycle_setup(app: App) -> float:
|
def get_time_of_pre_cycle_setup(app: App) -> float:
|
||||||
|
"""
|
||||||
|
Public. Return time of pre cycle setup
|
||||||
|
:param app: app instance for testing time of pre cycle setup
|
||||||
|
:return: time of pre cycle setup as float
|
||||||
|
"""
|
||||||
start = time()
|
start = time()
|
||||||
with redirect_stdout(io.StringIO()):
|
with redirect_stdout(io.StringIO()):
|
||||||
app.pre_cycle_setup()
|
app.pre_cycle_setup()
|
||||||
|
|||||||
@@ -22,13 +22,19 @@ from argenta.router.exceptions import (
|
|||||||
|
|
||||||
|
|
||||||
class Router:
|
class Router:
|
||||||
def __init__(self, title: str | None = "Awesome title"):
|
def __init__(self, title: str | None = "Awesome title", disable_redirect_stdout: bool = False):
|
||||||
"""
|
"""
|
||||||
Public. Directly configures and manages handlers
|
Public. Directly configures and manages handlers
|
||||||
:param title: the title of the router, displayed when displaying the available commands
|
:param title: the title of the router, displayed when displaying the available commands
|
||||||
|
:param disable_redirect_stdout: Disables stdout forwarding, if the argument value is True,
|
||||||
|
the StaticDividingLine will be forced to be used as a line separator for this router,
|
||||||
|
disabled forwarding is needed when there is text output in conjunction with a text input request (for example, input()),
|
||||||
|
if the argument value is True, the output of the input() prompt is intercepted and not displayed,
|
||||||
|
which is ambiguous behavior and can lead to unexpected work
|
||||||
:return: None
|
:return: None
|
||||||
"""
|
"""
|
||||||
self.title = title
|
self.title = title
|
||||||
|
self.disable_redirect_stdout = disable_redirect_stdout
|
||||||
|
|
||||||
self._command_handlers: CommandHandlers = CommandHandlers()
|
self._command_handlers: CommandHandlers = CommandHandlers()
|
||||||
self._ignore_command_register: bool = False
|
self._ignore_command_register: bool = False
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import re
|
|||||||
from argenta.app import App
|
from argenta.app import App
|
||||||
from argenta.command import Command
|
from argenta.command import Command
|
||||||
from argenta.router import Router
|
from argenta.router import Router
|
||||||
from argenta.command.flags.models import Flags
|
from argenta.command.flag.flags.models import Flags
|
||||||
from argenta.command.flag.defaults import PredefinedFlags
|
from argenta.command.flag.defaults import PredefinedFlags
|
||||||
from argenta.orchestrator import Orchestrator
|
from argenta.orchestrator import Orchestrator
|
||||||
from argenta.response import Response
|
from argenta.response import Response
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ from argenta.response import Response
|
|||||||
from argenta.router import Router
|
from argenta.router import Router
|
||||||
from argenta.orchestrator import Orchestrator
|
from argenta.orchestrator import Orchestrator
|
||||||
from argenta.command.flag import Flag
|
from argenta.command.flag import Flag
|
||||||
from argenta.command.flags import Flags
|
from argenta.command.flag.flags import Flags
|
||||||
from argenta.command.flag.defaults import PredefinedFlags
|
from argenta.command.flag.defaults import PredefinedFlags
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
from argenta.command.flag import Flag, InputFlag
|
from argenta.command.flag import Flag, InputFlag
|
||||||
from argenta.command.flags import Flags
|
from argenta.command.flag.flags import Flags
|
||||||
from argenta.command.models import InputCommand, Command
|
from argenta.command.models import InputCommand, Command
|
||||||
from argenta.command.exceptions import (UnprocessedInputFlagException,
|
from argenta.command.exceptions import (UnprocessedInputFlagException,
|
||||||
RepeatedInputFlagsException,
|
RepeatedInputFlagsException,
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
from argenta.command.flag import Flag, InputFlag
|
from argenta.command.flag import Flag, InputFlag
|
||||||
from argenta.command.flags import InputFlags, Flags
|
from argenta.command.flag.flags import InputFlags, Flags
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
import re
|
import re
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
from argenta.command.flag import InputFlag, Flag
|
from argenta.command.flag import InputFlag, Flag
|
||||||
from argenta.command.flags import Flags, InputFlags, UndefinedInputFlags, InvalidValueInputFlags, ValidInputFlags
|
from argenta.command.flag.flags import Flags, InputFlags, UndefinedInputFlags, InvalidValueInputFlags, ValidInputFlags
|
||||||
from argenta.router import Router
|
from argenta.router import Router
|
||||||
from argenta.command import Command
|
from argenta.command import Command
|
||||||
from argenta.router.exceptions import (TriggerContainSpacesException,
|
from argenta.router.exceptions import (TriggerContainSpacesException,
|
||||||
|
|||||||
Reference in New Issue
Block a user