mirror of
https://github.com/koloideal/Argenta.git
synced 2026-06-10 01:55:29 +03:00
pretty gifff
This commit is contained in:
@@ -9,7 +9,7 @@ Argenta is the **"Simplest"**, **"Most Modular"**, and **"Most Elegant"** way to
|
||||
|
||||
---
|
||||
|
||||

|
||||

|
||||
|
||||
**Argenta** allows you to build interactive CLI applications incredibly easily. There's no need to manually parse complex command structures or manage state transitions — just use routers and commands!
|
||||
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ Argenta — это **"Самый простой"**, **"Самый модульн
|
||||
|
||||
---
|
||||
|
||||

|
||||

|
||||
|
||||
**Argenta** позволяет создавать интерактивные CLI-приложения невероятно легко. Не нужно вручную парсить сложные структуры команд или управлять переходами состояний — просто используйте роутеры и команды!
|
||||
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
from .benchmarks.pre_cycle_setup import *
|
||||
+10
-1
@@ -1,10 +1,19 @@
|
||||
from metrics.utils import attempts_to_average
|
||||
from .registry import Benchmarks, Benchmark
|
||||
|
||||
|
||||
def main():
|
||||
all_benchmarks: list[Benchmark] = Benchmarks.get_benchmarks()
|
||||
|
||||
for benchmark in all_benchmarks: pass
|
||||
for benchmark in all_benchmarks:
|
||||
bench_attempts: list[float] = []
|
||||
for _ in range(benchmark.iterations):
|
||||
bench_attempts.append(benchmark.run())
|
||||
|
||||
print(f'Name: {benchmark.name}\n'
|
||||
f'Description: {benchmark.description}\n'
|
||||
f'Iterations: {benchmark.iterations}\n'
|
||||
f'Average time per iteration: {attempts_to_average(bench_attempts, benchmark.iterations)} ms\n')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
__all__ = [
|
||||
"benchmark_no_aliases",
|
||||
"benchmark_many_aliases",
|
||||
"benchmark_few_aliases",
|
||||
"benchmark_extreme_aliases",
|
||||
"benchmark_very_many_aliases"
|
||||
]
|
||||
|
||||
from argenta import App
|
||||
from argenta.router import Router
|
||||
from argenta.command.models import Command
|
||||
|
||||
+1
-1
@@ -23,7 +23,7 @@ class Benchmark:
|
||||
self.description = description
|
||||
self.iterations = iterations
|
||||
|
||||
def __call__(self) -> float:
|
||||
def run(self) -> float:
|
||||
return self.func()
|
||||
|
||||
@override
|
||||
|
||||
+6
-5
@@ -1,22 +1,23 @@
|
||||
__all__ = [
|
||||
"get_time_of_pre_cycle_setup",
|
||||
"attempts_to_average"
|
||||
]
|
||||
|
||||
import io
|
||||
from contextlib import redirect_stdout
|
||||
import time
|
||||
from decimal import Decimal, ROUND_HALF_UP
|
||||
|
||||
from argenta import App
|
||||
|
||||
|
||||
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.monotonic()
|
||||
with redirect_stdout(io.StringIO()):
|
||||
app._pre_cycle_setup() # pyright: ignore[reportPrivateUsage]
|
||||
end = time.monotonic()
|
||||
return end - start
|
||||
|
||||
|
||||
def attempts_to_average(bench_attempts: list[float], iterations: int) -> Decimal:
|
||||
return Decimal(sum(bench_attempts) / iterations).quantize(Decimal("0.00001"), rounding=ROUND_HALF_UP)
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
from argenta.app import App
|
||||
from argenta.command import Command
|
||||
from argenta.metrics import get_time_of_pre_cycle_setup
|
||||
from argenta.response import Response
|
||||
from argenta.router import Router
|
||||
|
||||
|
||||
def commands_with_two_aliases(num_of_commands: int):
|
||||
router = Router()
|
||||
|
||||
for i in range(num_of_commands):
|
||||
@router.command(Command(f'cmd{i}', aliases=[f'cdr{i}', f'prt{i}']))
|
||||
def handler(response: Response): # pyright: ignore[reportUnusedFunction, reportUnusedParameter]
|
||||
pass
|
||||
|
||||
app = App()
|
||||
app.include_router(router)
|
||||
|
||||
return get_time_of_pre_cycle_setup(app)
|
||||
|
||||
def commands_with_one_aliases(num_of_commands: int):
|
||||
router = Router()
|
||||
|
||||
for i in range(num_of_commands):
|
||||
@router.command(Command(f'cmd{i}', aliases=[f'cdr{i}']))
|
||||
def handler(response: Response): # pyright: ignore[reportUnusedFunction, reportUnusedParameter]
|
||||
pass
|
||||
|
||||
app = App()
|
||||
app.include_router(router)
|
||||
|
||||
return get_time_of_pre_cycle_setup(app)
|
||||
@@ -1,9 +1,10 @@
|
||||
# main.py
|
||||
from argenta import App, Orchestrator
|
||||
from argenta.app import DynamicDividingLine
|
||||
|
||||
from .routers import router
|
||||
|
||||
app: App = App()
|
||||
app: App = App(prompt='>>> ', dividing_line=DynamicDividingLine('~'))
|
||||
orchestrator: Orchestrator = Orchestrator()
|
||||
|
||||
def main() -> None:
|
||||
|
||||
@@ -339,9 +339,6 @@ class BaseApp:
|
||||
|
||||
self._autocompleter.initial_setup(self.registered_routers.get_triggers())
|
||||
|
||||
if not self._override_system_messages:
|
||||
self._setup_default_view()
|
||||
|
||||
self._print_func(self._initial_message)
|
||||
|
||||
for message in self._messages_on_startup:
|
||||
@@ -382,7 +379,7 @@ DEFAULT_DIVIDING_LINE: StaticDividingLine = StaticDividingLine()
|
||||
|
||||
DEFAULT_PRINT_FUNC: Printer = Console().print
|
||||
DEFAULT_AUTOCOMPLETER: AutoCompleter = AutoCompleter()
|
||||
DEFAULT_EXIT_COMMAND: Command = Command("Q", description="Exit command")
|
||||
DEFAULT_EXIT_COMMAND: Command = Command("q", description="Exit command")
|
||||
|
||||
|
||||
class App(BaseApp):
|
||||
@@ -427,6 +424,8 @@ class App(BaseApp):
|
||||
autocompleter=autocompleter,
|
||||
print_func=print_func,
|
||||
)
|
||||
if not self._override_system_messages:
|
||||
self._setup_default_view()
|
||||
|
||||
def run_polling(self) -> None:
|
||||
"""
|
||||
|
||||
@@ -361,8 +361,6 @@ def test_set_exit_command_handler_stores_handler() -> None:
|
||||
|
||||
def test_setup_default_view_formats_prompt() -> None:
|
||||
app = App(prompt='>>')
|
||||
app._setup_default_view()
|
||||
|
||||
assert app._prompt == '[italic dim bold]>>'
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user