Compare commits
172 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 77416cf22c | |||
| b6c84f1a91 | |||
| c2d235e576 | |||
| f7f5db58aa | |||
| 73303b1c08 | |||
| 22f1171192 | |||
| a844095fdc | |||
| a7c6a14705 | |||
| cfdb37330e | |||
| aef6a9ca38 | |||
| c8e0729be8 | |||
| c2bbc5f15d | |||
| 0acbf54e44 | |||
| c3d9541330 | |||
| f6561de9b3 | |||
| bebd84969b | |||
| 365347ea7f | |||
| 33cb528b1d | |||
| fd287c5da0 | |||
| 45f410e3e8 | |||
| 8b06e9cd39 | |||
| c38fe10006 | |||
| 03cbc64f48 | |||
| cbf7d3c578 | |||
| ea2d068022 | |||
| 5991851207 | |||
| f628c3b5b5 | |||
| 05379712f4 | |||
| ed1cbf0fcf | |||
| 471f05369b | |||
| 13f7e33db1 | |||
| 9a78aa9263 | |||
| 58ccd6b26d | |||
| 73144f7ba4 | |||
| 650f4c9036 | |||
| 393f5c7d81 | |||
| 9eb2bb6c46 | |||
| 79b275eac7 | |||
| 07ac2af71e | |||
| c4b3aa7db8 | |||
| 61ef6a6466 | |||
| 477f3a7dec | |||
| adf3431388 | |||
| 83955aa046 | |||
| 5a17e916eb | |||
| 1159dda16e | |||
| 315508a36e | |||
| 9d6598c4e0 | |||
| eb43806da6 | |||
| e076dbf84f | |||
| 2f090b6b47 | |||
| c9dbf2bbae | |||
| e768c1bd2c | |||
| 408450ec12 | |||
| 106ca058be | |||
| b5ddfb3b35 | |||
| 61e4502e41 | |||
| 9b2fc87e33 | |||
| 89f09c42f8 | |||
| 5bcae8fe68 | |||
| ca58008431 | |||
| 30974f48eb | |||
| df4ba080b0 | |||
| f93930d712 | |||
| 036c17ec9a | |||
| 7281fdeabf | |||
| 051ec6df28 | |||
| 00a1e11fc1 | |||
| 584df9ba69 | |||
| a649022f1d | |||
| 26a9d8a6da | |||
| 9522b0161a | |||
| e189f8d9aa | |||
| 3ef8707cfa | |||
| a5fdcab862 | |||
| ba035881ee | |||
| 34ebe55531 | |||
| 01c9d2dc6d | |||
| a6db733204 | |||
| 8506e4ffcf | |||
| 04d3329572 | |||
| 5bfdde4bd9 | |||
| e2dd7e4aea | |||
| d1d644d422 | |||
| 8b496aa782 | |||
| 592d128ef6 | |||
| b44ee227fd | |||
| 0dce4a0d9e | |||
| ca6634c6f0 | |||
| c1805af420 | |||
| 0e308ce77f | |||
| ab1d335f8e | |||
| 1a2e9d1487 | |||
| 76bcba9340 | |||
| ae9795bd53 | |||
| 7540728f1b | |||
| 54da63dd03 | |||
| 8e08d0fe09 | |||
| 55b88f7c8a | |||
| 1cd616336f | |||
| 253790fe2e | |||
| 1c6f896b73 | |||
| 8810e12551 | |||
| 285007a59a | |||
| 6edd17646a | |||
| 154ee25dde | |||
| 30cf3cfd06 | |||
| 0d98d80919 | |||
| 54992e55cb | |||
| cc8135b733 | |||
| 5c6fa5151a | |||
| 2918bc9f81 | |||
| 6e2fbc23e9 | |||
| 1ec8ea53b4 | |||
| 4256d67789 | |||
| 0246ff4b22 | |||
| 956febc757 | |||
| beafdd0afd | |||
| b172e2cdc3 | |||
| baaf0e25f3 | |||
| 09c40978a1 | |||
| 0f4f48555e | |||
| d30515c1a2 | |||
| 5a6fc1d8ca | |||
| e5d6ead38e | |||
| b61c151e1c | |||
| a57ce490c1 | |||
| edbd45f0bf | |||
| d59d274bca | |||
| 2bf2144815 | |||
| 971258728c | |||
| 2c9c8da13c | |||
| 404758bd91 | |||
| 8fbf651223 | |||
| 459c16ec87 | |||
| d9c74310c3 | |||
| 5e6cdc342e | |||
| a378163431 | |||
| fd4f2e1570 | |||
| 3f7c577c29 | |||
| b72fcc6a11 | |||
| 158e5eb75a | |||
| 46cb2f70c5 | |||
| ef242a5732 | |||
| f87f102ced | |||
| ddf2a2fb10 | |||
| eac5358ead | |||
| 76c18ddbff | |||
| 4eeb4eb182 | |||
| 905698384a | |||
| 79ccfbb3b1 | |||
| a63c46a78b | |||
| a3a7cbf2e6 | |||
| a9e545f3d8 | |||
| 37b62fd69b | |||
| 0ae86d0b2b | |||
| ebfd5a80b3 | |||
| 250704fc88 | |||
| 87239f1501 | |||
| 48c117dd72 | |||
| 1d782f6213 | |||
| ddf396a644 | |||
| c10af04280 | |||
| 890d863391 | |||
| 29b184b2ed | |||
| 6d331a57c1 | |||
| b0eb1e3e6c | |||
| 2d088caaaf | |||
| b4b7d5442c | |||
| 684760121c | |||
| dfc3c472ce | |||
| 8a3f742636 |
@@ -0,0 +1,31 @@
|
||||
name: mypy
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ "main" ]
|
||||
pull_request:
|
||||
branches: [ "main" ]
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- uses: actions/setup-python@v3
|
||||
with:
|
||||
python-version: "3.13"
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
pip install mypy
|
||||
pip install .
|
||||
|
||||
- name: Run type checker
|
||||
run: mypy -p argenta
|
||||
@@ -0,0 +1,30 @@
|
||||
name: ruff
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ "main" ]
|
||||
pull_request:
|
||||
branches: [ "main" ]
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- uses: actions/setup-python@v3
|
||||
with:
|
||||
python-version: "3.13"
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
pip install ruff
|
||||
|
||||
- name: Run linter
|
||||
run: ruff check ./src
|
||||
@@ -0,0 +1,31 @@
|
||||
name: tests
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ "main" ]
|
||||
pull_request:
|
||||
branches: [ "main" ]
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- uses: actions/setup-python@v3
|
||||
with:
|
||||
python-version: "3.13"
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
pip install uv
|
||||
uv sync --group dev
|
||||
|
||||
- name: Run tests
|
||||
run: uv run python -m unittest discover
|
||||
@@ -1,14 +1,10 @@
|
||||
.venv
|
||||
*venv
|
||||
.idea
|
||||
argenta/router/__pycache__/
|
||||
argenta/app/__pycache__/
|
||||
argenta/__pycache__/
|
||||
.vscode
|
||||
dist
|
||||
tests/__pycache__
|
||||
tests/mock_default_app/handlers/__pycache__/
|
||||
tests/mock_default_app/__pycache__/
|
||||
tests/mock_app/local_data_func/__pycache__/
|
||||
tests/mock_app/handlers/handlers_implementation/__pycache__/
|
||||
tests/mock_app/handlers/__pycache__/
|
||||
tests/mock_app/business_logic/__pycache__/
|
||||
tests/mock_app/__pycache__/
|
||||
uv.lock
|
||||
*__pycache__/
|
||||
*.hist*
|
||||
build
|
||||
source
|
||||
*cache
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
# Argenta
|
||||
|
||||
### Bibliothek zum Erstellen modularer CLI-Anwendungen
|
||||
|
||||
Mit Argenta können Sie die CLI-Funktionalität in isolierte, abstrahierte Umgebungen einkapseln. Zum Beispiel: Sie erstellen ein Dienstprogramm ähnlich dem Metasploit Framework, bei dem der Benutzer zuerst in einen bestimmten Scoop eintritt (z. B. ein Modul zum Scannen auswählt) und dann auf eine Reihe von Befehlen zugreift, die nur für diesen Kontext spezifisch sind. Argenta bietet eine einfache und prägnante Möglichkeit, eine solche Architektur zu konstruieren.
|
||||
|
||||
---
|
||||
|
||||

|
||||
|
||||
---
|
||||
|
||||
# Installation
|
||||
```bash
|
||||
pip install argenta
|
||||
```
|
||||
or
|
||||
```bash
|
||||
poetry add argenta
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
# Schnellstart
|
||||
|
||||
Ein Beispiel für eine einfache Anwendung
|
||||
```python
|
||||
# routers.py
|
||||
from argenta.router import Router
|
||||
from argenta.command import Command
|
||||
from argenta.response import Response
|
||||
|
||||
|
||||
router = Router()
|
||||
|
||||
@router.command(Command("hello"))
|
||||
def handler(response: Response):
|
||||
print("Hello, world!")
|
||||
```
|
||||
|
||||
```python
|
||||
# main.py
|
||||
from argenta.app import App
|
||||
from argenta.orchestrator import Orchestrator
|
||||
from routers import router
|
||||
|
||||
app: App = App()
|
||||
orchestrator: Orchestrator = Orchestrator()
|
||||
|
||||
|
||||
def main() -> None:
|
||||
app.include_router(router)
|
||||
orchestrator.start_polling(app)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
# Funktionen in der Entwicklung
|
||||
|
||||
- Vollständige Unterstützung für Autocompleter unter Linux
|
||||
|
||||
## Vollständige [Dokumentation](https://argenta-docs.vercel.app) | MIT 2025 kolo | made by [kolo](https://t.me/kolo_id)
|
||||
|
||||
|
||||
|
||||
@@ -1,2 +1,73 @@
|
||||
# Argenta
|
||||
Python library for creating cli apps
|
||||
|
||||
### Library for creating modular CLI applications
|
||||
|
||||
#### RU - [README.ru.md](https://github.com/koloideal/Argenta/blob/main/README.ru.md) • DE - [README.de.md](https://github.com/koloideal/Argenta/blob/main/README.de.md)
|
||||
|
||||
---
|
||||
|
||||
Argenta allows you to encapsulate CLI functionality in isolated, abstracted environments. Eg: you are creating a utility similar to the Metasploit Framework, where the user first logs into a specific scope (for example, selects a module to scan), and then gets access to a set of commands specific only to that context. Argenta provides a simple and concise way to build such an architecture.
|
||||
|
||||
---
|
||||
|
||||

|
||||
|
||||
---
|
||||
|
||||
# Installing
|
||||
```bash
|
||||
pip install argenta
|
||||
```
|
||||
or
|
||||
```bash
|
||||
poetry add argenta
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
# Quick start
|
||||
|
||||
An example of a simple application
|
||||
```python
|
||||
# routers.py
|
||||
from argenta.router import Router
|
||||
from argenta.command import Command
|
||||
from argenta.response import Response
|
||||
|
||||
|
||||
router = Router()
|
||||
|
||||
@router.command(Command("hello"))
|
||||
def handler(response: Response):
|
||||
print("Hello, world!")
|
||||
```
|
||||
|
||||
```python
|
||||
# main.py
|
||||
from argenta.app import App
|
||||
from argenta.orchestrator import Orchestrator
|
||||
from routers import router
|
||||
|
||||
app: App = App()
|
||||
orchestrator: Orchestrator = Orchestrator()
|
||||
|
||||
|
||||
def main() -> None:
|
||||
app.include_router(router)
|
||||
orchestrator.start_polling(app)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
# Features in development
|
||||
|
||||
- Full support for autocompleter on Linux
|
||||
|
||||
## Full [docs](https://argenta-docs.vercel.app) | MIT 2025 kolo | made by [kolo](https://t.me/kolo_id)
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
# Argenta
|
||||
|
||||
### Библиотека для создания модульных CLI приложeний
|
||||
|
||||
Argenta позволяет инкапсулировать CLI фукциональность в изолированные, абстрагированные **среды**. К примеру: вы создаете утилиту, подобную Metasploit Framework, где пользователь сначала входит в определенный скоуп (например, выбирает модуль для сканирования), а затем получает доступ к набору команд, специфичных только для этого контекста. Argenta предоставляет простой и лаконичный способ для построения такой архитектуры.
|
||||
|
||||
---
|
||||
|
||||

|
||||
|
||||
---
|
||||
|
||||
# Установка
|
||||
```bash
|
||||
pip install argenta
|
||||
```
|
||||
or
|
||||
```bash
|
||||
poetry add argenta
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
# Быстрый старт
|
||||
|
||||
Пример простейшего приложения
|
||||
```python
|
||||
# routers.py
|
||||
from argenta.router import Router
|
||||
from argenta.command import Command
|
||||
from argenta.response import Response
|
||||
|
||||
|
||||
router = Router()
|
||||
|
||||
@router.command(Command("hello"))
|
||||
def handler(response: Response):
|
||||
print("Hello, world!")
|
||||
```
|
||||
|
||||
```python
|
||||
# main.py
|
||||
from argenta.app import App
|
||||
from argenta.orchestrator import Orchestrator
|
||||
from routers import router
|
||||
|
||||
app: App = App()
|
||||
orchestrator: Orchestrator = Orchestrator()
|
||||
|
||||
|
||||
def main() -> None:
|
||||
app.include_router(router)
|
||||
orchestrator.start_polling(app)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
# Фичи в разработке
|
||||
|
||||
- Полноценная поддержка автокомплитера на Linux
|
||||
|
||||
## Полная [документация](https://argenta-docs.vercel.app) | MIT 2025 kolo | made by [kolo](https://t.me/kolo_id)
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
from .entity import App
|
||||
from .exceptions import (HandlerForUnknownCommandsCanOnlyBeDeclaredForMainRouterException,
|
||||
InvalidDescriptionMessagePatternException,
|
||||
InvalidRouterInstanceException,
|
||||
OnlyOneMainRouterIsAllowedException,
|
||||
MissingMainRouterException,
|
||||
MissingHandlersForUnknownCommandsOnMainRouterException)
|
||||
@@ -1,145 +0,0 @@
|
||||
from typing import Callable
|
||||
from ..router.entity import Router
|
||||
from .exceptions import (InvalidRouterInstanceException,
|
||||
InvalidDescriptionMessagePatternException,
|
||||
OnlyOneMainRouterIsAllowedException,
|
||||
MissingMainRouterException,
|
||||
MissingHandlersForUnknownCommandsOnMainRouterException,
|
||||
HandlerForUnknownCommandsCanOnlyBeDeclaredForMainRouterException)
|
||||
|
||||
|
||||
class App:
|
||||
def __init__(self,
|
||||
prompt: str = 'Enter a command',
|
||||
exit_command: str = 'q',
|
||||
ignore_exit_command_register: bool = True,
|
||||
initial_greeting: str = '\nHello, I am Argenta\n',
|
||||
farewell_message: str = 'GoodBye',
|
||||
line_separate: str = '',
|
||||
command_group_description_separate: str = '',
|
||||
print_func: Callable[[str], None] = print) -> None:
|
||||
self.prompt = prompt
|
||||
self.print_func = print_func
|
||||
self.exit_command = exit_command
|
||||
self.ignore_exit_command_register = ignore_exit_command_register
|
||||
self.farewell_message = farewell_message
|
||||
self.initial_greeting = initial_greeting
|
||||
self.line_separate = line_separate
|
||||
self.command_group_description_separate = command_group_description_separate
|
||||
|
||||
self._routers: list[Router] = []
|
||||
self._registered_commands: list[dict[str, str | list[dict[str, Callable[[], None] | str]] | Router]] = []
|
||||
self._main_app_router: Router | None = None
|
||||
self._description_message_pattern: str = '[{command}] *=*=* {description}'
|
||||
|
||||
|
||||
def start_polling(self) -> None:
|
||||
self.print_func(self.initial_greeting)
|
||||
self._validate_main_router()
|
||||
|
||||
while True:
|
||||
self._print_command_group_description()
|
||||
self.print_func(self.prompt)
|
||||
|
||||
command: str = input()
|
||||
|
||||
self._checking_command_for_exit_command(command)
|
||||
self.print_func(self.line_separate)
|
||||
|
||||
is_unknown_command: bool = self._check_is_command_unknown(command)
|
||||
|
||||
if is_unknown_command:
|
||||
continue
|
||||
|
||||
for router in self._routers:
|
||||
router.input_command_handler(command)
|
||||
self.print_func(self.line_separate)
|
||||
self.print_func(self.command_group_description_separate)
|
||||
|
||||
|
||||
def set_initial_greeting(self, greeting: str) -> None:
|
||||
self.initial_greeting: str = greeting
|
||||
|
||||
|
||||
def set_farewell_message(self, message: str) -> None:
|
||||
self.farewell_message: str = message
|
||||
|
||||
|
||||
def set_description_message_pattern(self, pattern: str) -> None:
|
||||
try:
|
||||
pattern.format(command='command',
|
||||
description='description')
|
||||
except KeyError:
|
||||
raise InvalidDescriptionMessagePatternException(pattern)
|
||||
self._description_message_pattern: str = pattern
|
||||
|
||||
|
||||
def _validate_main_router(self):
|
||||
if not self._main_app_router:
|
||||
raise MissingMainRouterException()
|
||||
|
||||
if not self._main_app_router.unknown_command_func:
|
||||
raise MissingHandlersForUnknownCommandsOnMainRouterException()
|
||||
|
||||
for router in self._routers:
|
||||
if router.unknown_command_func and self._main_app_router is not router:
|
||||
raise HandlerForUnknownCommandsCanOnlyBeDeclaredForMainRouterException()
|
||||
|
||||
|
||||
def _checking_command_for_exit_command(self, command: str):
|
||||
if command.lower() == self.exit_command.lower():
|
||||
if self.ignore_exit_command_register:
|
||||
self.print_func(self.farewell_message)
|
||||
exit(0)
|
||||
else:
|
||||
if command == self.exit_command:
|
||||
self.print_func(self.farewell_message)
|
||||
exit(0)
|
||||
|
||||
|
||||
def _check_is_command_unknown(self, command: str):
|
||||
registered_commands: list[dict[str, str | list[dict[str, Callable[[], None] | str]] | Router]] = self._registered_commands
|
||||
for router in registered_commands:
|
||||
for command_entity in router['commands']:
|
||||
if command_entity['command'].lower() == command.lower():
|
||||
if router['router'].ignore_command_register:
|
||||
return False
|
||||
else:
|
||||
if command_entity['command'] == command:
|
||||
return False
|
||||
self._main_app_router.unknown_command_handler(command)
|
||||
self.print_func(self.line_separate)
|
||||
self.print_func(self.command_group_description_separate)
|
||||
return True
|
||||
|
||||
|
||||
def _print_command_group_description(self):
|
||||
for router in self._registered_commands:
|
||||
self.print_func(router['name'])
|
||||
for command_entity in router['commands']:
|
||||
self.print_func(self._description_message_pattern.format(
|
||||
command=command_entity['command'],
|
||||
description=command_entity['description']
|
||||
)
|
||||
)
|
||||
self.print_func(self.command_group_description_separate)
|
||||
|
||||
|
||||
def include_router(self, router: Router, is_main: bool = False) -> None:
|
||||
if not isinstance(router, Router):
|
||||
raise InvalidRouterInstanceException()
|
||||
|
||||
if is_main:
|
||||
if not self._main_app_router:
|
||||
self._main_app_router = router
|
||||
router.set_router_as_main()
|
||||
else:
|
||||
raise OnlyOneMainRouterIsAllowedException(router)
|
||||
|
||||
self._routers.append(router)
|
||||
|
||||
registered_commands: list[dict[str, Callable[[], None] | str]] = router.get_registered_commands()
|
||||
self._registered_commands.append({'name': router.get_name(),
|
||||
'router': router,
|
||||
'commands': registered_commands})
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
class InvalidRouterInstanceException(Exception):
|
||||
def __str__(self):
|
||||
return "Invalid Router Instance"
|
||||
|
||||
|
||||
class InvalidDescriptionMessagePatternException(Exception):
|
||||
def __init__(self, pattern: str):
|
||||
self.pattern = pattern
|
||||
def __str__(self):
|
||||
return ("Invalid Description Message Pattern\n"
|
||||
"Correct pattern example: [{command}] *=*=* {description}\n"
|
||||
"The pattern must contain two variables: `command` and `description` - description of the command\n"
|
||||
f"Your pattern: {self.pattern}")
|
||||
|
||||
|
||||
class OnlyOneMainRouterIsAllowedException(Exception):
|
||||
def __init__(self, existing_main_router):
|
||||
self.existing_main_router = existing_main_router
|
||||
|
||||
def __str__(self):
|
||||
return ("Only One Main Router Allowed\n"
|
||||
f"Existing main router is: {self.existing_main_router}")
|
||||
|
||||
|
||||
class MissingMainRouterException(Exception):
|
||||
def __str__(self):
|
||||
return ("Missing Main Router\n"
|
||||
"One of the registered routers must be the main one")
|
||||
|
||||
|
||||
class MissingHandlersForUnknownCommandsOnMainRouterException(Exception):
|
||||
def __str__(self):
|
||||
return ("Missing Handlers For Unknown Commands On The Main Router\n"
|
||||
"The main router must have a declared handler for unknown commands")
|
||||
|
||||
|
||||
class HandlerForUnknownCommandsCanOnlyBeDeclaredForMainRouterException(Exception):
|
||||
def __str__(self):
|
||||
return '\nThe handler for unknown commands can only be declared for the main router'
|
||||
@@ -1,4 +0,0 @@
|
||||
from .entity import Router
|
||||
from .exceptions import (UnknownCommandHandlerHasAlreadyBeenCreatedException,
|
||||
InvalidDescriptionInstanceException,
|
||||
InvalidCommandInstanceException)
|
||||
@@ -1,71 +0,0 @@
|
||||
from typing import Callable, Any
|
||||
from ..router.exceptions import (InvalidCommandInstanceException,
|
||||
UnknownCommandHandlerHasAlreadyBeenCreatedException,
|
||||
InvalidDescriptionInstanceException)
|
||||
|
||||
|
||||
class Router:
|
||||
def __init__(self,
|
||||
name: str,
|
||||
ignore_command_register: bool = False):
|
||||
|
||||
self.ignore_command_register = ignore_command_register
|
||||
self.name = name
|
||||
|
||||
self._processed_commands: list[dict[str, Callable[[], None] | str]] = []
|
||||
self.unknown_command_func: Callable[[str], None] | None = None
|
||||
self._is_main_router: bool = False
|
||||
|
||||
|
||||
def command(self, command: str, description: str) -> Callable[[Any], Any]:
|
||||
if not isinstance(command, str):
|
||||
raise InvalidCommandInstanceException()
|
||||
if not isinstance(description, str):
|
||||
raise InvalidDescriptionInstanceException()
|
||||
else:
|
||||
def command_decorator(func):
|
||||
self._processed_commands.append({'func': func,
|
||||
'command': command,
|
||||
'description': description})
|
||||
def wrapper(*args, **kwargs):
|
||||
return func(*args, **kwargs)
|
||||
return wrapper
|
||||
return command_decorator
|
||||
|
||||
|
||||
def unknown_command(self, func):
|
||||
if self.unknown_command_func is not None:
|
||||
raise UnknownCommandHandlerHasAlreadyBeenCreatedException()
|
||||
|
||||
self.unknown_command_func: Callable = func
|
||||
|
||||
def wrapper(*args, **kwargs):
|
||||
return func(*args, **kwargs)
|
||||
return wrapper
|
||||
|
||||
|
||||
def input_command_handler(self, input_command):
|
||||
for command_entity in self._processed_commands:
|
||||
if input_command.lower() == command_entity['command'].lower():
|
||||
if self.ignore_command_register:
|
||||
return command_entity['func']()
|
||||
else:
|
||||
if input_command == command_entity['command']:
|
||||
return command_entity['func']()
|
||||
|
||||
|
||||
def unknown_command_handler(self, unknown_command):
|
||||
self.unknown_command_func(unknown_command)
|
||||
|
||||
|
||||
def set_router_as_main(self):
|
||||
self._is_main_router = True
|
||||
|
||||
|
||||
def get_registered_commands(self) -> list[dict[str, Callable[[], None] | str]]:
|
||||
return self._processed_commands
|
||||
|
||||
|
||||
def get_name(self) -> str:
|
||||
return self.name
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
class InvalidCommandInstanceException(Exception):
|
||||
def __str__(self):
|
||||
return "Invalid Command Instance"
|
||||
|
||||
|
||||
class InvalidDescriptionInstanceException(Exception):
|
||||
def __str__(self):
|
||||
return "Invalid Description Instance"
|
||||
|
||||
|
||||
class UnknownCommandHandlerHasAlreadyBeenCreatedException(Exception):
|
||||
def __str__(self):
|
||||
return "Only one unknown command handler can be declared"
|
||||
|
After Width: | Height: | Size: 1.5 MiB |
|
After Width: | Height: | Size: 1.9 MiB |
|
After Width: | Height: | Size: 928 KiB |
@@ -0,0 +1,46 @@
|
||||
<?xml version="1.0" standalone="no"?>
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN"
|
||||
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
|
||||
<svg version="1.0" xmlns="http://www.w3.org/2000/svg"
|
||||
width="809.000000pt" height="809.000000pt" viewBox="0 0 809.000000 809.000000"
|
||||
preserveAspectRatio="xMidYMid meet">
|
||||
|
||||
<g transform="translate(0.000000,809.000000) scale(0.100000,-0.100000)"
|
||||
fill="#000000" stroke="none">
|
||||
<path d="M3845 7600 c-683 -38 -1333 -259 -1875 -639 -702 -492 -1223 -1251
|
||||
-1434 -2089 -83 -330 -111 -602 -103 -980 6 -273 19 -393 67 -632 167 -829
|
||||
642 -1593 1321 -2122 512 -399 1133 -656 1794 -745 165 -22 666 -25 825 -5
|
||||
779 99 1451 397 2020 898 687 603 1095 1401 1201 2344 17 147 17 571 0 715
|
||||
-59 518 -204 977 -442 1402 -180 322 -355 552 -629 823 -518 515 -1164 850
|
||||
-1887 979 -254 45 -594 66 -858 51z m655 -234 c545 -76 1005 -248 1445 -541
|
||||
195 -130 336 -245 506 -415 457 -456 758 -987 909 -1605 134 -547 132 -1119
|
||||
-5 -1665 -149 -593 -445 -1112 -885 -1550 -624 -623 -1414 -966 -2315 -1006
|
||||
-412 -18 -935 73 -1339 232 -656 259 -1228 720 -1610 1299 -298 450 -461 890
|
||||
-538 1451 -28 210 -31 620 -4 819 103 786 437 1477 975 2016 149 149 266 249
|
||||
417 357 315 225 692 405 1059 506 211 58 342 81 675 120 87 10 601 -3 710 -18z"/>
|
||||
<path d="M3691 6759 c-231 -17 -522 -67 -660 -114 -227 -77 -354 -211 -381
|
||||
-400 -14 -105 -13 -628 2 -643 9 -9 158 -12 611 -12 598 0 628 -2 649 -34 14
|
||||
-21 8 -66 -12 -86 -20 -20 -33 -20 -908 -20 -857 0 -892 -1 -967 -20 -294 -75
|
||||
-500 -321 -599 -715 -49 -195 -61 -309 -60 -585 0 -221 3 -272 23 -385 44
|
||||
-251 116 -418 232 -540 78 -82 143 -123 254 -162 78 -27 85 -27 351 -31 l272
|
||||
-4 16 23 c14 20 16 58 16 259 0 334 20 446 107 613 80 153 268 310 447 374
|
||||
128 45 138 46 881 52 683 7 713 8 786 28 201 56 353 177 437 348 80 162 86
|
||||
240 74 905 -11 608 -10 600 -84 743 -80 153 -240 271 -453 332 -252 73 -653
|
||||
101 -1034 74z m-383 -466 c126 -78 147 -245 44 -355 -144 -154 -396 -54 -395
|
||||
157 0 97 62 187 154 222 54 20 143 10 197 -24z"/>
|
||||
<path d="M5451 5491 c-20 -20 -21 -30 -21 -283 0 -276 -7 -351 -42 -458 -81
|
||||
-251 -281 -454 -523 -534 -149 -48 -151 -48 -890 -56 -678 -6 -703 -7 -780
|
||||
-28 -139 -38 -219 -84 -315 -181 -61 -61 -95 -105 -117 -151 -65 -134 -64
|
||||
-129 -75 -780 -12 -665 -10 -694 47 -817 122 -265 419 -429 895 -494 127 -18
|
||||
592 -18 730 -1 377 48 646 169 785 355 57 75 67 94 96 182 20 64 23 94 27 325
|
||||
4 238 3 257 -15 278 l-18 23 -551 -1 c-399 0 -559 3 -577 11 -51 23 -56 102
|
||||
-8 126 9 4 439 10 956 13 1044 7 981 2 1125 75 178 89 305 255 386 502 84 257
|
||||
111 618 73 973 -39 364 -167 655 -351 801 -63 50 -121 80 -213 110 -64 20 -93
|
||||
23 -337 27 -260 4 -267 3 -287 -17z m-2104 -1698 c78 -52 531 -413 561 -447
|
||||
17 -19 33 -48 37 -65 15 -71 3 -84 -323 -356 -275 -229 -310 -255 -342 -255
|
||||
-78 1 -112 75 -61 134 9 10 86 75 171 144 247 201 355 294 358 311 1 9 -15 28
|
||||
-38 44 -127 89 -503 393 -512 413 -23 50 20 103 82 104 15 0 45 -12 67 -27z
|
||||
m1388 -1244 c59 -15 129 -77 151 -134 36 -96 0 -204 -88 -262 -36 -24 -51 -28
|
||||
-118 -28 -67 0 -82 4 -118 28 -153 101 -124 338 48 392 57 17 71 18 125 4z"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 2.9 KiB |
|
After Width: | Height: | Size: 60 KiB |
|
After Width: | Height: | Size: 58 KiB |
|
After Width: | Height: | Size: 54 KiB |
|
After Width: | Height: | Size: 50 KiB |
@@ -0,0 +1,33 @@
|
||||
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
|
||||
from argenta.app import App
|
||||
|
||||
|
||||
|
||||
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)
|
||||
@@ -0,0 +1,5 @@
|
||||
import argparse
|
||||
|
||||
parser = argparse.ArgumentParser(prog='myprogram')
|
||||
_ = parser.add_argument('--foo', help='foo of the %(prog)s program')
|
||||
parser.print_help()
|
||||
@@ -0,0 +1,29 @@
|
||||
from mock.mock_app.routers import work_router
|
||||
|
||||
from argenta import App, Orchestrator
|
||||
from argenta.app import PredefinedMessages, DynamicDividingLine, AutoCompleter
|
||||
from argenta.orchestrator import ArgParser
|
||||
from argenta.orchestrator.argparser import BooleanArgument
|
||||
|
||||
|
||||
arg_parser = ArgParser(processed_args=[BooleanArgument("repeat")])
|
||||
app: App = App(
|
||||
dividing_line=DynamicDividingLine(),
|
||||
autocompleter=AutoCompleter(),
|
||||
)
|
||||
orchestrator: Orchestrator = Orchestrator(arg_parser)
|
||||
|
||||
|
||||
def main():
|
||||
app.include_router(work_router)
|
||||
print(f"\n\n{orchestrator.get_input_args()}")
|
||||
|
||||
app.add_message_on_startup(PredefinedMessages.USAGE)
|
||||
app.add_message_on_startup(PredefinedMessages.AUTOCOMPLETE)
|
||||
app.add_message_on_startup(PredefinedMessages.HELP)
|
||||
|
||||
orchestrator.start_polling(app)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,25 @@
|
||||
from argenta.command import Command, PredefinedFlags, Flags, Flag, PossibleValues
|
||||
from argenta.response import Response
|
||||
from argenta import Router
|
||||
|
||||
|
||||
work_router: Router = Router(title="Work points:")
|
||||
|
||||
flag = Flag('csdv', possible_values=PossibleValues.NEITHER)
|
||||
|
||||
|
||||
@work_router.command(
|
||||
Command("get",
|
||||
description="Get Help",
|
||||
aliases=["help", "Get_help"],
|
||||
flags=Flags([PredefinedFlags.PORT,
|
||||
PredefinedFlags.HOST])))
|
||||
def command_help(response: Response):
|
||||
print(response.status)
|
||||
print(response.input_flags.flags)
|
||||
|
||||
|
||||
@work_router.command("run")
|
||||
def command_start_solving(response: Response):
|
||||
print(response.status)
|
||||
print(response.input_flags.flags)
|
||||
@@ -1,442 +0,0 @@
|
||||
# This file is automatically @generated by Poetry 2.0.1 and should not be changed by hand.
|
||||
|
||||
[[package]]
|
||||
name = "art"
|
||||
version = "6.4"
|
||||
description = "ASCII Art Library For Python"
|
||||
optional = false
|
||||
python-versions = ">=3.6"
|
||||
groups = ["dev"]
|
||||
files = [
|
||||
{file = "art-6.4-py3-none-any.whl", hash = "sha256:4e58b6f0a0bb8574efb311eff24bdd28bf889c0c526ccbbb5410c644340a301c"},
|
||||
{file = "art-6.4.tar.gz", hash = "sha256:417fea674bff8cea7ed058291ad1b81a6032dfce5152f28e629fa4a798a2c14c"},
|
||||
]
|
||||
|
||||
[package.extras]
|
||||
dev = ["bandit (>=1.5.1)", "coverage (>=4.1)", "pydocstyle (>=3.0.0)", "vulture (>=1.0)"]
|
||||
|
||||
[[package]]
|
||||
name = "certifi"
|
||||
version = "2025.1.31"
|
||||
description = "Python package for providing Mozilla's CA Bundle."
|
||||
optional = false
|
||||
python-versions = ">=3.6"
|
||||
groups = ["dev"]
|
||||
files = [
|
||||
{file = "certifi-2025.1.31-py3-none-any.whl", hash = "sha256:ca78db4565a652026a4db2bcdf68f2fb589ea80d0be70e03929ed730746b84fe"},
|
||||
{file = "certifi-2025.1.31.tar.gz", hash = "sha256:3d5da6925056f6f18f119200434a4780a94263f10d1c21d032a6f6b2baa20651"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "charset-normalizer"
|
||||
version = "3.4.1"
|
||||
description = "The Real First Universal Charset Detector. Open, modern and actively maintained alternative to Chardet."
|
||||
optional = false
|
||||
python-versions = ">=3.7"
|
||||
groups = ["dev"]
|
||||
files = [
|
||||
{file = "charset_normalizer-3.4.1-cp310-cp310-macosx_10_9_universal2.whl", hash = "sha256:91b36a978b5ae0ee86c394f5a54d6ef44db1de0815eb43de826d41d21e4af3de"},
|
||||
{file = "charset_normalizer-3.4.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:7461baadb4dc00fd9e0acbe254e3d7d2112e7f92ced2adc96e54ef6501c5f176"},
|
||||
{file = "charset_normalizer-3.4.1-cp310-cp310-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:e218488cd232553829be0664c2292d3af2eeeb94b32bea483cf79ac6a694e037"},
|
||||
{file = "charset_normalizer-3.4.1-cp310-cp310-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:80ed5e856eb7f30115aaf94e4a08114ccc8813e6ed1b5efa74f9f82e8509858f"},
|
||||
{file = "charset_normalizer-3.4.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:b010a7a4fd316c3c484d482922d13044979e78d1861f0e0650423144c616a46a"},
|
||||
{file = "charset_normalizer-3.4.1-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:4532bff1b8421fd0a320463030c7520f56a79c9024a4e88f01c537316019005a"},
|
||||
{file = "charset_normalizer-3.4.1-cp310-cp310-musllinux_1_2_aarch64.whl", hash = "sha256:d973f03c0cb71c5ed99037b870f2be986c3c05e63622c017ea9816881d2dd247"},
|
||||
{file = "charset_normalizer-3.4.1-cp310-cp310-musllinux_1_2_i686.whl", hash = "sha256:3a3bd0dcd373514dcec91c411ddb9632c0d7d92aed7093b8c3bbb6d69ca74408"},
|
||||
{file = "charset_normalizer-3.4.1-cp310-cp310-musllinux_1_2_ppc64le.whl", hash = "sha256:d9c3cdf5390dcd29aa8056d13e8e99526cda0305acc038b96b30352aff5ff2bb"},
|
||||
{file = "charset_normalizer-3.4.1-cp310-cp310-musllinux_1_2_s390x.whl", hash = "sha256:2bdfe3ac2e1bbe5b59a1a63721eb3b95fc9b6817ae4a46debbb4e11f6232428d"},
|
||||
{file = "charset_normalizer-3.4.1-cp310-cp310-musllinux_1_2_x86_64.whl", hash = "sha256:eab677309cdb30d047996b36d34caeda1dc91149e4fdca0b1a039b3f79d9a807"},
|
||||
{file = "charset_normalizer-3.4.1-cp310-cp310-win32.whl", hash = "sha256:c0429126cf75e16c4f0ad00ee0eae4242dc652290f940152ca8c75c3a4b6ee8f"},
|
||||
{file = "charset_normalizer-3.4.1-cp310-cp310-win_amd64.whl", hash = "sha256:9f0b8b1c6d84c8034a44893aba5e767bf9c7a211e313a9605d9c617d7083829f"},
|
||||
{file = "charset_normalizer-3.4.1-cp311-cp311-macosx_10_9_universal2.whl", hash = "sha256:8bfa33f4f2672964266e940dd22a195989ba31669bd84629f05fab3ef4e2d125"},
|
||||
{file = "charset_normalizer-3.4.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:28bf57629c75e810b6ae989f03c0828d64d6b26a5e205535585f96093e405ed1"},
|
||||
{file = "charset_normalizer-3.4.1-cp311-cp311-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:f08ff5e948271dc7e18a35641d2f11a4cd8dfd5634f55228b691e62b37125eb3"},
|
||||
{file = "charset_normalizer-3.4.1-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:234ac59ea147c59ee4da87a0c0f098e9c8d169f4dc2a159ef720f1a61bbe27cd"},
|
||||
{file = "charset_normalizer-3.4.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:fd4ec41f914fa74ad1b8304bbc634b3de73d2a0889bd32076342a573e0779e00"},
|
||||
{file = "charset_normalizer-3.4.1-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:eea6ee1db730b3483adf394ea72f808b6e18cf3cb6454b4d86e04fa8c4327a12"},
|
||||
{file = "charset_normalizer-3.4.1-cp311-cp311-musllinux_1_2_aarch64.whl", hash = "sha256:c96836c97b1238e9c9e3fe90844c947d5afbf4f4c92762679acfe19927d81d77"},
|
||||
{file = "charset_normalizer-3.4.1-cp311-cp311-musllinux_1_2_i686.whl", hash = "sha256:4d86f7aff21ee58f26dcf5ae81a9addbd914115cdebcbb2217e4f0ed8982e146"},
|
||||
{file = "charset_normalizer-3.4.1-cp311-cp311-musllinux_1_2_ppc64le.whl", hash = "sha256:09b5e6733cbd160dcc09589227187e242a30a49ca5cefa5a7edd3f9d19ed53fd"},
|
||||
{file = "charset_normalizer-3.4.1-cp311-cp311-musllinux_1_2_s390x.whl", hash = "sha256:5777ee0881f9499ed0f71cc82cf873d9a0ca8af166dfa0af8ec4e675b7df48e6"},
|
||||
{file = "charset_normalizer-3.4.1-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:237bdbe6159cff53b4f24f397d43c6336c6b0b42affbe857970cefbb620911c8"},
|
||||
{file = "charset_normalizer-3.4.1-cp311-cp311-win32.whl", hash = "sha256:8417cb1f36cc0bc7eaba8ccb0e04d55f0ee52df06df3ad55259b9a323555fc8b"},
|
||||
{file = "charset_normalizer-3.4.1-cp311-cp311-win_amd64.whl", hash = "sha256:d7f50a1f8c450f3925cb367d011448c39239bb3eb4117c36a6d354794de4ce76"},
|
||||
{file = "charset_normalizer-3.4.1-cp312-cp312-macosx_10_13_universal2.whl", hash = "sha256:73d94b58ec7fecbc7366247d3b0b10a21681004153238750bb67bd9012414545"},
|
||||
{file = "charset_normalizer-3.4.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:dad3e487649f498dd991eeb901125411559b22e8d7ab25d3aeb1af367df5efd7"},
|
||||
{file = "charset_normalizer-3.4.1-cp312-cp312-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:c30197aa96e8eed02200a83fba2657b4c3acd0f0aa4bdc9f6c1af8e8962e0757"},
|
||||
{file = "charset_normalizer-3.4.1-cp312-cp312-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:2369eea1ee4a7610a860d88f268eb39b95cb588acd7235e02fd5a5601773d4fa"},
|
||||
{file = "charset_normalizer-3.4.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:bc2722592d8998c870fa4e290c2eec2c1569b87fe58618e67d38b4665dfa680d"},
|
||||
{file = "charset_normalizer-3.4.1-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:ffc9202a29ab3920fa812879e95a9e78b2465fd10be7fcbd042899695d75e616"},
|
||||
{file = "charset_normalizer-3.4.1-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:804a4d582ba6e5b747c625bf1255e6b1507465494a40a2130978bda7b932c90b"},
|
||||
{file = "charset_normalizer-3.4.1-cp312-cp312-musllinux_1_2_i686.whl", hash = "sha256:0f55e69f030f7163dffe9fd0752b32f070566451afe180f99dbeeb81f511ad8d"},
|
||||
{file = "charset_normalizer-3.4.1-cp312-cp312-musllinux_1_2_ppc64le.whl", hash = "sha256:c4c3e6da02df6fa1410a7680bd3f63d4f710232d3139089536310d027950696a"},
|
||||
{file = "charset_normalizer-3.4.1-cp312-cp312-musllinux_1_2_s390x.whl", hash = "sha256:5df196eb874dae23dcfb968c83d4f8fdccb333330fe1fc278ac5ceeb101003a9"},
|
||||
{file = "charset_normalizer-3.4.1-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:e358e64305fe12299a08e08978f51fc21fac060dcfcddd95453eabe5b93ed0e1"},
|
||||
{file = "charset_normalizer-3.4.1-cp312-cp312-win32.whl", hash = "sha256:9b23ca7ef998bc739bf6ffc077c2116917eabcc901f88da1b9856b210ef63f35"},
|
||||
{file = "charset_normalizer-3.4.1-cp312-cp312-win_amd64.whl", hash = "sha256:6ff8a4a60c227ad87030d76e99cd1698345d4491638dfa6673027c48b3cd395f"},
|
||||
{file = "charset_normalizer-3.4.1-cp313-cp313-macosx_10_13_universal2.whl", hash = "sha256:aabfa34badd18f1da5ec1bc2715cadc8dca465868a4e73a0173466b688f29dda"},
|
||||
{file = "charset_normalizer-3.4.1-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:22e14b5d70560b8dd51ec22863f370d1e595ac3d024cb8ad7d308b4cd95f8313"},
|
||||
{file = "charset_normalizer-3.4.1-cp313-cp313-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:8436c508b408b82d87dc5f62496973a1805cd46727c34440b0d29d8a2f50a6c9"},
|
||||
{file = "charset_normalizer-3.4.1-cp313-cp313-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:2d074908e1aecee37a7635990b2c6d504cd4766c7bc9fc86d63f9c09af3fa11b"},
|
||||
{file = "charset_normalizer-3.4.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:955f8851919303c92343d2f66165294848d57e9bba6cf6e3625485a70a038d11"},
|
||||
{file = "charset_normalizer-3.4.1-cp313-cp313-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:44ecbf16649486d4aebafeaa7ec4c9fed8b88101f4dd612dcaf65d5e815f837f"},
|
||||
{file = "charset_normalizer-3.4.1-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:0924e81d3d5e70f8126529951dac65c1010cdf117bb75eb02dd12339b57749dd"},
|
||||
{file = "charset_normalizer-3.4.1-cp313-cp313-musllinux_1_2_i686.whl", hash = "sha256:2967f74ad52c3b98de4c3b32e1a44e32975e008a9cd2a8cc8966d6a5218c5cb2"},
|
||||
{file = "charset_normalizer-3.4.1-cp313-cp313-musllinux_1_2_ppc64le.whl", hash = "sha256:c75cb2a3e389853835e84a2d8fb2b81a10645b503eca9bcb98df6b5a43eb8886"},
|
||||
{file = "charset_normalizer-3.4.1-cp313-cp313-musllinux_1_2_s390x.whl", hash = "sha256:09b26ae6b1abf0d27570633b2b078a2a20419c99d66fb2823173d73f188ce601"},
|
||||
{file = "charset_normalizer-3.4.1-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:fa88b843d6e211393a37219e6a1c1df99d35e8fd90446f1118f4216e307e48cd"},
|
||||
{file = "charset_normalizer-3.4.1-cp313-cp313-win32.whl", hash = "sha256:eb8178fe3dba6450a3e024e95ac49ed3400e506fd4e9e5c32d30adda88cbd407"},
|
||||
{file = "charset_normalizer-3.4.1-cp313-cp313-win_amd64.whl", hash = "sha256:b1ac5992a838106edb89654e0aebfc24f5848ae2547d22c2c3f66454daa11971"},
|
||||
{file = "charset_normalizer-3.4.1-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:f30bf9fd9be89ecb2360c7d94a711f00c09b976258846efe40db3d05828e8089"},
|
||||
{file = "charset_normalizer-3.4.1-cp37-cp37m-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:97f68b8d6831127e4787ad15e6757232e14e12060bec17091b85eb1486b91d8d"},
|
||||
{file = "charset_normalizer-3.4.1-cp37-cp37m-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:7974a0b5ecd505609e3b19742b60cee7aa2aa2fb3151bc917e6e2646d7667dcf"},
|
||||
{file = "charset_normalizer-3.4.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:fc54db6c8593ef7d4b2a331b58653356cf04f67c960f584edb7c3d8c97e8f39e"},
|
||||
{file = "charset_normalizer-3.4.1-cp37-cp37m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:311f30128d7d333eebd7896965bfcfbd0065f1716ec92bd5638d7748eb6f936a"},
|
||||
{file = "charset_normalizer-3.4.1-cp37-cp37m-musllinux_1_2_aarch64.whl", hash = "sha256:7d053096f67cd1241601111b698f5cad775f97ab25d81567d3f59219b5f1adbd"},
|
||||
{file = "charset_normalizer-3.4.1-cp37-cp37m-musllinux_1_2_i686.whl", hash = "sha256:807f52c1f798eef6cf26beb819eeb8819b1622ddfeef9d0977a8502d4db6d534"},
|
||||
{file = "charset_normalizer-3.4.1-cp37-cp37m-musllinux_1_2_ppc64le.whl", hash = "sha256:dccbe65bd2f7f7ec22c4ff99ed56faa1e9f785482b9bbd7c717e26fd723a1d1e"},
|
||||
{file = "charset_normalizer-3.4.1-cp37-cp37m-musllinux_1_2_s390x.whl", hash = "sha256:2fb9bd477fdea8684f78791a6de97a953c51831ee2981f8e4f583ff3b9d9687e"},
|
||||
{file = "charset_normalizer-3.4.1-cp37-cp37m-musllinux_1_2_x86_64.whl", hash = "sha256:01732659ba9b5b873fc117534143e4feefecf3b2078b0a6a2e925271bb6f4cfa"},
|
||||
{file = "charset_normalizer-3.4.1-cp37-cp37m-win32.whl", hash = "sha256:7a4f97a081603d2050bfaffdefa5b02a9ec823f8348a572e39032caa8404a487"},
|
||||
{file = "charset_normalizer-3.4.1-cp37-cp37m-win_amd64.whl", hash = "sha256:7b1bef6280950ee6c177b326508f86cad7ad4dff12454483b51d8b7d673a2c5d"},
|
||||
{file = "charset_normalizer-3.4.1-cp38-cp38-macosx_10_9_universal2.whl", hash = "sha256:ecddf25bee22fe4fe3737a399d0d177d72bc22be6913acfab364b40bce1ba83c"},
|
||||
{file = "charset_normalizer-3.4.1-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:8c60ca7339acd497a55b0ea5d506b2a2612afb2826560416f6894e8b5770d4a9"},
|
||||
{file = "charset_normalizer-3.4.1-cp38-cp38-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:b7b2d86dd06bfc2ade3312a83a5c364c7ec2e3498f8734282c6c3d4b07b346b8"},
|
||||
{file = "charset_normalizer-3.4.1-cp38-cp38-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:dd78cfcda14a1ef52584dbb008f7ac81c1328c0f58184bf9a84c49c605002da6"},
|
||||
{file = "charset_normalizer-3.4.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6e27f48bcd0957c6d4cb9d6fa6b61d192d0b13d5ef563e5f2ae35feafc0d179c"},
|
||||
{file = "charset_normalizer-3.4.1-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:01ad647cdd609225c5350561d084b42ddf732f4eeefe6e678765636791e78b9a"},
|
||||
{file = "charset_normalizer-3.4.1-cp38-cp38-musllinux_1_2_aarch64.whl", hash = "sha256:619a609aa74ae43d90ed2e89bdd784765de0a25ca761b93e196d938b8fd1dbbd"},
|
||||
{file = "charset_normalizer-3.4.1-cp38-cp38-musllinux_1_2_i686.whl", hash = "sha256:89149166622f4db9b4b6a449256291dc87a99ee53151c74cbd82a53c8c2f6ccd"},
|
||||
{file = "charset_normalizer-3.4.1-cp38-cp38-musllinux_1_2_ppc64le.whl", hash = "sha256:7709f51f5f7c853f0fb938bcd3bc59cdfdc5203635ffd18bf354f6967ea0f824"},
|
||||
{file = "charset_normalizer-3.4.1-cp38-cp38-musllinux_1_2_s390x.whl", hash = "sha256:345b0426edd4e18138d6528aed636de7a9ed169b4aaf9d61a8c19e39d26838ca"},
|
||||
{file = "charset_normalizer-3.4.1-cp38-cp38-musllinux_1_2_x86_64.whl", hash = "sha256:0907f11d019260cdc3f94fbdb23ff9125f6b5d1039b76003b5b0ac9d6a6c9d5b"},
|
||||
{file = "charset_normalizer-3.4.1-cp38-cp38-win32.whl", hash = "sha256:ea0d8d539afa5eb2728aa1932a988a9a7af94f18582ffae4bc10b3fbdad0626e"},
|
||||
{file = "charset_normalizer-3.4.1-cp38-cp38-win_amd64.whl", hash = "sha256:329ce159e82018d646c7ac45b01a430369d526569ec08516081727a20e9e4af4"},
|
||||
{file = "charset_normalizer-3.4.1-cp39-cp39-macosx_10_9_universal2.whl", hash = "sha256:b97e690a2118911e39b4042088092771b4ae3fc3aa86518f84b8cf6888dbdb41"},
|
||||
{file = "charset_normalizer-3.4.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:78baa6d91634dfb69ec52a463534bc0df05dbd546209b79a3880a34487f4b84f"},
|
||||
{file = "charset_normalizer-3.4.1-cp39-cp39-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:1a2bc9f351a75ef49d664206d51f8e5ede9da246602dc2d2726837620ea034b2"},
|
||||
{file = "charset_normalizer-3.4.1-cp39-cp39-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:75832c08354f595c760a804588b9357d34ec00ba1c940c15e31e96d902093770"},
|
||||
{file = "charset_normalizer-3.4.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:0af291f4fe114be0280cdd29d533696a77b5b49cfde5467176ecab32353395c4"},
|
||||
{file = "charset_normalizer-3.4.1-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:0167ddc8ab6508fe81860a57dd472b2ef4060e8d378f0cc555707126830f2537"},
|
||||
{file = "charset_normalizer-3.4.1-cp39-cp39-musllinux_1_2_aarch64.whl", hash = "sha256:2a75d49014d118e4198bcee5ee0a6f25856b29b12dbf7cd012791f8a6cc5c496"},
|
||||
{file = "charset_normalizer-3.4.1-cp39-cp39-musllinux_1_2_i686.whl", hash = "sha256:363e2f92b0f0174b2f8238240a1a30142e3db7b957a5dd5689b0e75fb717cc78"},
|
||||
{file = "charset_normalizer-3.4.1-cp39-cp39-musllinux_1_2_ppc64le.whl", hash = "sha256:ab36c8eb7e454e34e60eb55ca5d241a5d18b2c6244f6827a30e451c42410b5f7"},
|
||||
{file = "charset_normalizer-3.4.1-cp39-cp39-musllinux_1_2_s390x.whl", hash = "sha256:4c0907b1928a36d5a998d72d64d8eaa7244989f7aaaf947500d3a800c83a3fd6"},
|
||||
{file = "charset_normalizer-3.4.1-cp39-cp39-musllinux_1_2_x86_64.whl", hash = "sha256:04432ad9479fa40ec0f387795ddad4437a2b50417c69fa275e212933519ff294"},
|
||||
{file = "charset_normalizer-3.4.1-cp39-cp39-win32.whl", hash = "sha256:3bed14e9c89dcb10e8f3a29f9ccac4955aebe93c71ae803af79265c9ca5644c5"},
|
||||
{file = "charset_normalizer-3.4.1-cp39-cp39-win_amd64.whl", hash = "sha256:49402233c892a461407c512a19435d1ce275543138294f7ef013f0b63d5d3765"},
|
||||
{file = "charset_normalizer-3.4.1-py3-none-any.whl", hash = "sha256:d98b1668f06378c6dbefec3b92299716b931cd4e6061f3c875a71ced1780ab85"},
|
||||
{file = "charset_normalizer-3.4.1.tar.gz", hash = "sha256:44251f18cd68a75b56585dd00dae26183e102cd5e0f9f1466e6df5da2ed64ea3"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "colorama"
|
||||
version = "0.4.6"
|
||||
description = "Cross-platform colored terminal text."
|
||||
optional = false
|
||||
python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*,>=2.7"
|
||||
groups = ["dev"]
|
||||
markers = "platform_system == \"Windows\""
|
||||
files = [
|
||||
{file = "colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6"},
|
||||
{file = "colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "idna"
|
||||
version = "3.10"
|
||||
description = "Internationalized Domain Names in Applications (IDNA)"
|
||||
optional = false
|
||||
python-versions = ">=3.6"
|
||||
groups = ["dev"]
|
||||
files = [
|
||||
{file = "idna-3.10-py3-none-any.whl", hash = "sha256:946d195a0d259cbba61165e88e65941f16e9b36ea6ddb97f00452bae8b1287d3"},
|
||||
{file = "idna-3.10.tar.gz", hash = "sha256:12f65c9b470abda6dc35cf8e63cc574b1c52b11df2c86030af0ac09b01b13ea9"},
|
||||
]
|
||||
|
||||
[package.extras]
|
||||
all = ["flake8 (>=7.1.1)", "mypy (>=1.11.2)", "pytest (>=8.3.2)", "ruff (>=0.6.2)"]
|
||||
|
||||
[[package]]
|
||||
name = "markdown-it-py"
|
||||
version = "3.0.0"
|
||||
description = "Python port of markdown-it. Markdown parsing, done right!"
|
||||
optional = false
|
||||
python-versions = ">=3.8"
|
||||
groups = ["dev"]
|
||||
files = [
|
||||
{file = "markdown-it-py-3.0.0.tar.gz", hash = "sha256:e3f60a94fa066dc52ec76661e37c851cb232d92f9886b15cb560aaada2df8feb"},
|
||||
{file = "markdown_it_py-3.0.0-py3-none-any.whl", hash = "sha256:355216845c60bd96232cd8d8c40e8f9765cc86f46880e43a8fd22dc1a1a8cab1"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
mdurl = ">=0.1,<1.0"
|
||||
|
||||
[package.extras]
|
||||
benchmarking = ["psutil", "pytest", "pytest-benchmark"]
|
||||
code-style = ["pre-commit (>=3.0,<4.0)"]
|
||||
compare = ["commonmark (>=0.9,<1.0)", "markdown (>=3.4,<4.0)", "mistletoe (>=1.0,<2.0)", "mistune (>=2.0,<3.0)", "panflute (>=2.3,<3.0)"]
|
||||
linkify = ["linkify-it-py (>=1,<3)"]
|
||||
plugins = ["mdit-py-plugins"]
|
||||
profiling = ["gprof2dot"]
|
||||
rtd = ["jupyter_sphinx", "mdit-py-plugins", "myst-parser", "pyyaml", "sphinx", "sphinx-copybutton", "sphinx-design", "sphinx_book_theme"]
|
||||
testing = ["coverage", "pytest", "pytest-cov", "pytest-regressions"]
|
||||
|
||||
[[package]]
|
||||
name = "mdurl"
|
||||
version = "0.1.2"
|
||||
description = "Markdown URL utilities"
|
||||
optional = false
|
||||
python-versions = ">=3.7"
|
||||
groups = ["dev"]
|
||||
files = [
|
||||
{file = "mdurl-0.1.2-py3-none-any.whl", hash = "sha256:84008a41e51615a49fc9966191ff91509e3c40b939176e643fd50a5c2196b8f8"},
|
||||
{file = "mdurl-0.1.2.tar.gz", hash = "sha256:bb413d29f5eea38f31dd4754dd7377d4465116fb207585f97bf925588687c1ba"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "numexpr"
|
||||
version = "2.10.2"
|
||||
description = "Fast numerical expression evaluator for NumPy"
|
||||
optional = false
|
||||
python-versions = ">=3.9"
|
||||
groups = ["dev"]
|
||||
files = [
|
||||
{file = "numexpr-2.10.2-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:b5b0e82d2109c1d9e63fcd5ea177d80a11b881157ab61178ddbdebd4c561ea46"},
|
||||
{file = "numexpr-2.10.2-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:3fc2b8035a0c2cdc352e58c3875cb668836018065cbf5752cb531015d9a568d8"},
|
||||
{file = "numexpr-2.10.2-cp310-cp310-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:0db5ff5183935d1612653559c319922143e8fa3019007696571b13135f216458"},
|
||||
{file = "numexpr-2.10.2-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:15f59655458056fdb3a621b1bb8e071581ccf7e823916c7568bb7c9a3e393025"},
|
||||
{file = "numexpr-2.10.2-cp310-cp310-musllinux_1_2_x86_64.whl", hash = "sha256:ce8cccf944339051e44a49a124a06287fe3066d0acbff33d1aa5aee10a96abb7"},
|
||||
{file = "numexpr-2.10.2-cp310-cp310-win32.whl", hash = "sha256:ba85371c9a8d03e115f4dfb6d25dfbce05387002b9bc85016af939a1da9624f0"},
|
||||
{file = "numexpr-2.10.2-cp310-cp310-win_amd64.whl", hash = "sha256:deb64235af9eeba59fcefa67e82fa80cfc0662e1b0aa373b7118a28da124d51d"},
|
||||
{file = "numexpr-2.10.2-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:6b360eb8d392483410fe6a3d5a7144afa298c9a0aa3e9fe193e89590b47dd477"},
|
||||
{file = "numexpr-2.10.2-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:d9a42f5c24880350d88933c4efee91b857c378aaea7e8b86221fff569069841e"},
|
||||
{file = "numexpr-2.10.2-cp311-cp311-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:83fcb11988b57cc25b028a36d285287d706d1f536ebf2662ea30bd990e0de8b9"},
|
||||
{file = "numexpr-2.10.2-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:4213a92efa9770bc28e3792134e27c7e5c7e97068bdfb8ba395baebbd12f991b"},
|
||||
{file = "numexpr-2.10.2-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:ebdbef5763ca057eea0c2b5698e4439d084a0505d9d6e94f4804f26e8890c45e"},
|
||||
{file = "numexpr-2.10.2-cp311-cp311-win32.whl", hash = "sha256:3bf01ec502d89944e49e9c1b5cc7c7085be8ca2eb9dd46a0eafd218afbdbd5f5"},
|
||||
{file = "numexpr-2.10.2-cp311-cp311-win_amd64.whl", hash = "sha256:e2d0ae24b0728e4bc3f1d3f33310340d67321d36d6043f7ce26897f4f1042db0"},
|
||||
{file = "numexpr-2.10.2-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:b5323a46e75832334f1af86da1ef6ff0add00fbacdd266250be872b438bdf2be"},
|
||||
{file = "numexpr-2.10.2-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:a42963bd4c62d8afa4f51e7974debfa39a048383f653544ab54f50a2f7ec6c42"},
|
||||
{file = "numexpr-2.10.2-cp312-cp312-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:5191ba8f2975cb9703afc04ae845a929e193498c0e8bcd408ecb147b35978470"},
|
||||
{file = "numexpr-2.10.2-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:97298b14f0105a794bea06fd9fbc5c423bd3ff4d88cbc618860b83eb7a436ad6"},
|
||||
{file = "numexpr-2.10.2-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:f9d7805ccb6be2d3b0f7f6fad3707a09ac537811e8e9964f4074d28cb35543db"},
|
||||
{file = "numexpr-2.10.2-cp312-cp312-win32.whl", hash = "sha256:cb845b2d4f9f8ef0eb1c9884f2b64780a85d3b5ae4eeb26ae2b0019f489cd35e"},
|
||||
{file = "numexpr-2.10.2-cp312-cp312-win_amd64.whl", hash = "sha256:57b59cbb5dcce4edf09cd6ce0b57ff60312479930099ca8d944c2fac896a1ead"},
|
||||
{file = "numexpr-2.10.2-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:a37d6a51ec328c561b2ca8a2bef07025642eca995b8553a5267d0018c732976d"},
|
||||
{file = "numexpr-2.10.2-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:81d1dde7dd6166d8ff5727bb46ab42a6b0048db0e97ceb84a121334a404a800f"},
|
||||
{file = "numexpr-2.10.2-cp313-cp313-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:5b3f814437d5a10797f8d89d2037cca2c9d9fa578520fc911f894edafed6ea3e"},
|
||||
{file = "numexpr-2.10.2-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:9309f2e43fe6e4560699ef5c27d7a848b3ff38549b6b57194207cf0e88900527"},
|
||||
{file = "numexpr-2.10.2-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:ebb73b93f5c4d6994f357fa5a47a9f7a5485577e633b3c46a603cb01445bbb19"},
|
||||
{file = "numexpr-2.10.2-cp313-cp313-win32.whl", hash = "sha256:ec04c9a3c050c175348801e27c18c68d28673b7bfb865ef88ce333be523bbc01"},
|
||||
{file = "numexpr-2.10.2-cp313-cp313-win_amd64.whl", hash = "sha256:d7a3fc83c959288544db3adc70612475d8ad53a66c69198105c74036182d10dd"},
|
||||
{file = "numexpr-2.10.2-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:0495f8111c3633e265248709b8b3b521bbfa646ba384909edd10e2b9a588a83a"},
|
||||
{file = "numexpr-2.10.2-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:2aa05ac71bee3b1253e73173c4d7fa96a09a18970c0226f1c2c07a71ffe988dc"},
|
||||
{file = "numexpr-2.10.2-cp39-cp39-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:c3a23c3002ab330056fbdd2785871937a6f2f2fa85d06c8d0ff74ea8418119d1"},
|
||||
{file = "numexpr-2.10.2-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:a018a7d81326f4c73d8b5aee61794d7d8514512f43957c0db61eb2a8a86848c7"},
|
||||
{file = "numexpr-2.10.2-cp39-cp39-musllinux_1_2_x86_64.whl", hash = "sha256:037859b17a0abe2b489d4c2cfdadd2bf458ec80dd83f338ea5544c7987e06b85"},
|
||||
{file = "numexpr-2.10.2-cp39-cp39-win32.whl", hash = "sha256:eb278ccda6f893a312aa0452701bb17d098b7b14eb7c9381517d509cce0a39a3"},
|
||||
{file = "numexpr-2.10.2-cp39-cp39-win_amd64.whl", hash = "sha256:734b64c6d6a597601ce9d0ef7b666e678ec015b446f1d1412c23903c021436c3"},
|
||||
{file = "numexpr-2.10.2.tar.gz", hash = "sha256:b0aff6b48ebc99d2f54f27b5f73a58cb92fde650aeff1b397c71c8788b4fff1a"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
numpy = ">=1.23.0"
|
||||
|
||||
[[package]]
|
||||
name = "numpy"
|
||||
version = "2.2.2"
|
||||
description = "Fundamental package for array computing in Python"
|
||||
optional = false
|
||||
python-versions = ">=3.10"
|
||||
groups = ["dev"]
|
||||
files = [
|
||||
{file = "numpy-2.2.2-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:7079129b64cb78bdc8d611d1fd7e8002c0a2565da6a47c4df8062349fee90e3e"},
|
||||
{file = "numpy-2.2.2-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:2ec6c689c61df613b783aeb21f945c4cbe6c51c28cb70aae8430577ab39f163e"},
|
||||
{file = "numpy-2.2.2-cp310-cp310-macosx_14_0_arm64.whl", hash = "sha256:40c7ff5da22cd391944a28c6a9c638a5eef77fcf71d6e3a79e1d9d9e82752715"},
|
||||
{file = "numpy-2.2.2-cp310-cp310-macosx_14_0_x86_64.whl", hash = "sha256:995f9e8181723852ca458e22de5d9b7d3ba4da3f11cc1cb113f093b271d7965a"},
|
||||
{file = "numpy-2.2.2-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:b78ea78450fd96a498f50ee096f69c75379af5138f7881a51355ab0e11286c97"},
|
||||
{file = "numpy-2.2.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:3fbe72d347fbc59f94124125e73fc4976a06927ebc503ec5afbfb35f193cd957"},
|
||||
{file = "numpy-2.2.2-cp310-cp310-musllinux_1_2_aarch64.whl", hash = "sha256:8e6da5cffbbe571f93588f562ed130ea63ee206d12851b60819512dd3e1ba50d"},
|
||||
{file = "numpy-2.2.2-cp310-cp310-musllinux_1_2_x86_64.whl", hash = "sha256:09d6a2032faf25e8d0cadde7fd6145118ac55d2740132c1d845f98721b5ebcfd"},
|
||||
{file = "numpy-2.2.2-cp310-cp310-win32.whl", hash = "sha256:159ff6ee4c4a36a23fe01b7c3d07bd8c14cc433d9720f977fcd52c13c0098160"},
|
||||
{file = "numpy-2.2.2-cp310-cp310-win_amd64.whl", hash = "sha256:64bd6e1762cd7f0986a740fee4dff927b9ec2c5e4d9a28d056eb17d332158014"},
|
||||
{file = "numpy-2.2.2-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:642199e98af1bd2b6aeb8ecf726972d238c9877b0f6e8221ee5ab945ec8a2189"},
|
||||
{file = "numpy-2.2.2-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:6d9fc9d812c81e6168b6d405bf00b8d6739a7f72ef22a9214c4241e0dc70b323"},
|
||||
{file = "numpy-2.2.2-cp311-cp311-macosx_14_0_arm64.whl", hash = "sha256:c7d1fd447e33ee20c1f33f2c8e6634211124a9aabde3c617687d8b739aa69eac"},
|
||||
{file = "numpy-2.2.2-cp311-cp311-macosx_14_0_x86_64.whl", hash = "sha256:451e854cfae0febe723077bd0cf0a4302a5d84ff25f0bfece8f29206c7bed02e"},
|
||||
{file = "numpy-2.2.2-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:bd249bc894af67cbd8bad2c22e7cbcd46cf87ddfca1f1289d1e7e54868cc785c"},
|
||||
{file = "numpy-2.2.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:02935e2c3c0c6cbe9c7955a8efa8908dd4221d7755644c59d1bba28b94fd334f"},
|
||||
{file = "numpy-2.2.2-cp311-cp311-musllinux_1_2_aarch64.whl", hash = "sha256:a972cec723e0563aa0823ee2ab1df0cb196ed0778f173b381c871a03719d4826"},
|
||||
{file = "numpy-2.2.2-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:d6d6a0910c3b4368d89dde073e630882cdb266755565155bc33520283b2d9df8"},
|
||||
{file = "numpy-2.2.2-cp311-cp311-win32.whl", hash = "sha256:860fd59990c37c3ef913c3ae390b3929d005243acca1a86facb0773e2d8d9e50"},
|
||||
{file = "numpy-2.2.2-cp311-cp311-win_amd64.whl", hash = "sha256:da1eeb460ecce8d5b8608826595c777728cdf28ce7b5a5a8c8ac8d949beadcf2"},
|
||||
{file = "numpy-2.2.2-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:ac9bea18d6d58a995fac1b2cb4488e17eceeac413af014b1dd26170b766d8467"},
|
||||
{file = "numpy-2.2.2-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:23ae9f0c2d889b7b2d88a3791f6c09e2ef827c2446f1c4a3e3e76328ee4afd9a"},
|
||||
{file = "numpy-2.2.2-cp312-cp312-macosx_14_0_arm64.whl", hash = "sha256:3074634ea4d6df66be04f6728ee1d173cfded75d002c75fac79503a880bf3825"},
|
||||
{file = "numpy-2.2.2-cp312-cp312-macosx_14_0_x86_64.whl", hash = "sha256:8ec0636d3f7d68520afc6ac2dc4b8341ddb725039de042faf0e311599f54eb37"},
|
||||
{file = "numpy-2.2.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:2ffbb1acd69fdf8e89dd60ef6182ca90a743620957afb7066385a7bbe88dc748"},
|
||||
{file = "numpy-2.2.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:0349b025e15ea9d05c3d63f9657707a4e1d471128a3b1d876c095f328f8ff7f0"},
|
||||
{file = "numpy-2.2.2-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:463247edcee4a5537841d5350bc87fe8e92d7dd0e8c71c995d2c6eecb8208278"},
|
||||
{file = "numpy-2.2.2-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:9dd47ff0cb2a656ad69c38da850df3454da88ee9a6fde0ba79acceee0e79daba"},
|
||||
{file = "numpy-2.2.2-cp312-cp312-win32.whl", hash = "sha256:4525b88c11906d5ab1b0ec1f290996c0020dd318af8b49acaa46f198b1ffc283"},
|
||||
{file = "numpy-2.2.2-cp312-cp312-win_amd64.whl", hash = "sha256:5acea83b801e98541619af398cc0109ff48016955cc0818f478ee9ef1c5c3dcb"},
|
||||
{file = "numpy-2.2.2-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:b208cfd4f5fe34e1535c08983a1a6803fdbc7a1e86cf13dd0c61de0b51a0aadc"},
|
||||
{file = "numpy-2.2.2-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:d0bbe7dd86dca64854f4b6ce2ea5c60b51e36dfd597300057cf473d3615f2369"},
|
||||
{file = "numpy-2.2.2-cp313-cp313-macosx_14_0_arm64.whl", hash = "sha256:22ea3bb552ade325530e72a0c557cdf2dea8914d3a5e1fecf58fa5dbcc6f43cd"},
|
||||
{file = "numpy-2.2.2-cp313-cp313-macosx_14_0_x86_64.whl", hash = "sha256:128c41c085cab8a85dc29e66ed88c05613dccf6bc28b3866cd16050a2f5448be"},
|
||||
{file = "numpy-2.2.2-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:250c16b277e3b809ac20d1f590716597481061b514223c7badb7a0f9993c7f84"},
|
||||
{file = "numpy-2.2.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:e0c8854b09bc4de7b041148d8550d3bd712b5c21ff6a8ed308085f190235d7ff"},
|
||||
{file = "numpy-2.2.2-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:b6fb9c32a91ec32a689ec6410def76443e3c750e7cfc3fb2206b985ffb2b85f0"},
|
||||
{file = "numpy-2.2.2-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:57b4012e04cc12b78590a334907e01b3a85efb2107df2b8733ff1ed05fce71de"},
|
||||
{file = "numpy-2.2.2-cp313-cp313-win32.whl", hash = "sha256:4dbd80e453bd34bd003b16bd802fac70ad76bd463f81f0c518d1245b1c55e3d9"},
|
||||
{file = "numpy-2.2.2-cp313-cp313-win_amd64.whl", hash = "sha256:5a8c863ceacae696aff37d1fd636121f1a512117652e5dfb86031c8d84836369"},
|
||||
{file = "numpy-2.2.2-cp313-cp313t-macosx_10_13_x86_64.whl", hash = "sha256:b3482cb7b3325faa5f6bc179649406058253d91ceda359c104dac0ad320e1391"},
|
||||
{file = "numpy-2.2.2-cp313-cp313t-macosx_11_0_arm64.whl", hash = "sha256:9491100aba630910489c1d0158034e1c9a6546f0b1340f716d522dc103788e39"},
|
||||
{file = "numpy-2.2.2-cp313-cp313t-macosx_14_0_arm64.whl", hash = "sha256:41184c416143defa34cc8eb9d070b0a5ba4f13a0fa96a709e20584638254b317"},
|
||||
{file = "numpy-2.2.2-cp313-cp313t-macosx_14_0_x86_64.whl", hash = "sha256:7dca87ca328f5ea7dafc907c5ec100d187911f94825f8700caac0b3f4c384b49"},
|
||||
{file = "numpy-2.2.2-cp313-cp313t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:0bc61b307655d1a7f9f4b043628b9f2b721e80839914ede634e3d485913e1fb2"},
|
||||
{file = "numpy-2.2.2-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:9fad446ad0bc886855ddf5909cbf8cb5d0faa637aaa6277fb4b19ade134ab3c7"},
|
||||
{file = "numpy-2.2.2-cp313-cp313t-musllinux_1_2_aarch64.whl", hash = "sha256:149d1113ac15005652e8d0d3f6fd599360e1a708a4f98e43c9c77834a28238cb"},
|
||||
{file = "numpy-2.2.2-cp313-cp313t-musllinux_1_2_x86_64.whl", hash = "sha256:106397dbbb1896f99e044efc90360d098b3335060375c26aa89c0d8a97c5f648"},
|
||||
{file = "numpy-2.2.2-cp313-cp313t-win32.whl", hash = "sha256:0eec19f8af947a61e968d5429f0bd92fec46d92b0008d0a6685b40d6adf8a4f4"},
|
||||
{file = "numpy-2.2.2-cp313-cp313t-win_amd64.whl", hash = "sha256:97b974d3ba0fb4612b77ed35d7627490e8e3dff56ab41454d9e8b23448940576"},
|
||||
{file = "numpy-2.2.2-pp310-pypy310_pp73-macosx_10_15_x86_64.whl", hash = "sha256:b0531f0b0e07643eb089df4c509d30d72c9ef40defa53e41363eca8a8cc61495"},
|
||||
{file = "numpy-2.2.2-pp310-pypy310_pp73-macosx_14_0_x86_64.whl", hash = "sha256:e9e82dcb3f2ebbc8cb5ce1102d5f1c5ed236bf8a11730fb45ba82e2841ec21df"},
|
||||
{file = "numpy-2.2.2-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:e0d4142eb40ca6f94539e4db929410f2a46052a0fe7a2c1c59f6179c39938d2a"},
|
||||
{file = "numpy-2.2.2-pp310-pypy310_pp73-win_amd64.whl", hash = "sha256:356ca982c188acbfa6af0d694284d8cf20e95b1c3d0aefa8929376fea9146f60"},
|
||||
{file = "numpy-2.2.2.tar.gz", hash = "sha256:ed6906f61834d687738d25988ae117683705636936cc605be0bb208b23df4d8f"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pygments"
|
||||
version = "2.19.1"
|
||||
description = "Pygments is a syntax highlighting package written in Python."
|
||||
optional = false
|
||||
python-versions = ">=3.8"
|
||||
groups = ["dev"]
|
||||
files = [
|
||||
{file = "pygments-2.19.1-py3-none-any.whl", hash = "sha256:9ea1544ad55cecf4b8242fab6dd35a93bbce657034b0611ee383099054ab6d8c"},
|
||||
{file = "pygments-2.19.1.tar.gz", hash = "sha256:61c16d2a8576dc0649d9f39e089b5f02bcd27fba10d8fb4dcc28173f7a45151f"},
|
||||
]
|
||||
|
||||
[package.extras]
|
||||
windows-terminal = ["colorama (>=0.4.6)"]
|
||||
|
||||
[[package]]
|
||||
name = "requests"
|
||||
version = "2.32.3"
|
||||
description = "Python HTTP for Humans."
|
||||
optional = false
|
||||
python-versions = ">=3.8"
|
||||
groups = ["dev"]
|
||||
files = [
|
||||
{file = "requests-2.32.3-py3-none-any.whl", hash = "sha256:70761cfe03c773ceb22aa2f671b4757976145175cdfca038c02654d061d6dcc6"},
|
||||
{file = "requests-2.32.3.tar.gz", hash = "sha256:55365417734eb18255590a9ff9eb97e9e1da868d4ccd6402399eaf68af20a760"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
certifi = ">=2017.4.17"
|
||||
charset-normalizer = ">=2,<4"
|
||||
idna = ">=2.5,<4"
|
||||
urllib3 = ">=1.21.1,<3"
|
||||
|
||||
[package.extras]
|
||||
socks = ["PySocks (>=1.5.6,!=1.5.7)"]
|
||||
use-chardet-on-py3 = ["chardet (>=3.0.2,<6)"]
|
||||
|
||||
[[package]]
|
||||
name = "rich"
|
||||
version = "13.9.4"
|
||||
description = "Render rich text, tables, progress bars, syntax highlighting, markdown and more to the terminal"
|
||||
optional = false
|
||||
python-versions = ">=3.8.0"
|
||||
groups = ["dev"]
|
||||
files = [
|
||||
{file = "rich-13.9.4-py3-none-any.whl", hash = "sha256:6049d5e6ec054bf2779ab3358186963bac2ea89175919d699e378b99738c2a90"},
|
||||
{file = "rich-13.9.4.tar.gz", hash = "sha256:439594978a49a09530cff7ebc4b5c7103ef57baf48d5ea3184f21d9a2befa098"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
markdown-it-py = ">=2.2.0"
|
||||
pygments = ">=2.13.0,<3.0.0"
|
||||
|
||||
[package.extras]
|
||||
jupyter = ["ipywidgets (>=7.5.1,<9)"]
|
||||
|
||||
[[package]]
|
||||
name = "setuptools"
|
||||
version = "75.8.0"
|
||||
description = "Easily download, build, install, upgrade, and uninstall Python packages"
|
||||
optional = false
|
||||
python-versions = ">=3.9"
|
||||
groups = ["dev"]
|
||||
files = [
|
||||
{file = "setuptools-75.8.0-py3-none-any.whl", hash = "sha256:e3982f444617239225d675215d51f6ba05f845d4eec313da4418fdbb56fb27e3"},
|
||||
{file = "setuptools-75.8.0.tar.gz", hash = "sha256:c5afc8f407c626b8313a86e10311dd3f661c6cd9c09d4bf8c15c0e11f9f2b0e6"},
|
||||
]
|
||||
|
||||
[package.extras]
|
||||
check = ["pytest-checkdocs (>=2.4)", "pytest-ruff (>=0.2.1)", "ruff (>=0.8.0)"]
|
||||
core = ["importlib_metadata (>=6)", "jaraco.collections", "jaraco.functools (>=4)", "jaraco.text (>=3.7)", "more_itertools", "more_itertools (>=8.8)", "packaging", "packaging (>=24.2)", "platformdirs (>=4.2.2)", "tomli (>=2.0.1)", "wheel (>=0.43.0)"]
|
||||
cover = ["pytest-cov"]
|
||||
doc = ["furo", "jaraco.packaging (>=9.3)", "jaraco.tidelift (>=1.4)", "pygments-github-lexers (==0.0.5)", "pyproject-hooks (!=1.1)", "rst.linker (>=1.9)", "sphinx (>=3.5)", "sphinx-favicon", "sphinx-inline-tabs", "sphinx-lint", "sphinx-notfound-page (>=1,<2)", "sphinx-reredirects", "sphinxcontrib-towncrier", "towncrier (<24.7)"]
|
||||
enabler = ["pytest-enabler (>=2.2)"]
|
||||
test = ["build[virtualenv] (>=1.0.3)", "filelock (>=3.4.0)", "ini2toml[lite] (>=0.14)", "jaraco.develop (>=7.21)", "jaraco.envs (>=2.2)", "jaraco.path (>=3.7.2)", "jaraco.test (>=5.5)", "packaging (>=24.2)", "pip (>=19.1)", "pyproject-hooks (!=1.1)", "pytest (>=6,!=8.1.*)", "pytest-home (>=0.5)", "pytest-perf", "pytest-subprocess", "pytest-timeout", "pytest-xdist (>=3)", "tomli-w (>=1.0.0)", "virtualenv (>=13.0.0)", "wheel (>=0.44.0)"]
|
||||
type = ["importlib_metadata (>=7.0.2)", "jaraco.develop (>=7.21)", "mypy (==1.14.*)", "pytest-mypy"]
|
||||
|
||||
[[package]]
|
||||
name = "tqdm"
|
||||
version = "4.67.1"
|
||||
description = "Fast, Extensible Progress Meter"
|
||||
optional = false
|
||||
python-versions = ">=3.7"
|
||||
groups = ["dev"]
|
||||
files = [
|
||||
{file = "tqdm-4.67.1-py3-none-any.whl", hash = "sha256:26445eca388f82e72884e0d580d5464cd801a3ea01e63e5601bdff9ba6a48de2"},
|
||||
{file = "tqdm-4.67.1.tar.gz", hash = "sha256:f8aef9c52c08c13a65f30ea34f4e5aac3fd1a34959879d7e59e63027286627f2"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
colorama = {version = "*", markers = "platform_system == \"Windows\""}
|
||||
|
||||
[package.extras]
|
||||
dev = ["nbval", "pytest (>=6)", "pytest-asyncio (>=0.24)", "pytest-cov", "pytest-timeout"]
|
||||
discord = ["requests"]
|
||||
notebook = ["ipywidgets (>=6)"]
|
||||
slack = ["slack-sdk"]
|
||||
telegram = ["requests"]
|
||||
|
||||
[[package]]
|
||||
name = "urllib3"
|
||||
version = "2.3.0"
|
||||
description = "HTTP library with thread-safe connection pooling, file post, and more."
|
||||
optional = false
|
||||
python-versions = ">=3.9"
|
||||
groups = ["dev"]
|
||||
files = [
|
||||
{file = "urllib3-2.3.0-py3-none-any.whl", hash = "sha256:1cee9ad369867bfdbbb48b7dd50374c0967a0bb7710050facf0dd6911440e3df"},
|
||||
{file = "urllib3-2.3.0.tar.gz", hash = "sha256:f8c5449b3cf0861679ce7e0503c7b44b5ec981bec0d1d3795a07f1ba96f0204d"},
|
||||
]
|
||||
|
||||
[package.extras]
|
||||
brotli = ["brotli (>=1.0.9)", "brotlicffi (>=0.8.0)"]
|
||||
h2 = ["h2 (>=4,<5)"]
|
||||
socks = ["pysocks (>=1.5.6,!=1.5.7,<2.0)"]
|
||||
zstd = ["zstandard (>=0.18.0)"]
|
||||
|
||||
[[package]]
|
||||
name = "word2number"
|
||||
version = "1.1"
|
||||
description = "Convert number words eg. three hundred and forty two to numbers (342)."
|
||||
optional = false
|
||||
python-versions = "*"
|
||||
groups = ["dev"]
|
||||
files = [
|
||||
{file = "word2number-1.1.zip", hash = "sha256:70e27a5d387f67b04c71fbb7621c05930b19bfd26efd6851e6e0f9969dcde7d0"},
|
||||
]
|
||||
|
||||
[metadata]
|
||||
lock-version = "2.1"
|
||||
python-versions = ">=3.11"
|
||||
content-hash = "6d71ae12bf4fc44dab312c9626aff93bbc4f5928bf439f144c07de5d9c93d43f"
|
||||
@@ -1,28 +1,36 @@
|
||||
[project]
|
||||
name = "argenta"
|
||||
version = "0.1.3"
|
||||
description = "python library for creating cli apps"
|
||||
authors = [
|
||||
{name = "kolo",email = "kolo.is.main@gmail.com"}
|
||||
]
|
||||
license = {text = "MIT"}
|
||||
readme = "README.md"
|
||||
version = "1.1.1"
|
||||
description = "Python library for building modular CLI applications"
|
||||
authors = [{ name = "kolo", email = "kolo.is.main@gmail.com" }]
|
||||
requires-python = ">=3.11"
|
||||
readme = "README.md"
|
||||
license = { text = "MIT" }
|
||||
dependencies = [
|
||||
"rich (>=14.0.0,<15.0.0)",
|
||||
"art (>=6.4,<7.0)",
|
||||
"pyreadline3>=3.5.4",
|
||||
]
|
||||
|
||||
[tool.ruff]
|
||||
exclude = [
|
||||
".idea",
|
||||
"venv",
|
||||
".git",
|
||||
"poetry.lock",
|
||||
".__pycache__",
|
||||
"tests"
|
||||
]
|
||||
|
||||
[build-system]
|
||||
requires = ["poetry-core>=2.0.0,<3.0.0"]
|
||||
build-backend = "poetry.core.masonry.api"
|
||||
requires = ["hatchling"]
|
||||
build-backend = "hatchling.build"
|
||||
|
||||
[tool.poetry.group.dev.dependencies]
|
||||
art = "^6.4"
|
||||
rich = "^13.9.4"
|
||||
numpy = "^2.2.2"
|
||||
word2number = "^1.1"
|
||||
numexpr = "^2.10.2"
|
||||
requests = "^2.32.3"
|
||||
tqdm = "^4.67.1"
|
||||
setuptools = "^75.8.0"
|
||||
[dependency-groups]
|
||||
dev = [
|
||||
"mypy>=1.14.1",
|
||||
"pytest>=8.3.2",
|
||||
"ruff>=0.12.12",
|
||||
"wemake-python-styleguide>=0.17.0",
|
||||
]
|
||||
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
from setuptools import setup, find_packages
|
||||
|
||||
with open("README.md", "r", encoding="utf-8") as fh:
|
||||
long_description = fh.read()
|
||||
|
||||
setup(
|
||||
name="argenta",
|
||||
version="0.1.3",
|
||||
author="kolo",
|
||||
author_email="kolo.is.main@gmail.com",
|
||||
description="Python library for creating CLI apps",
|
||||
long_description=long_description,
|
||||
long_description_content_type="text/markdown",
|
||||
packages=find_packages(),
|
||||
install_requires=[
|
||||
"requests",
|
||||
],
|
||||
classifiers=[
|
||||
"Programming Language :: Python :: 3",
|
||||
"Operating System :: OS Independent",
|
||||
],
|
||||
python_requires='>=3.11',
|
||||
)
|
||||
@@ -0,0 +1,10 @@
|
||||
__all__ = [
|
||||
'App',
|
||||
'Orchestrator',
|
||||
'Router',
|
||||
]
|
||||
|
||||
|
||||
from argenta.app import App
|
||||
from argenta.orchestrator import Orchestrator
|
||||
from argenta.router import Router
|
||||
@@ -0,0 +1,12 @@
|
||||
__all__ = [
|
||||
"App",
|
||||
"PredefinedMessages",
|
||||
"DynamicDividingLine",
|
||||
"StaticDividingLine",
|
||||
"AutoCompleter"
|
||||
]
|
||||
|
||||
from argenta.app.models import App
|
||||
from argenta.app.defaults import PredefinedMessages
|
||||
from argenta.app.dividing_line.models import DynamicDividingLine, StaticDividingLine
|
||||
from argenta.app.autocompleter.entity import AutoCompleter
|
||||
@@ -0,0 +1,4 @@
|
||||
__all__ = ["AutoCompleter"]
|
||||
|
||||
|
||||
from argenta.app.autocompleter.entity import AutoCompleter
|
||||
@@ -0,0 +1,90 @@
|
||||
import os
|
||||
import readline
|
||||
from typing import Never
|
||||
|
||||
|
||||
class AutoCompleter:
|
||||
def __init__(
|
||||
self, history_filename: str | None = None, autocomplete_button: str = "tab"
|
||||
) -> None:
|
||||
"""
|
||||
Public. Configures and implements auto-completion of input command
|
||||
:param history_filename: the name of the file for saving the history of the autocompleter
|
||||
:param autocomplete_button: the button for auto-completion
|
||||
:return: None
|
||||
"""
|
||||
self.history_filename: str | None = history_filename
|
||||
self.autocomplete_button: str = autocomplete_button
|
||||
|
||||
def _complete(self, text: str, state: int) -> str | None:
|
||||
"""
|
||||
Private. Auto-completion function
|
||||
:param text: part of the command being entered
|
||||
:param state: the current cursor position is relative to the beginning of the line
|
||||
:return: the desired candidate as str or None
|
||||
"""
|
||||
matches: list[str] = sorted(
|
||||
cmd for cmd in _get_history_items() if cmd.startswith(text)
|
||||
)
|
||||
if len(matches) > 1:
|
||||
common_prefix = matches[0]
|
||||
for match in matches[1:]:
|
||||
i = 0
|
||||
while (
|
||||
i < len(common_prefix)
|
||||
and i < len(match)
|
||||
and common_prefix[i] == match[i]
|
||||
):
|
||||
i += 1
|
||||
common_prefix = common_prefix[:i]
|
||||
if state == 0:
|
||||
readline.insert_text(common_prefix[len(text) :])
|
||||
readline.redisplay()
|
||||
return None
|
||||
elif len(matches) == 1:
|
||||
return matches[0] if state == 0 else None
|
||||
else:
|
||||
return None
|
||||
|
||||
def initial_setup(self, all_commands: list[str]) -> None:
|
||||
"""
|
||||
Private. Initial setup function
|
||||
:param all_commands: Registered commands for adding them to the autocomplete history
|
||||
:return: None
|
||||
"""
|
||||
if self.history_filename:
|
||||
if os.path.exists(self.history_filename):
|
||||
readline.read_history_file(self.history_filename)
|
||||
else:
|
||||
for line in all_commands:
|
||||
readline.add_history(line)
|
||||
|
||||
readline.set_completer(self._complete)
|
||||
readline.set_completer_delims(readline.get_completer_delims().replace(" ", ""))
|
||||
readline.parse_and_bind(f"{self.autocomplete_button}: complete")
|
||||
|
||||
def exit_setup(self, all_commands: list[str]) -> None:
|
||||
"""
|
||||
Private. Exit setup function
|
||||
:return: None
|
||||
"""
|
||||
if self.history_filename:
|
||||
readline.write_history_file(self.history_filename)
|
||||
with open(self.history_filename, "r") as history_file:
|
||||
raw_history = history_file.read()
|
||||
pretty_history: list[str] = []
|
||||
for line in set(raw_history.strip().split("\n")):
|
||||
if line.split()[0] in all_commands:
|
||||
pretty_history.append(line)
|
||||
with open(self.history_filename, "w") as history_file:
|
||||
_ = history_file.write("\n".join(pretty_history))
|
||||
|
||||
def _get_history_items() -> list[str] | list[Never]:
|
||||
"""
|
||||
Private. Returns a list of all commands entered by the user
|
||||
:return: all commands entered by the user as list[str] | list[Never]
|
||||
"""
|
||||
return [
|
||||
readline.get_history_item(i)
|
||||
for i in range(1, readline.get_current_history_length() + 1)
|
||||
]
|
||||
@@ -0,0 +1,10 @@
|
||||
from enum import StrEnum
|
||||
|
||||
|
||||
class PredefinedMessages(StrEnum):
|
||||
"""
|
||||
Public. A dataclass with predetermined messages for quick use
|
||||
"""
|
||||
USAGE = "[b dim]Usage[/b dim]: [i]<command> <[green]flags[/green]>[/i]"
|
||||
HELP = "[b dim]Help[/b dim]: [i]<command>[/i] [b red]--help[/b red]"
|
||||
AUTOCOMPLETE = "[b dim]Autocomplete[/b dim]: [i]<part>[/i] [bold]<tab>"
|
||||
@@ -0,0 +1,4 @@
|
||||
__all__ = ["StaticDividingLine", "DynamicDividingLine"]
|
||||
|
||||
|
||||
from argenta.app.dividing_line.models import StaticDividingLine, DynamicDividingLine
|
||||
@@ -0,0 +1,66 @@
|
||||
from abc import ABC
|
||||
|
||||
|
||||
class BaseDividingLine(ABC):
|
||||
def __init__(self, unit_part: str = "-") -> None:
|
||||
"""
|
||||
Private. The basic dividing line
|
||||
:param unit_part: the single part of the dividing line
|
||||
:return: None
|
||||
"""
|
||||
self._unit_part: str = unit_part
|
||||
|
||||
def get_unit_part(self) -> str:
|
||||
"""
|
||||
Private. Returns the unit part of the dividing line
|
||||
:return: unit_part of dividing line as str
|
||||
"""
|
||||
if len(self._unit_part) == 0:
|
||||
return " "
|
||||
else:
|
||||
return self._unit_part[0]
|
||||
|
||||
|
||||
class StaticDividingLine(BaseDividingLine):
|
||||
def __init__(self, unit_part: str = "-", *, length: int = 25) -> None:
|
||||
"""
|
||||
Public. The static dividing line
|
||||
:param unit_part: the single part of the dividing line
|
||||
:param length: the length of the dividing line
|
||||
:return: None
|
||||
"""
|
||||
super().__init__(unit_part)
|
||||
self.length: int = length
|
||||
|
||||
def get_full_static_line(self, *, is_override: bool) -> str:
|
||||
"""
|
||||
Private. Returns the full line of the dividing line
|
||||
:param is_override: has the default text layout been redefined
|
||||
:return: full line of dividing line as str
|
||||
"""
|
||||
if is_override:
|
||||
return f"\n{self.length * self.get_unit_part()}\n"
|
||||
else:
|
||||
return f"\n[dim]{self.length * self.get_unit_part()}[/dim]\n"
|
||||
|
||||
|
||||
class DynamicDividingLine(BaseDividingLine):
|
||||
def __init__(self, unit_part: str = "-") -> None:
|
||||
"""
|
||||
Public. The dynamic dividing line
|
||||
:param unit_part: the single part of the dividing line
|
||||
:return: None
|
||||
"""
|
||||
super().__init__(unit_part)
|
||||
|
||||
def get_full_dynamic_line(self, *, length: int, is_override: bool) -> str:
|
||||
"""
|
||||
Private. Returns the full line of the dividing line
|
||||
:param length: the length of the dividing line
|
||||
:param is_override: has the default text layout been redefined
|
||||
:return: full line of dividing line as str
|
||||
"""
|
||||
if is_override:
|
||||
return f"\n{length * self.get_unit_part()}\n"
|
||||
else:
|
||||
return f"\n[dim]{self.get_unit_part() * length}[/dim]\n"
|
||||
@@ -0,0 +1,471 @@
|
||||
import io
|
||||
import re
|
||||
from contextlib import redirect_stdout
|
||||
from typing import Never, TypeAlias
|
||||
|
||||
from art import text2art # pyright: ignore[reportMissingTypeStubs, reportUnknownVariableType]
|
||||
from rich.console import Console
|
||||
from rich.markup import escape
|
||||
|
||||
from argenta.app.autocompleter import AutoCompleter
|
||||
from argenta.app.dividing_line.models import DynamicDividingLine, StaticDividingLine
|
||||
from argenta.app.protocols import (
|
||||
DescriptionMessageGenerator,
|
||||
EmptyCommandHandler,
|
||||
NonStandardBehaviorHandler,
|
||||
Printer,
|
||||
)
|
||||
from argenta.app.registered_routers.entity import RegisteredRouters
|
||||
from argenta.command.exceptions import (
|
||||
EmptyInputCommandException,
|
||||
InputCommandException,
|
||||
RepeatedInputFlagsException,
|
||||
UnprocessedInputFlagException,
|
||||
)
|
||||
from argenta.command.models import Command, InputCommand
|
||||
from argenta.response import Response
|
||||
from argenta.router import Router
|
||||
from argenta.router.defaults import system_router
|
||||
|
||||
Matches: TypeAlias = list[str] | list[Never]
|
||||
|
||||
|
||||
class BaseApp:
|
||||
def __init__(self, *, prompt: str,
|
||||
initial_message: str,
|
||||
farewell_message: str,
|
||||
exit_command: Command,
|
||||
system_router_title: str | None,
|
||||
ignore_command_register: bool,
|
||||
dividing_line: StaticDividingLine | DynamicDividingLine,
|
||||
repeat_command_groups: bool,
|
||||
override_system_messages: bool,
|
||||
autocompleter: AutoCompleter,
|
||||
print_func: Printer) -> None:
|
||||
self._prompt: str = prompt
|
||||
self._print_func: Printer = print_func
|
||||
self._exit_command: Command = exit_command
|
||||
self._system_router_title: str | None = system_router_title
|
||||
self._dividing_line: StaticDividingLine | DynamicDividingLine = dividing_line
|
||||
self._ignore_command_register: bool = ignore_command_register
|
||||
self._repeat_command_groups_description: bool = repeat_command_groups
|
||||
self._override_system_messages: bool = override_system_messages
|
||||
self._autocompleter: AutoCompleter = autocompleter
|
||||
|
||||
self._farewell_message: str = farewell_message
|
||||
self._initial_message: str = initial_message
|
||||
|
||||
self._description_message_gen: DescriptionMessageGenerator = lambda command, description: f"{command} *=*=* {description}"
|
||||
self._registered_routers: RegisteredRouters = RegisteredRouters()
|
||||
self._messages_on_startup: list[str] = []
|
||||
|
||||
self._matching_lower_triggers_with_routers: dict[str, Router] = {}
|
||||
self._matching_default_triggers_with_routers: dict[str, Router] = {}
|
||||
|
||||
self._current_matching_triggers_with_routers: dict[str, Router] = self._matching_lower_triggers_with_routers if self._ignore_command_register else self._matching_default_triggers_with_routers
|
||||
|
||||
self._incorrect_input_syntax_handler: NonStandardBehaviorHandler[str] = lambda _: print_func(f"Incorrect flag syntax: {_}")
|
||||
self._repeated_input_flags_handler: NonStandardBehaviorHandler[str] = lambda _: print_func(f"Repeated input flags: {_}")
|
||||
self._empty_input_command_handler: EmptyCommandHandler = lambda: print_func("Empty input command")
|
||||
self._unknown_command_handler: NonStandardBehaviorHandler[InputCommand] = lambda _: print_func(f"Unknown command: {_.trigger}")
|
||||
self._exit_command_handler: NonStandardBehaviorHandler[Response] = lambda _: print_func(self._farewell_message)
|
||||
|
||||
def set_description_message_pattern(self, _: DescriptionMessageGenerator, /) -> None:
|
||||
"""
|
||||
Public. Sets the output pattern of the available commands
|
||||
:param _: output pattern of the available commands
|
||||
:return: None
|
||||
"""
|
||||
self._description_message_gen = _
|
||||
|
||||
def set_incorrect_input_syntax_handler(self, _: NonStandardBehaviorHandler[str], /) -> None:
|
||||
"""
|
||||
Public. Sets the handler for incorrect flags when entering a command
|
||||
:param _: handler for incorrect flags when entering a command
|
||||
:return: None
|
||||
"""
|
||||
self._incorrect_input_syntax_handler = _
|
||||
|
||||
def set_repeated_input_flags_handler(self, _: NonStandardBehaviorHandler[str], /) -> None:
|
||||
"""
|
||||
Public. Sets the handler for repeated flags when entering a command
|
||||
:param _: handler for repeated flags when entering a command
|
||||
:return: None
|
||||
"""
|
||||
self._repeated_input_flags_handler = _
|
||||
|
||||
def set_unknown_command_handler(self, _: NonStandardBehaviorHandler[InputCommand], /) -> None:
|
||||
"""
|
||||
Public. Sets the handler for unknown commands when entering a command
|
||||
:param _: handler for unknown commands when entering a command
|
||||
:return: None
|
||||
"""
|
||||
self._unknown_command_handler = _
|
||||
|
||||
def set_empty_command_handler(self, _: EmptyCommandHandler, /) -> None:
|
||||
"""
|
||||
Public. Sets the handler for empty commands when entering a command
|
||||
:param _: handler for empty commands when entering a command
|
||||
:return: None
|
||||
"""
|
||||
self._empty_input_command_handler = _
|
||||
|
||||
def set_exit_command_handler(self, _: NonStandardBehaviorHandler[Response], /) -> None:
|
||||
"""
|
||||
Public. Sets the handler for exit command when entering a command
|
||||
:param _: handler for exit command when entering a command
|
||||
:return: None
|
||||
"""
|
||||
self._exit_command_handler = _
|
||||
|
||||
def _print_command_group_description(self) -> None:
|
||||
"""
|
||||
Private. Prints the description of the available commands
|
||||
:return: None
|
||||
"""
|
||||
for registered_router in self._registered_routers:
|
||||
if registered_router.title:
|
||||
self._print_func(registered_router.title)
|
||||
for command_handler in registered_router.command_handlers:
|
||||
handled_command = command_handler.handled_command
|
||||
self._print_func(
|
||||
self._description_message_gen(
|
||||
handled_command.trigger,
|
||||
handled_command.description,
|
||||
)
|
||||
)
|
||||
self._print_func("")
|
||||
|
||||
def _print_framed_text(self, text: str) -> None:
|
||||
"""
|
||||
Private. Outputs text by framing it in a static or dynamic split strip
|
||||
:param text: framed text
|
||||
:return: None
|
||||
"""
|
||||
if isinstance(self._dividing_line, DynamicDividingLine):
|
||||
clear_text = re.sub(r"\u001b\[[0-9;]*m", "", text)
|
||||
max_length_line = max([len(line) for line in clear_text.split("\n")])
|
||||
max_length_line = (
|
||||
max_length_line
|
||||
if 10 <= max_length_line <= 80
|
||||
else 80
|
||||
if max_length_line > 80
|
||||
else 10
|
||||
)
|
||||
|
||||
self._print_func(
|
||||
self._dividing_line.get_full_dynamic_line(
|
||||
length=max_length_line, is_override=self._override_system_messages
|
||||
)
|
||||
)
|
||||
print(text.strip("\n"))
|
||||
self._print_func(
|
||||
self._dividing_line.get_full_dynamic_line(
|
||||
length=max_length_line, is_override=self._override_system_messages
|
||||
)
|
||||
)
|
||||
|
||||
elif isinstance(self._dividing_line, StaticDividingLine): # pyright: ignore[reportUnnecessaryIsInstance]
|
||||
self._print_func(
|
||||
self._dividing_line.get_full_static_line(is_override=self._override_system_messages)
|
||||
)
|
||||
print(text.strip("\n"))
|
||||
self._print_func(
|
||||
self._dividing_line.get_full_static_line(is_override=self._override_system_messages)
|
||||
)
|
||||
|
||||
else:
|
||||
raise NotImplementedError
|
||||
|
||||
def _is_exit_command(self, command: InputCommand) -> bool:
|
||||
"""
|
||||
Private. Checks if the given command is an exit command
|
||||
:param command: command to check
|
||||
:return: is it an exit command or not as bool
|
||||
"""
|
||||
trigger = command.trigger
|
||||
exit_trigger = self._exit_command.trigger
|
||||
if self._ignore_command_register:
|
||||
if (
|
||||
trigger.lower() == exit_trigger.lower()
|
||||
):
|
||||
return True
|
||||
elif trigger.lower() in [
|
||||
x.lower() for x in self._exit_command.aliases
|
||||
]:
|
||||
return True
|
||||
else:
|
||||
if trigger == exit_trigger:
|
||||
return True
|
||||
elif trigger in self._exit_command.aliases:
|
||||
return True
|
||||
return False
|
||||
|
||||
def _is_unknown_command(self, command: InputCommand) -> bool:
|
||||
"""
|
||||
Private. Checks if the given command is an unknown command
|
||||
:param command: command to check
|
||||
:return: is it an unknown command or not as bool
|
||||
"""
|
||||
input_command_trigger = command.trigger
|
||||
if self._ignore_command_register:
|
||||
if input_command_trigger.lower() in list(self._current_matching_triggers_with_routers.keys()):
|
||||
return False
|
||||
else:
|
||||
if input_command_trigger in list(self._current_matching_triggers_with_routers.keys()):
|
||||
return False
|
||||
return True
|
||||
|
||||
def _error_handler(
|
||||
self, error: InputCommandException, raw_command: str
|
||||
) -> None:
|
||||
"""
|
||||
Private. Handles parsing errors of the entered command
|
||||
:param error: error being handled
|
||||
:param raw_command: the raw input command
|
||||
:return: None
|
||||
"""
|
||||
if isinstance(error, UnprocessedInputFlagException):
|
||||
self._incorrect_input_syntax_handler(raw_command)
|
||||
elif isinstance(error, RepeatedInputFlagsException):
|
||||
self._repeated_input_flags_handler(raw_command)
|
||||
elif isinstance(error, EmptyInputCommandException):
|
||||
self._empty_input_command_handler()
|
||||
|
||||
def _setup_system_router(self) -> None:
|
||||
"""
|
||||
Private. Sets up system router
|
||||
:return: None
|
||||
"""
|
||||
system_router.title = self._system_router_title
|
||||
|
||||
@system_router.command(self._exit_command)
|
||||
def _(response: Response) -> None:
|
||||
self._exit_command_handler(response)
|
||||
|
||||
if system_router not in self._registered_routers.registered_routers:
|
||||
system_router.command_register_ignore = self._ignore_command_register
|
||||
self._registered_routers.add_registered_router(system_router)
|
||||
|
||||
def _most_similar_command(self, unknown_command: str) -> str | None:
|
||||
all_commands = list(self._current_matching_triggers_with_routers.keys())
|
||||
|
||||
matches_startswith_unknown_command: Matches = sorted(
|
||||
cmd for cmd in all_commands if cmd.startswith(unknown_command)
|
||||
)
|
||||
matches_startswith_cmd: Matches = sorted(
|
||||
cmd for cmd in all_commands if unknown_command.startswith(cmd)
|
||||
)
|
||||
|
||||
matches: Matches = matches_startswith_unknown_command or matches_startswith_cmd
|
||||
|
||||
if len(matches) == 1:
|
||||
return matches[0]
|
||||
elif len(matches) > 1:
|
||||
return sorted(matches, key=lambda cmd: len(cmd))[0]
|
||||
else:
|
||||
return None
|
||||
|
||||
def _setup_default_view(self) -> None:
|
||||
"""
|
||||
Private. Sets up default app view
|
||||
:return: None
|
||||
"""
|
||||
self._prompt = f"[italic dim bold]{self._prompt}"
|
||||
self._initial_message = ("\n" + f"[bold red]{text2art(self._initial_message, font='tarty1')}" + "\n")
|
||||
self._farewell_message = (
|
||||
"[bold red]\n\n" +
|
||||
str(text2art(self._farewell_message, font="chanky")) + # pyright: ignore[reportUnknownArgumentType]
|
||||
"\n[/bold red]\n" +
|
||||
"[red i]github.com/koloideal/Argenta[/red i] | [red bold i]made by kolo[/red bold i]\n"
|
||||
)
|
||||
self._description_message_gen = lambda command, description: (
|
||||
f"[bold red]{escape('[' + command + ']')}[/bold red] "
|
||||
f"[blue dim]*=*=*[/blue dim] "
|
||||
f"[bold yellow italic]{escape(description)}"
|
||||
)
|
||||
self._incorrect_input_syntax_handler = lambda raw_command: self._print_func(f"[red bold]Incorrect flag syntax: {escape(raw_command)}")
|
||||
self._repeated_input_flags_handler = lambda raw_command: self._print_func(f"[red bold]Repeated input flags: {escape(raw_command)}")
|
||||
self._empty_input_command_handler = lambda: self._print_func("[red bold]Empty input command")
|
||||
|
||||
def unknown_command_handler(command: InputCommand) -> None:
|
||||
cmd_trg: str = command.trigger
|
||||
mst_sim_cmd: str | None = self._most_similar_command(cmd_trg)
|
||||
first_part_of_text = f"[red]Unknown command:[/red] [blue]{escape(cmd_trg)}[/blue]"
|
||||
second_part_of_text = (
|
||||
("[red], most similar:[/red] " + ("[blue]" + mst_sim_cmd + "[/blue]"))
|
||||
if mst_sim_cmd
|
||||
else ""
|
||||
)
|
||||
self._print_func(first_part_of_text + second_part_of_text)
|
||||
|
||||
self._unknown_command_handler = unknown_command_handler
|
||||
|
||||
def _pre_cycle_setup(self) -> None:
|
||||
"""
|
||||
Private. Configures various aspects of the application before the start of the cycle
|
||||
:return: None
|
||||
"""
|
||||
self._setup_system_router()
|
||||
|
||||
for router_entity in self._registered_routers:
|
||||
router_triggers = router_entity.triggers
|
||||
router_aliases = router_entity.aliases
|
||||
combined = router_triggers + router_aliases
|
||||
|
||||
for trigger in combined:
|
||||
self._matching_default_triggers_with_routers[trigger] = router_entity
|
||||
self._matching_lower_triggers_with_routers[trigger.lower()] = router_entity
|
||||
|
||||
self._autocompleter.initial_setup(list(self._current_matching_triggers_with_routers.keys()))
|
||||
|
||||
seen = {}
|
||||
for item in list(self._current_matching_triggers_with_routers.keys()):
|
||||
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:
|
||||
self._setup_default_view()
|
||||
|
||||
self._print_func(self._initial_message)
|
||||
|
||||
for message in self._messages_on_startup:
|
||||
self._print_func(message)
|
||||
if self._messages_on_startup:
|
||||
print("\n")
|
||||
if not self._repeat_command_groups_description:
|
||||
self._print_command_group_description()
|
||||
|
||||
|
||||
AVAILABLE_DIVIDING_LINES: TypeAlias = StaticDividingLine | DynamicDividingLine
|
||||
DEFAULT_DIVIDING_LINE: StaticDividingLine = StaticDividingLine()
|
||||
|
||||
DEFAULT_PRINT_FUNC: Printer = Console().print
|
||||
DEFAULT_AUTOCOMPLETER: AutoCompleter = AutoCompleter()
|
||||
DEFAULT_EXIT_COMMAND: Command = Command("Q", description="Exit command")
|
||||
|
||||
|
||||
class App(BaseApp):
|
||||
def __init__(
|
||||
self, *,
|
||||
prompt: str = "What do you want to do?\n\n",
|
||||
initial_message: str = "Argenta\n",
|
||||
farewell_message: str = "\nSee you\n",
|
||||
exit_command: Command = DEFAULT_EXIT_COMMAND,
|
||||
system_router_title: str | None = "System points:",
|
||||
ignore_command_register: bool = True,
|
||||
dividing_line: AVAILABLE_DIVIDING_LINES = DEFAULT_DIVIDING_LINE,
|
||||
repeat_command_groups: bool = True,
|
||||
override_system_messages: bool = False,
|
||||
autocompleter: AutoCompleter = DEFAULT_AUTOCOMPLETER,
|
||||
print_func: Printer = DEFAULT_PRINT_FUNC,
|
||||
) -> None:
|
||||
"""
|
||||
Public. The essence of the application itself.
|
||||
Configures and manages all aspects of the behavior and presentation of the user interacting with the user
|
||||
:param prompt: displayed before entering the command
|
||||
:param initial_message: displayed at the start of the app
|
||||
:param farewell_message: displayed at the end of the app
|
||||
:param exit_command: the entity of the command that will be terminated when entered
|
||||
:param system_router_title: system router title
|
||||
:param ignore_command_register: whether to ignore the case of the entered commands
|
||||
:param dividing_line: the entity of the dividing line
|
||||
:param repeat_command_groups: whether to repeat the available commands and their description
|
||||
:param override_system_messages: whether to redefine the default formatting of system messages
|
||||
:param autocompleter: the entity of the autocompleter
|
||||
:param print_func: system messages text output function
|
||||
:return: None
|
||||
"""
|
||||
super().__init__(
|
||||
prompt=prompt,
|
||||
initial_message=initial_message,
|
||||
farewell_message=farewell_message,
|
||||
exit_command=exit_command,
|
||||
system_router_title=system_router_title,
|
||||
ignore_command_register=ignore_command_register,
|
||||
dividing_line=dividing_line,
|
||||
repeat_command_groups=repeat_command_groups,
|
||||
override_system_messages=override_system_messages,
|
||||
autocompleter=autocompleter,
|
||||
print_func=print_func,
|
||||
)
|
||||
|
||||
def run_polling(self) -> None:
|
||||
"""
|
||||
Private. Starts the user input processing cycle
|
||||
:return: None
|
||||
"""
|
||||
self._pre_cycle_setup()
|
||||
while True:
|
||||
if self._repeat_command_groups_description:
|
||||
self._print_command_group_description()
|
||||
|
||||
raw_command: str = Console().input(self._prompt)
|
||||
|
||||
try:
|
||||
input_command: InputCommand = InputCommand.parse(raw_command=raw_command)
|
||||
except InputCommandException as error:
|
||||
with redirect_stdout(io.StringIO()) as stderr:
|
||||
self._error_handler(error, raw_command)
|
||||
stderr_result: str = stderr.getvalue()
|
||||
self._print_framed_text(stderr_result)
|
||||
continue
|
||||
|
||||
if self._is_exit_command(input_command):
|
||||
system_router.finds_appropriate_handler(input_command)
|
||||
self._autocompleter.exit_setup(list(self._current_matching_triggers_with_routers.keys()))
|
||||
return
|
||||
|
||||
if self._is_unknown_command(input_command):
|
||||
with redirect_stdout(io.StringIO()) as stdout:
|
||||
self._unknown_command_handler(input_command)
|
||||
stdout_res: str = stdout.getvalue()
|
||||
self._print_framed_text(stdout_res)
|
||||
continue
|
||||
|
||||
processing_router = self._current_matching_triggers_with_routers[input_command.trigger.lower()]
|
||||
|
||||
if processing_router.disable_redirect_stdout:
|
||||
if isinstance(self._dividing_line, StaticDividingLine):
|
||||
self._print_func(self._dividing_line.get_full_static_line(is_override=self._override_system_messages))
|
||||
processing_router.finds_appropriate_handler(input_command)
|
||||
self._print_func(self._dividing_line.get_full_static_line(is_override=self._override_system_messages))
|
||||
else:
|
||||
dividing_line_unit_part: str = self._dividing_line.get_unit_part()
|
||||
self._print_func(StaticDividingLine(dividing_line_unit_part).get_full_static_line(is_override=self._override_system_messages))
|
||||
processing_router.finds_appropriate_handler(input_command)
|
||||
self._print_func(StaticDividingLine(dividing_line_unit_part).get_full_static_line(is_override=self._override_system_messages))
|
||||
else:
|
||||
with redirect_stdout(io.StringIO()) as stdout:
|
||||
processing_router.finds_appropriate_handler(input_command)
|
||||
stdout_result: str = stdout.getvalue()
|
||||
if stdout_result:
|
||||
self._print_framed_text(stdout_result)
|
||||
|
||||
def include_router(self, router: Router) -> None:
|
||||
"""
|
||||
Public. Registers the router in the application
|
||||
:param router: registered router
|
||||
:return: None
|
||||
"""
|
||||
router.command_register_ignore = self._ignore_command_register
|
||||
self._registered_routers.add_registered_router(router)
|
||||
|
||||
def include_routers(self, *routers: Router) -> None:
|
||||
"""
|
||||
Public. Registers the routers in the application
|
||||
:param routers: registered routers
|
||||
:return: None
|
||||
"""
|
||||
for router in routers:
|
||||
self.include_router(router)
|
||||
|
||||
def add_message_on_startup(self, message: str) -> None:
|
||||
"""
|
||||
Public. Adds a message that will be displayed when the application is launched
|
||||
:param message: the message being added
|
||||
:return: None
|
||||
"""
|
||||
self._messages_on_startup.append(message)
|
||||
@@ -0,0 +1,22 @@
|
||||
from typing import Protocol, TypeVar
|
||||
|
||||
T = TypeVar('T', contravariant=True) # noqa: WPS111
|
||||
|
||||
|
||||
class NonStandardBehaviorHandler(Protocol[T]):
|
||||
def __call__(self, __param: T) -> None:
|
||||
raise NotImplementedError
|
||||
|
||||
class EmptyCommandHandler(Protocol):
|
||||
def __call__(self) -> None:
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
class Printer(Protocol):
|
||||
def __call__(self, __text: str) -> None:
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
class DescriptionMessageGenerator(Protocol):
|
||||
def __call__(self, __first_param: str, __second_param: str) -> str:
|
||||
raise NotImplementedError
|
||||
@@ -0,0 +1,27 @@
|
||||
from typing import Iterator, Optional
|
||||
|
||||
from argenta.router import Router
|
||||
|
||||
|
||||
class RegisteredRouters:
|
||||
def __init__(self, registered_routers: Optional[list[Router]] = None) -> None:
|
||||
"""
|
||||
Private. Combines registered routers
|
||||
:param registered_routers: list of the registered routers
|
||||
:return: None
|
||||
"""
|
||||
self.registered_routers: list[Router] = registered_routers if registered_routers else []
|
||||
|
||||
def add_registered_router(self, router: Router, /) -> None:
|
||||
"""
|
||||
Private. Adds a new registered router
|
||||
:param router: registered router
|
||||
:return: None
|
||||
"""
|
||||
self.registered_routers.append(router)
|
||||
|
||||
def __iter__(self) -> Iterator[Router]:
|
||||
return iter(self.registered_routers)
|
||||
|
||||
def __next__(self) -> Router:
|
||||
return next(iter(self.registered_routers))
|
||||
@@ -0,0 +1,12 @@
|
||||
__all__ = [
|
||||
"Command",
|
||||
"PossibleValues",
|
||||
"PredefinedFlags",
|
||||
"InputCommand",
|
||||
"Flags",
|
||||
"Flag"
|
||||
]
|
||||
|
||||
from argenta.command.models import Command, InputCommand
|
||||
from argenta.command.flag import defaults as PredefinedFlags
|
||||
from argenta.command.flag import (Flag, Flags, PossibleValues)
|
||||
@@ -0,0 +1,49 @@
|
||||
from argenta.command.flag.models import Flag, InputFlag
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import override
|
||||
|
||||
|
||||
class InputCommandException(ABC, Exception):
|
||||
"""
|
||||
Private. Base exception class for all exceptions raised when parse input command
|
||||
"""
|
||||
@override
|
||||
@abstractmethod
|
||||
def __str__(self) -> str:
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
class UnprocessedInputFlagException(InputCommandException):
|
||||
"""
|
||||
Private. Raised when an unprocessed input flag is detected
|
||||
"""
|
||||
@override
|
||||
def __str__(self) -> str:
|
||||
return "Unprocessed Input Flags"
|
||||
|
||||
|
||||
class RepeatedInputFlagsException(InputCommandException):
|
||||
"""
|
||||
Private. Raised when repeated input flags are detected
|
||||
"""
|
||||
|
||||
def __init__(self, flag: Flag | InputFlag):
|
||||
self.flag: Flag | InputFlag = flag
|
||||
super().__init__()
|
||||
|
||||
@override
|
||||
def __str__(self) -> str:
|
||||
string_entity: str = self.flag.string_entity
|
||||
return (
|
||||
"Repeated Input Flags\n"
|
||||
f"Duplicate flag was detected in the input: '{string_entity}'"
|
||||
)
|
||||
|
||||
|
||||
class EmptyInputCommandException(InputCommandException):
|
||||
"""
|
||||
Private. Raised when an empty input command is detected
|
||||
"""
|
||||
@override
|
||||
def __str__(self) -> str:
|
||||
return "Input Command is empty"
|
||||
@@ -0,0 +1,11 @@
|
||||
__all__ = [
|
||||
"Flag",
|
||||
"InputFlag",
|
||||
"Flags",
|
||||
"PossibleValues",
|
||||
"ValidationStatus"
|
||||
]
|
||||
|
||||
|
||||
from argenta.command.flag.models import Flag, InputFlag, PossibleValues, ValidationStatus
|
||||
from argenta.command.flag.flags.models import Flags
|
||||
@@ -0,0 +1,27 @@
|
||||
from typing import Literal
|
||||
from argenta.command.flag.models import Flag, PossibleValues
|
||||
import re
|
||||
|
||||
|
||||
DEFAULT_PREFIX: Literal["-", "--", "---"] = "-"
|
||||
|
||||
HELP = Flag(name="help", possible_values=PossibleValues.NEITHER)
|
||||
SHORT_HELP = Flag(name="H", prefix=DEFAULT_PREFIX, possible_values=PossibleValues.NEITHER)
|
||||
|
||||
INFO = Flag(name="info", possible_values=PossibleValues.NEITHER) # noqa: WPS110
|
||||
SHORT_INFO = Flag(name="I", prefix=DEFAULT_PREFIX, possible_values=PossibleValues.NEITHER)
|
||||
|
||||
ALL = Flag(name="all", possible_values=PossibleValues.NEITHER)
|
||||
SHORT_ALL = Flag(name="A", prefix=DEFAULT_PREFIX, possible_values=PossibleValues.NEITHER)
|
||||
|
||||
HOST = Flag(
|
||||
name="host", possible_values=re.compile(r"^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$")
|
||||
)
|
||||
SHORT_HOST = Flag(
|
||||
name="H",
|
||||
prefix=DEFAULT_PREFIX,
|
||||
possible_values=re.compile(r"^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$"),
|
||||
)
|
||||
|
||||
PORT = Flag(name="port", possible_values=re.compile(r"^\d{1,5}$"))
|
||||
SHORT_PORT = Flag(name="P", prefix=DEFAULT_PREFIX, possible_values=re.compile(r"^\d{1,5}$"))
|
||||
@@ -0,0 +1,10 @@
|
||||
__all__ = [
|
||||
"Flags",
|
||||
"InputFlags"
|
||||
]
|
||||
|
||||
|
||||
from argenta.command.flag.flags.models import (
|
||||
Flags,
|
||||
InputFlags
|
||||
)
|
||||
@@ -0,0 +1,106 @@
|
||||
from argenta.command.flag.models import InputFlag, Flag
|
||||
from typing import Generic, TypeVar, override
|
||||
from collections.abc import Iterator
|
||||
|
||||
|
||||
FlagType = TypeVar("FlagType")
|
||||
|
||||
|
||||
class BaseFlags(Generic[FlagType]):
|
||||
def __init__(self, flags: list[FlagType] | None = None) -> None:
|
||||
"""
|
||||
Public. A model that combines the registered flags
|
||||
:param flags: the flags that will be registered
|
||||
:return: None
|
||||
"""
|
||||
self.flags: list[FlagType] = flags if flags else []
|
||||
|
||||
def add_flag(self, flag: FlagType) -> None:
|
||||
"""
|
||||
Public. Adds a flag to the list of flags
|
||||
:param flag: flag to add
|
||||
:return: None
|
||||
"""
|
||||
self.flags.append(flag)
|
||||
|
||||
def add_flags(self, flags: list[FlagType]) -> None:
|
||||
"""
|
||||
Public. Adds a list of flags to the list of flags
|
||||
:param flags: list of flags to add
|
||||
:return: None
|
||||
"""
|
||||
self.flags.extend(flags)
|
||||
|
||||
def __iter__(self) -> Iterator[FlagType]:
|
||||
return iter(self.flags)
|
||||
|
||||
def __next__(self) -> FlagType:
|
||||
return next(iter(self))
|
||||
|
||||
def __getitem__(self, flag_index: int) -> FlagType:
|
||||
return self.flags[flag_index]
|
||||
|
||||
def __bool__(self) -> bool:
|
||||
return bool(self.flags)
|
||||
|
||||
|
||||
class Flags(BaseFlags[Flag]):
|
||||
def get_flag_by_name(self, name: str) -> Flag | None:
|
||||
"""
|
||||
Public. Returns the flag entity by its name or None if not found
|
||||
:param name: the name of the flag to get
|
||||
:return: entity of the flag or None
|
||||
"""
|
||||
return next((flag for flag in self.flags if flag.name == name), None)
|
||||
|
||||
@override
|
||||
def __eq__(self, other: object) -> bool:
|
||||
if not isinstance(other, Flags):
|
||||
return NotImplemented
|
||||
|
||||
if len(self.flags) != len(other.flags):
|
||||
return False
|
||||
|
||||
flag_pairs: zip[tuple[Flag, Flag]] = zip(self.flags, other.flags)
|
||||
return all(s_flag == o_flag for s_flag, o_flag in flag_pairs)
|
||||
|
||||
def __contains__(self, flag_to_check: object) -> bool:
|
||||
if isinstance(flag_to_check, Flag):
|
||||
for flag in self.flags:
|
||||
if flag == flag_to_check:
|
||||
return True
|
||||
return False
|
||||
else:
|
||||
raise TypeError
|
||||
|
||||
|
||||
class InputFlags(BaseFlags[InputFlag]):
|
||||
def get_flag_by_name(self, name: str) -> InputFlag | None:
|
||||
"""
|
||||
Public. Returns the flag entity by its name or None if not found
|
||||
:param name: the name of the flag to get
|
||||
:return: entity of the flag or None
|
||||
"""
|
||||
return next((flag for flag in self.flags if flag.name == name), None)
|
||||
|
||||
@override
|
||||
def __eq__(self, other: object) -> bool:
|
||||
if not isinstance(other, InputFlags):
|
||||
raise NotImplementedError
|
||||
|
||||
if len(self.flags) != len(other.flags):
|
||||
return False
|
||||
|
||||
paired_flags: zip[tuple[InputFlag, InputFlag]] = zip(self.flags, other.flags)
|
||||
|
||||
return all(my_flag == other_flag for my_flag, other_flag in paired_flags)
|
||||
|
||||
def __contains__(self, ingressable_item: object) -> bool:
|
||||
if isinstance(ingressable_item, InputFlag):
|
||||
for flag in self.flags:
|
||||
if flag == ingressable_item:
|
||||
return True
|
||||
return False
|
||||
else:
|
||||
raise TypeError
|
||||
|
||||
@@ -0,0 +1,119 @@
|
||||
from enum import Enum
|
||||
from re import Pattern
|
||||
from typing import Literal, override
|
||||
|
||||
|
||||
class PossibleValues(Enum):
|
||||
NEITHER = 'NEITHER'
|
||||
ALL = 'ALL'
|
||||
|
||||
|
||||
class ValidationStatus(Enum):
|
||||
VALID = 'VALID'
|
||||
INVALID = 'INVALID'
|
||||
UNDEFINED = 'UNDEFINED'
|
||||
|
||||
|
||||
class Flag:
|
||||
def __init__(
|
||||
self, name: str, *,
|
||||
prefix: Literal["-", "--", "---"] = "--",
|
||||
possible_values: list[str] | Pattern[str] | PossibleValues = PossibleValues.ALL,
|
||||
) -> None:
|
||||
"""
|
||||
Public. The entity of the flag being registered for subsequent processing
|
||||
:param name: The name of the flag
|
||||
:param prefix: The prefix of the flag
|
||||
:param possible_values: The possible values of the flag, if False then the flag cannot have a value
|
||||
:return: None
|
||||
"""
|
||||
self.name: str = name
|
||||
self.prefix: Literal["-", "--", "---"] = prefix
|
||||
self.possible_values: list[str] | Pattern[str] | PossibleValues = possible_values
|
||||
|
||||
def validate_input_flag_value(self, input_flag_value: str | None) -> bool:
|
||||
"""
|
||||
Private. Validates the input flag value
|
||||
:param input_flag_value: The input flag value to validate
|
||||
:return: whether the entered flag is valid as bool
|
||||
"""
|
||||
if self.possible_values == PossibleValues.NEITHER:
|
||||
return input_flag_value is None
|
||||
|
||||
if isinstance(self.possible_values, Pattern):
|
||||
return isinstance(input_flag_value, str) and bool(self.possible_values.match(input_flag_value))
|
||||
|
||||
if isinstance(self.possible_values, list):
|
||||
return input_flag_value in self.possible_values
|
||||
|
||||
return True
|
||||
|
||||
@property
|
||||
def string_entity(self) -> str:
|
||||
"""
|
||||
Public. Returns a string representation of the flag
|
||||
:return: string representation of the flag as str
|
||||
"""
|
||||
string_entity: str = self.prefix + self.name
|
||||
return string_entity
|
||||
|
||||
@override
|
||||
def __str__(self) -> str:
|
||||
return self.string_entity
|
||||
|
||||
@override
|
||||
def __repr__(self) -> str:
|
||||
return f'Flag<name={self.name}, prefix={self.prefix}>'
|
||||
|
||||
@override
|
||||
def __eq__(self, other: object) -> bool:
|
||||
if isinstance(other, Flag):
|
||||
return self.string_entity == other.string_entity
|
||||
else:
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
class InputFlag:
|
||||
def __init__(
|
||||
self, name: str, *,
|
||||
prefix: Literal['-', '--', '---'] = '--',
|
||||
input_value: str | None,
|
||||
status: ValidationStatus | None
|
||||
):
|
||||
"""
|
||||
Public. The entity of the flag of the entered command
|
||||
:param name: the name of the input flag
|
||||
:param prefix: the prefix of the input flag
|
||||
:param value: the value of the input flag
|
||||
:return: None
|
||||
"""
|
||||
self.name: str = name
|
||||
self.prefix: Literal['-', '--', '---'] = prefix
|
||||
self.input_value: str | None = input_value
|
||||
self.status: ValidationStatus | None = status
|
||||
|
||||
@property
|
||||
def string_entity(self) -> str:
|
||||
"""
|
||||
Public. Returns a string representation of the flag
|
||||
:return: string representation of the flag as str
|
||||
"""
|
||||
string_entity: str = self.prefix + self.name
|
||||
return string_entity
|
||||
|
||||
@override
|
||||
def __str__(self) -> str:
|
||||
return f'{self.string_entity} {self.input_value}'
|
||||
|
||||
@override
|
||||
def __repr__(self) -> str:
|
||||
return f'InputFlag<name={self.name}, prefix={self.prefix}, value={self.input_value}, status={self.status}>'
|
||||
|
||||
@override
|
||||
def __eq__(self, other: object) -> bool:
|
||||
if isinstance(other, InputFlag):
|
||||
return (
|
||||
self.name == other.name
|
||||
)
|
||||
else:
|
||||
raise NotImplementedError
|
||||
@@ -0,0 +1,151 @@
|
||||
from argenta.command.flag.models import Flag, InputFlag, ValidationStatus
|
||||
from argenta.command.flag.flags.models import InputFlags, Flags
|
||||
from argenta.command.exceptions import (
|
||||
UnprocessedInputFlagException,
|
||||
RepeatedInputFlagsException,
|
||||
EmptyInputCommandException,
|
||||
)
|
||||
from typing import Never, Self, cast, Literal
|
||||
|
||||
|
||||
ParseFlagsResult = tuple[InputFlags, str | None, str | None]
|
||||
ParseResult = tuple[str, InputFlags]
|
||||
|
||||
MIN_FLAG_PREFIX: str = "-"
|
||||
DEFAULT_WITHOUT_FLAGS: Flags = Flags()
|
||||
|
||||
DEFAULT_WITHOUT_INPUT_FLAGS: InputFlags = InputFlags()
|
||||
|
||||
|
||||
class Command:
|
||||
def __init__(
|
||||
self,
|
||||
trigger: str, *,
|
||||
description: str | None = None,
|
||||
flags: Flag | Flags = DEFAULT_WITHOUT_FLAGS,
|
||||
aliases: list[str] | None = None,
|
||||
):
|
||||
"""
|
||||
Public. The command that can and should be registered in the Router
|
||||
:param trigger: A string trigger, which, when entered by the user, indicates that the input corresponds to the command
|
||||
:param description: the description of the command
|
||||
:param flags: processed commands
|
||||
:param aliases: string synonyms for the main trigger
|
||||
"""
|
||||
self.registered_flags: Flags = flags if isinstance(flags, Flags) else Flags([flags])
|
||||
self.trigger: str = trigger
|
||||
self.description: str = description if description else "Command without description"
|
||||
self.aliases: list[str] = aliases if aliases else []
|
||||
|
||||
def validate_input_flag(
|
||||
self, flag: InputFlag
|
||||
) -> ValidationStatus:
|
||||
"""
|
||||
Private. Validates the input flag
|
||||
:param flag: input flag for validation
|
||||
:return: is input flag valid as bool
|
||||
"""
|
||||
registered_flags: Flags = self.registered_flags
|
||||
for registered_flag in registered_flags:
|
||||
if registered_flag.string_entity == flag.string_entity:
|
||||
is_valid = registered_flag.validate_input_flag_value(flag.input_value)
|
||||
if is_valid:
|
||||
return ValidationStatus.VALID
|
||||
else:
|
||||
return ValidationStatus.INVALID
|
||||
return ValidationStatus.UNDEFINED
|
||||
|
||||
|
||||
class InputCommand:
|
||||
def __init__(self, trigger: str, *,
|
||||
input_flags: InputFlag | InputFlags = DEFAULT_WITHOUT_INPUT_FLAGS):
|
||||
"""
|
||||
Private. The model of the input command, after parsing
|
||||
:param trigger:the trigger of the command
|
||||
:param input_flags: the input flags
|
||||
:return: None
|
||||
"""
|
||||
self.trigger: str = trigger
|
||||
self.input_flags: InputFlags = input_flags if isinstance(input_flags, InputFlags) else InputFlags([input_flags])
|
||||
|
||||
@classmethod
|
||||
def parse(cls, raw_command: str) -> Self:
|
||||
"""
|
||||
Private. Parse the raw input command
|
||||
:param raw_command: raw input command
|
||||
:return: model of the input command, after parsing as InputCommand
|
||||
"""
|
||||
trigger, input_flags = CommandParser(raw_command).parse_raw_command()
|
||||
|
||||
return cls(trigger=trigger, input_flags=input_flags)
|
||||
|
||||
|
||||
class CommandParser:
|
||||
def __init__(self, raw_command: str) -> None:
|
||||
self.raw_command: str = raw_command
|
||||
self._parsed_input_flags: InputFlags = InputFlags()
|
||||
|
||||
def parse_raw_command(self) -> ParseResult:
|
||||
if not self.raw_command:
|
||||
raise EmptyInputCommandException()
|
||||
|
||||
input_flags, crnt_flag_name, crnt_flag_val = self._parse_flags(self.raw_command.split()[1:])
|
||||
|
||||
if any([crnt_flag_name, crnt_flag_val]):
|
||||
raise UnprocessedInputFlagException()
|
||||
else:
|
||||
return (self.raw_command.split()[0], input_flags)
|
||||
|
||||
def _parse_flags(self, _tokens: list[str] | list[Never]) -> ParseFlagsResult:
|
||||
crnt_flg_name, crnt_flg_val = None, None
|
||||
for index, token in enumerate(_tokens):
|
||||
crnt_flg_name, crnt_flg_val = _parse_single_token(token, crnt_flg_name, crnt_flg_val)
|
||||
|
||||
if not crnt_flg_name or self._is_next_token_value(index, _tokens):
|
||||
continue
|
||||
|
||||
input_flag = InputFlag(
|
||||
name=crnt_flg_name[crnt_flg_name.rfind(MIN_FLAG_PREFIX) + 1:],
|
||||
prefix=cast(
|
||||
Literal["-", "--", "---"],
|
||||
crnt_flg_name[:crnt_flg_name.rfind(MIN_FLAG_PREFIX) + 1],
|
||||
),
|
||||
input_value=crnt_flg_val,
|
||||
status=None
|
||||
)
|
||||
|
||||
if input_flag in self._parsed_input_flags:
|
||||
raise RepeatedInputFlagsException(input_flag)
|
||||
|
||||
self._parsed_input_flags.add_flag(input_flag)
|
||||
crnt_flg_name, crnt_flg_val = None, None
|
||||
|
||||
return (self._parsed_input_flags, crnt_flg_name, crnt_flg_val)
|
||||
|
||||
def _is_next_token_value(self, current_index: int,
|
||||
_tokens: list[str] | list[Never]) -> bool:
|
||||
next_index = current_index + 1
|
||||
if next_index >= len(_tokens):
|
||||
return False
|
||||
|
||||
next_token = _tokens[next_index]
|
||||
return not next_token.startswith(MIN_FLAG_PREFIX)
|
||||
|
||||
def _parse_single_token(
|
||||
token: str,
|
||||
crnt_flag_name: str | None,
|
||||
crnt_flag_val: str | None
|
||||
) -> tuple[str | None, str | None]:
|
||||
if not token.startswith(MIN_FLAG_PREFIX):
|
||||
if not crnt_flag_name or crnt_flag_val:
|
||||
raise UnprocessedInputFlagException
|
||||
return crnt_flag_name, token
|
||||
|
||||
prefix = token[:token.rfind(MIN_FLAG_PREFIX)]
|
||||
if len(token) < 2 or len(prefix) > 2:
|
||||
raise UnprocessedInputFlagException
|
||||
|
||||
new_flag_name = token
|
||||
new_flag_value = None
|
||||
|
||||
return new_flag_name, new_flag_value
|
||||
@@ -0,0 +1,4 @@
|
||||
__all__ = ["get_time_of_pre_cycle_setup"]
|
||||
|
||||
|
||||
from argenta.metrics.main import get_time_of_pre_cycle_setup
|
||||
@@ -0,0 +1,18 @@
|
||||
import io
|
||||
from contextlib import redirect_stdout
|
||||
from time import time
|
||||
|
||||
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()
|
||||
with redirect_stdout(io.StringIO()):
|
||||
app._pre_cycle_setup() # pyright: ignore[reportPrivateUsage]
|
||||
end = time()
|
||||
return end - start
|
||||
@@ -0,0 +1,8 @@
|
||||
__all__ = [
|
||||
"Orchestrator",
|
||||
"ArgParser"
|
||||
]
|
||||
|
||||
|
||||
from argenta.orchestrator.entity import Orchestrator
|
||||
from argenta.orchestrator.argparser.entity import ArgParser
|
||||
@@ -0,0 +1,12 @@
|
||||
__all__ = [
|
||||
"ArgParser",
|
||||
"PositionalArgument",
|
||||
"OptionalArgument",
|
||||
"BooleanArgument"
|
||||
]
|
||||
|
||||
|
||||
from argenta.orchestrator.argparser.entity import ArgParser
|
||||
from argenta.orchestrator.argparser.arguments import (BooleanArgument,
|
||||
PositionalArgument,
|
||||
OptionalArgument)
|
||||
@@ -0,0 +1,8 @@
|
||||
__all__ = ["BooleanArgument", "PositionalArgument", "OptionalArgument"]
|
||||
|
||||
|
||||
from argenta.orchestrator.argparser.arguments.models import (
|
||||
BooleanArgument,
|
||||
PositionalArgument,
|
||||
OptionalArgument,
|
||||
)
|
||||
@@ -0,0 +1,62 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import Literal, override
|
||||
|
||||
|
||||
class BaseArgument(ABC):
|
||||
"""
|
||||
Private. Base class for all arguments
|
||||
"""
|
||||
@property
|
||||
@abstractmethod
|
||||
def string_entity(self) -> str:
|
||||
"""
|
||||
Public. Returns the string representation of the argument
|
||||
:return: the string representation as a str
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
class PositionalArgument(BaseArgument):
|
||||
def __init__(self, name: str):
|
||||
"""
|
||||
Public. Required argument at startup
|
||||
:param name: name of the argument, must not start with minus (-)
|
||||
"""
|
||||
self.name: str = name
|
||||
|
||||
@property
|
||||
@override
|
||||
def string_entity(self) -> str:
|
||||
return self.name
|
||||
|
||||
|
||||
class OptionalArgument(BaseArgument):
|
||||
def __init__(self, name: str, prefix: Literal["-", "--", "---"] = "--"):
|
||||
"""
|
||||
Public. Optional argument, must have the value
|
||||
:param name: name of the argument
|
||||
:param prefix: prefix of the argument
|
||||
"""
|
||||
self.name: str = name
|
||||
self.prefix: Literal["-", "--", "---"] = prefix
|
||||
|
||||
@property
|
||||
@override
|
||||
def string_entity(self) -> str:
|
||||
return self.prefix + self.name
|
||||
|
||||
|
||||
class BooleanArgument(BaseArgument):
|
||||
def __init__(self, name: str, prefix: Literal["-", "--", "---"] = "--"):
|
||||
"""
|
||||
Public. Boolean argument, does not require a value
|
||||
:param name: name of the argument
|
||||
:param prefix: prefix of the argument
|
||||
"""
|
||||
self.name: str = name
|
||||
self.prefix: Literal["-", "--", "---"] = prefix
|
||||
|
||||
@property
|
||||
@override
|
||||
def string_entity(self) -> str:
|
||||
return self.prefix + self.name
|
||||
@@ -0,0 +1,39 @@
|
||||
from argparse import ArgumentParser, Namespace
|
||||
|
||||
from argenta.orchestrator.argparser.arguments.models import (
|
||||
BooleanArgument,
|
||||
OptionalArgument,
|
||||
PositionalArgument,
|
||||
)
|
||||
|
||||
|
||||
class ArgParser:
|
||||
def __init__(
|
||||
self,
|
||||
processed_args: list[PositionalArgument | OptionalArgument | BooleanArgument], *,
|
||||
name: str = "Argenta",
|
||||
description: str = "Argenta available arguments",
|
||||
epilog: str = "github.com/koloideal/Argenta | made by kolo",
|
||||
) -> None:
|
||||
"""
|
||||
Public. Cmd argument parser and configurator at startup
|
||||
:param name: the name of the ArgParse instance
|
||||
:param description: the description of the ArgParse instance
|
||||
:param epilog: the epilog of the ArgParse instance
|
||||
:param processed_args: registered and processed arguments
|
||||
"""
|
||||
self._name: str = name
|
||||
self._description: str = description
|
||||
self._epilog: str = epilog
|
||||
|
||||
self._entity: ArgumentParser = ArgumentParser(prog=name, description=description, epilog=epilog)
|
||||
self._processed_args: list[PositionalArgument | OptionalArgument | BooleanArgument] = processed_args
|
||||
|
||||
for arg in processed_args:
|
||||
if isinstance(arg, PositionalArgument) or isinstance(arg, OptionalArgument):
|
||||
_ = self._entity.add_argument(arg.string_entity)
|
||||
else:
|
||||
_ = self._entity.add_argument(arg.string_entity, action="store_true")
|
||||
|
||||
def parse_args(self) -> Namespace:
|
||||
return self._entity.parse_args()
|
||||
@@ -0,0 +1,32 @@
|
||||
from argparse import Namespace
|
||||
|
||||
from argenta.app import App
|
||||
from argenta.orchestrator.argparser import ArgParser
|
||||
|
||||
|
||||
class Orchestrator:
|
||||
def __init__(self, arg_parser: ArgParser | None = None):
|
||||
"""
|
||||
Public. An orchestrator and configurator that defines the behavior of an integrated system, one level higher than the App
|
||||
:param arg_parser: Cmd argument parser and configurator at startup
|
||||
:return: None
|
||||
"""
|
||||
self._arg_parser: ArgParser | None = arg_parser
|
||||
|
||||
def start_polling(self, app: App) -> None:
|
||||
"""
|
||||
Public. Starting the user input processing cycle
|
||||
:param app: a running application
|
||||
:return: None
|
||||
"""
|
||||
app.run_polling()
|
||||
|
||||
def get_input_args(self) -> Namespace | None:
|
||||
"""
|
||||
Public. Returns the arguments parsed
|
||||
:return: None
|
||||
"""
|
||||
if self._arg_parser:
|
||||
return self._arg_parser.parse_args()
|
||||
else:
|
||||
return None
|
||||
@@ -0,0 +1,5 @@
|
||||
__all__ = ["Response", "ResponseStatus"]
|
||||
|
||||
|
||||
from argenta.response.entity import Response
|
||||
from argenta.response.status import ResponseStatus
|
||||
@@ -0,0 +1,23 @@
|
||||
from typing import Literal
|
||||
from argenta.command.flag.flags.models import InputFlags
|
||||
from argenta.response.status import ResponseStatus
|
||||
|
||||
|
||||
EMPTY_INPUT_FLAGS: InputFlags = InputFlags()
|
||||
|
||||
|
||||
class Response:
|
||||
__slots__: tuple[Literal['status', 'input_flags'], ...] = ("status", "input_flags")
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
status: ResponseStatus,
|
||||
input_flags: InputFlags = EMPTY_INPUT_FLAGS,
|
||||
):
|
||||
"""
|
||||
Public. The entity of the user input sent to the handler
|
||||
:param status: the status of the response
|
||||
:param input_flags: all input flags
|
||||
"""
|
||||
self.status: ResponseStatus = status
|
||||
self.input_flags: InputFlags = input_flags
|
||||
@@ -0,0 +1,19 @@
|
||||
from enum import Enum
|
||||
|
||||
|
||||
class ResponseStatus(Enum):
|
||||
ALL_FLAGS_VALID = "ALL_FLAGS_VALID"
|
||||
UNDEFINED_FLAGS = "UNDEFINED_FLAGS"
|
||||
INVALID_VALUE_FLAGS = "INVALID_VALUE_FLAGS"
|
||||
UNDEFINED_AND_INVALID_FLAGS = "UNDEFINED_AND_INVALID_FLAGS"
|
||||
|
||||
@classmethod
|
||||
def from_flags(cls, *, has_invalid_value_flags: bool, has_undefined_flags: bool) -> 'ResponseStatus':
|
||||
key = (has_invalid_value_flags, has_undefined_flags)
|
||||
status_map: dict[tuple[bool, bool], ResponseStatus] = {
|
||||
(True, True): cls.UNDEFINED_AND_INVALID_FLAGS,
|
||||
(True, False): cls.INVALID_VALUE_FLAGS,
|
||||
(False, True): cls.UNDEFINED_FLAGS,
|
||||
(False, False): cls.ALL_FLAGS_VALID,
|
||||
}
|
||||
return status_map[key]
|
||||
@@ -0,0 +1,4 @@
|
||||
from argenta.router.entity import Router
|
||||
|
||||
|
||||
__all__ = ["Router"]
|
||||
@@ -0,0 +1,47 @@
|
||||
from collections.abc import Iterator
|
||||
from typing import Callable
|
||||
|
||||
from argenta.command import Command
|
||||
from argenta.response import Response
|
||||
|
||||
|
||||
class CommandHandler:
|
||||
def __init__(self, handler_as_func: Callable[[Response], None], handled_command: Command):
|
||||
"""
|
||||
Private. Entity of the model linking the handler and the command being processed
|
||||
:param handler: the handler being called
|
||||
:param handled_command: the command being processed
|
||||
"""
|
||||
self.handler_as_func: Callable[[Response], None] = handler_as_func
|
||||
self.handled_command: Command = handled_command
|
||||
|
||||
def handling(self, response: Response) -> None:
|
||||
"""
|
||||
Private. Direct processing of an input command
|
||||
:param response: the entity of response: various groups of flags and status of response
|
||||
:return: None
|
||||
"""
|
||||
self.handler_as_func(response)
|
||||
|
||||
|
||||
class CommandHandlers:
|
||||
def __init__(self, command_handlers: list[CommandHandler] | None = None):
|
||||
"""
|
||||
Private. The model that unites all CommandHandler of the routers
|
||||
:param command_handlers: list of CommandHandlers for register
|
||||
"""
|
||||
self.command_handlers: list[CommandHandler] = command_handlers if command_handlers else []
|
||||
|
||||
def add_handler(self, command_handler: CommandHandler) -> None:
|
||||
"""
|
||||
Private. Adds a CommandHandler to the list of CommandHandlers
|
||||
:param command_handler: CommandHandler to be added
|
||||
:return: None
|
||||
"""
|
||||
self.command_handlers.append(command_handler)
|
||||
|
||||
def __iter__(self) -> Iterator[CommandHandler]:
|
||||
return iter(self.command_handlers)
|
||||
|
||||
def __next__(self) -> CommandHandler:
|
||||
return next(iter(self.command_handlers))
|
||||
@@ -0,0 +1,4 @@
|
||||
from argenta.router import Router
|
||||
|
||||
|
||||
system_router = Router(title="System points:")
|
||||
@@ -0,0 +1,212 @@
|
||||
from typing import Callable, TypeAlias
|
||||
from inspect import getfullargspec, get_annotations, getsourcefile, getsourcelines
|
||||
from rich.console import Console
|
||||
|
||||
from argenta.command import Command, InputCommand
|
||||
from argenta.command.flag import ValidationStatus
|
||||
from argenta.response import Response, ResponseStatus
|
||||
from argenta.router.command_handler.entity import CommandHandlers, CommandHandler
|
||||
from argenta.command.flag.flags import (
|
||||
Flags,
|
||||
InputFlags
|
||||
)
|
||||
from argenta.router.exceptions import (
|
||||
RepeatedFlagNameException,
|
||||
TooManyTransferredArgsException,
|
||||
RequiredArgumentNotPassedException,
|
||||
TriggerContainSpacesException,
|
||||
)
|
||||
|
||||
|
||||
HandlerFunc: TypeAlias = Callable[[Response], None]
|
||||
|
||||
|
||||
class Router:
|
||||
def __init__(
|
||||
self, *, title: str | None = "Default title",
|
||||
disable_redirect_stdout: bool = False
|
||||
):
|
||||
"""
|
||||
Public. Directly configures and manages handlers
|
||||
: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
|
||||
"""
|
||||
self.title: str | None = title
|
||||
self.disable_redirect_stdout: bool = disable_redirect_stdout
|
||||
|
||||
self.command_handlers: CommandHandlers = CommandHandlers()
|
||||
self.command_register_ignore: bool = False
|
||||
|
||||
def command(self, command: Command | str) -> Callable[[HandlerFunc], HandlerFunc]:
|
||||
"""
|
||||
Public. Registers handler
|
||||
:param command: Registered command
|
||||
:return: decorated handler as Callable
|
||||
"""
|
||||
if isinstance(command, str):
|
||||
redefined_command = Command(command)
|
||||
else:
|
||||
redefined_command = command
|
||||
|
||||
_validate_command(redefined_command)
|
||||
|
||||
def decorator(func: HandlerFunc) -> HandlerFunc:
|
||||
_validate_func_args(func)
|
||||
self.command_handlers.add_handler(CommandHandler(func, redefined_command))
|
||||
|
||||
return func
|
||||
|
||||
return decorator
|
||||
|
||||
def finds_appropriate_handler(self, input_command: InputCommand) -> None:
|
||||
"""
|
||||
Private. Finds the appropriate handler for given input command and passes control to it
|
||||
:param input_command: input command as InputCommand
|
||||
:return: None
|
||||
"""
|
||||
input_command_name: str = input_command.trigger
|
||||
input_command_flags: InputFlags = input_command.input_flags
|
||||
|
||||
for command_handler in self.command_handlers:
|
||||
handle_command = command_handler.handled_command
|
||||
if input_command_name.lower() == handle_command.trigger.lower():
|
||||
self.process_input_command(input_command_flags, command_handler)
|
||||
if input_command_name.lower() in handle_command.aliases:
|
||||
self.process_input_command(input_command_flags, command_handler)
|
||||
|
||||
def process_input_command(
|
||||
self, input_command_flags: InputFlags, command_handler: CommandHandler
|
||||
) -> None:
|
||||
"""
|
||||
Private. Processes input command with the appropriate handler
|
||||
:param input_command_flags: input command flags as InputFlags
|
||||
:param command_handler: command handler for input command as CommandHandler
|
||||
:return: None
|
||||
"""
|
||||
handle_command = command_handler.handled_command
|
||||
if handle_command.registered_flags.flags:
|
||||
if input_command_flags.flags:
|
||||
response: Response = _structuring_input_flags(handle_command, input_command_flags)
|
||||
command_handler.handling(response)
|
||||
else:
|
||||
response = Response(ResponseStatus.ALL_FLAGS_VALID)
|
||||
command_handler.handling(response)
|
||||
else:
|
||||
if input_command_flags.flags:
|
||||
undefined_flags = InputFlags()
|
||||
for input_flag in input_command_flags:
|
||||
input_flag.status = ValidationStatus.UNDEFINED
|
||||
undefined_flags.add_flag(input_flag)
|
||||
response = Response(ResponseStatus.UNDEFINED_FLAGS, input_flags=undefined_flags)
|
||||
command_handler.handling(response)
|
||||
else:
|
||||
response = Response(ResponseStatus.ALL_FLAGS_VALID)
|
||||
command_handler.handling(response)
|
||||
|
||||
@property
|
||||
def triggers(self) -> list[str]:
|
||||
"""
|
||||
Public. Gets registered triggers
|
||||
:return: registered in router triggers as list[str]
|
||||
"""
|
||||
all_triggers: list[str] = []
|
||||
for command_handler in self.command_handlers:
|
||||
all_triggers.append(command_handler.handled_command.trigger)
|
||||
return all_triggers
|
||||
|
||||
@property
|
||||
def aliases(self) -> list[str]:
|
||||
"""
|
||||
Public. Gets registered aliases
|
||||
:return: registered in router aliases as list[str]
|
||||
"""
|
||||
all_aliases: list[str] = []
|
||||
for command_handler in self.command_handlers:
|
||||
if command_handler.handled_command.aliases:
|
||||
all_aliases.extend(command_handler.handled_command.aliases)
|
||||
return all_aliases
|
||||
|
||||
|
||||
class CommandDecorator:
|
||||
def __init__(self, router_instance: Router, command: Command):
|
||||
self.router: Router = router_instance
|
||||
self.command: Command = command
|
||||
|
||||
def __call__(self, handler_func: Callable[[Response], None]) -> Callable[[Response], None]:
|
||||
_validate_func_args(handler_func)
|
||||
self.router.command_handlers.add_handler(CommandHandler(handler_func, self.command))
|
||||
return handler_func
|
||||
|
||||
|
||||
def _structuring_input_flags(handled_command: Command,
|
||||
input_flags: InputFlags) -> Response:
|
||||
"""
|
||||
Private. Validates flags of input command
|
||||
:param handled_command: entity of the handled command
|
||||
:param input_flags:
|
||||
:return: entity of response as Response
|
||||
"""
|
||||
invalid_value_flags, undefined_flags = False, False
|
||||
|
||||
for flag in input_flags:
|
||||
flag_status: ValidationStatus = (handled_command.validate_input_flag(flag))
|
||||
flag.status = flag_status
|
||||
if flag_status == ValidationStatus.INVALID:
|
||||
invalid_value_flags = True
|
||||
elif flag_status == ValidationStatus.UNDEFINED:
|
||||
undefined_flags = True
|
||||
|
||||
status = ResponseStatus.from_flags(has_invalid_value_flags=invalid_value_flags,
|
||||
has_undefined_flags=undefined_flags)
|
||||
|
||||
return Response(
|
||||
status=status,
|
||||
input_flags=input_flags
|
||||
)
|
||||
|
||||
def _validate_func_args(func: Callable[[Response], None]) -> None:
|
||||
"""
|
||||
Private. Validates the arguments of the handler
|
||||
:param func: entity of the handler func
|
||||
:return: None if func is valid else raise exception
|
||||
"""
|
||||
transferred_args = getfullargspec(func).args
|
||||
if len(transferred_args) > 1:
|
||||
raise TooManyTransferredArgsException()
|
||||
elif len(transferred_args) == 0:
|
||||
raise RequiredArgumentNotPassedException()
|
||||
|
||||
transferred_arg: str = transferred_args[0]
|
||||
func_annotations: dict[str, None] = get_annotations(func)
|
||||
|
||||
arg_annotation = func_annotations.get(transferred_arg)
|
||||
|
||||
if arg_annotation is not None:
|
||||
if arg_annotation is not Response:
|
||||
source_line: int = getsourcelines(func)[1]
|
||||
Console().print(
|
||||
f'\nFile "{getsourcefile(func)}", line {source_line}\n[b red]WARNING:[/b red] [i]The typehint ' +
|
||||
f"of argument([green]{transferred_arg}[/green]) passed to the handler must be [/i][bold blue]{Response}[/bold blue]," +
|
||||
f" [i]but[/i] [bold blue]{arg_annotation}[/bold blue] [i]is specified[/i]",
|
||||
highlight=False,
|
||||
)
|
||||
|
||||
|
||||
def _validate_command(command: Command) -> None:
|
||||
"""
|
||||
Private. Validates the command registered in handler
|
||||
:param command: validated command
|
||||
:return: None if command is valid else raise exception
|
||||
"""
|
||||
command_name: str = command.trigger
|
||||
if command_name.find(" ") != -1:
|
||||
raise TriggerContainSpacesException()
|
||||
flags: Flags = command.registered_flags
|
||||
flags_name: list[str] = [flag.string_entity.lower() for flag in flags]
|
||||
if len(set(flags_name)) < len(flags_name):
|
||||
raise RepeatedFlagNameException()
|
||||
@@ -0,0 +1,37 @@
|
||||
from typing import override
|
||||
|
||||
|
||||
class RepeatedFlagNameException(Exception):
|
||||
"""
|
||||
Private. Raised when a repeated flag name is registered
|
||||
"""
|
||||
@override
|
||||
def __str__(self) -> str:
|
||||
return "Repeated registered flag names in register command"
|
||||
|
||||
|
||||
class TooManyTransferredArgsException(Exception):
|
||||
"""
|
||||
Private. Raised when too many arguments are passed
|
||||
"""
|
||||
@override
|
||||
def __str__(self) -> str:
|
||||
return "Too many transferred arguments"
|
||||
|
||||
|
||||
class RequiredArgumentNotPassedException(Exception):
|
||||
"""
|
||||
Private. Raised when a required argument is not passed
|
||||
"""
|
||||
@override
|
||||
def __str__(self) -> str:
|
||||
return "Required argument not passed"
|
||||
|
||||
|
||||
class TriggerContainSpacesException(Exception):
|
||||
"""
|
||||
Private. Raised when there is a space in the trigger being registered
|
||||
"""
|
||||
@override
|
||||
def __str__(self) -> str:
|
||||
return "Command trigger cannot contain spaces"
|
||||
@@ -1,75 +0,0 @@
|
||||
import os
|
||||
import shutil
|
||||
import time
|
||||
from zipfile import ZipFile
|
||||
import requests
|
||||
from ..local_data_func.get_script_release_tag import get_script_tag
|
||||
from tqdm import tqdm
|
||||
|
||||
|
||||
class UpdateScript:
|
||||
|
||||
GITHUB_REPO = "https://api.github.com/repos/koloideal/WordMath"
|
||||
|
||||
@staticmethod
|
||||
def get_latest_release() -> dict:
|
||||
response = requests.get(f"{UpdateScript.GITHUB_REPO}/releases/latest")
|
||||
data = response.json()
|
||||
return {'tag': data['tag_name'],
|
||||
'url': data['zipball_url']}
|
||||
|
||||
|
||||
@staticmethod
|
||||
def download_new_release(zip_url):
|
||||
response = requests.get(zip_url, stream=True)
|
||||
response.raise_for_status()
|
||||
|
||||
total_size = int(response.headers.get("content-length", 0))
|
||||
block_size = 1024
|
||||
|
||||
with tqdm(total=total_size, unit="B", unit_scale=True) as progress_bar:
|
||||
with open('new_release.zip', "wb") as file:
|
||||
for data in response.iter_content(block_size):
|
||||
progress_bar.update(len(data))
|
||||
file.write(data)
|
||||
time.sleep(0.3)
|
||||
|
||||
with ZipFile('new_release.zip') as zip_file:
|
||||
zip_file.extractall("new_release")
|
||||
|
||||
|
||||
@staticmethod
|
||||
def upgrade_script():
|
||||
excluded_files = ['venv', '.venv', '.git', 'new_release']
|
||||
for obj in os.listdir():
|
||||
if obj not in excluded_files:
|
||||
if os.path.isfile(obj):
|
||||
os.remove(obj)
|
||||
elif os.path.isdir(obj):
|
||||
shutil.rmtree(obj)
|
||||
|
||||
new_release = os.listdir('new_release')
|
||||
new_release_name = new_release[0] if new_release[0].startswith('koloideal-WordMath') else None
|
||||
path = f'new_release/{new_release_name}'
|
||||
all_files = os.listdir(path)
|
||||
for file in all_files:
|
||||
shutil.move(path + '/' + file, './' + file)
|
||||
|
||||
shutil.rmtree('new_release')
|
||||
|
||||
|
||||
@staticmethod
|
||||
def start_update() -> bool:
|
||||
existing_release_tag: str = get_script_tag()
|
||||
latest_release: dict = UpdateScript.get_latest_release()
|
||||
latest_release_tag = latest_release['tag']
|
||||
latest_release_url = latest_release['url']
|
||||
|
||||
if latest_release_tag != existing_release_tag:
|
||||
#UpdateScript.download_new_release(latest_release_url)
|
||||
#UpdateScript.upgrade_script()
|
||||
return latest_release_tag
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
@@ -1,68 +0,0 @@
|
||||
from numpy import ndarray
|
||||
from word2number import w2n
|
||||
from ..local_data_func.get_operator_synonyms import get_operator_synonyms
|
||||
import numexpr
|
||||
|
||||
|
||||
def word2num_math(string: str) -> ndarray | ZeroDivisionError | OverflowError:
|
||||
operator_synonyms: dict[str, list[str]] = get_operator_synonyms()
|
||||
|
||||
def variables_to_operator(synonym):
|
||||
for key in operator_synonyms.keys():
|
||||
if synonym in operator_synonyms[key]:
|
||||
return key
|
||||
|
||||
action = {
|
||||
"plus": '+',
|
||||
"minus": '-',
|
||||
"divide": '/',
|
||||
"multiply": '*',
|
||||
"degree": '**',
|
||||
}
|
||||
|
||||
result_string: str = ''
|
||||
all_variables_of_operators: list[str] = [x for l in operator_synonyms.values() for x in l]
|
||||
operators = {}
|
||||
|
||||
while True:
|
||||
is_clear = True
|
||||
number_of_operator = 1
|
||||
for word in string.split():
|
||||
try:
|
||||
if word in all_variables_of_operators:
|
||||
ope_index = string.index(word)
|
||||
if ope_index in operators.keys():
|
||||
is_clear = True
|
||||
break
|
||||
else:
|
||||
raise ValueError
|
||||
except ValueError:
|
||||
continue
|
||||
else:
|
||||
is_clear = False
|
||||
operators[number_of_operator] = variables_to_operator(word)
|
||||
number_of_operator += 1
|
||||
string = string.replace(word, "&&", 1)
|
||||
if is_clear:
|
||||
break
|
||||
|
||||
num_of_ope = 1
|
||||
for number in string.split("&&"):
|
||||
try:
|
||||
int_num = w2n.word_to_num(number.strip())
|
||||
except ValueError:
|
||||
return ValueError("Invalid input expression")
|
||||
if num_of_ope in operators.keys():
|
||||
result_string += f'{int_num} {action[operators[num_of_ope]]} '
|
||||
num_of_ope += 1
|
||||
else:
|
||||
result_string += f'{int_num}'
|
||||
|
||||
try:
|
||||
result = numexpr.evaluate(result_string)
|
||||
except ZeroDivisionError:
|
||||
return ZeroDivisionError('Except divide by zero')
|
||||
except OverflowError:
|
||||
return OverflowError('Too big result')
|
||||
else:
|
||||
return result
|
||||
@@ -1,10 +0,0 @@
|
||||
from rich.console import Console
|
||||
|
||||
|
||||
console = Console()
|
||||
|
||||
|
||||
def help_command():
|
||||
console.print("[italic bold]The main functionality of the script is to convert an expression from a string "
|
||||
"to a mathematical one and then calculate this expression. "
|
||||
"Project GitHub: https://github.com/koloideal/WordMath[/italic bold]")
|
||||
@@ -1,20 +0,0 @@
|
||||
from rich.console import Console
|
||||
from ...business_logic.word2num_math import word2num_math
|
||||
|
||||
|
||||
console = Console()
|
||||
print_line_separator = lambda: console.print('\n[bold blue]--------------------------------------[/bold blue]\n')
|
||||
|
||||
|
||||
def start_solving_command():
|
||||
while True:
|
||||
console.print(
|
||||
"\n[italic]Enter a string expression or [bold italic green] Q [/bold italic green] for exit:[/italic]")
|
||||
string_expression = input()
|
||||
if string_expression.lower() == 'q':
|
||||
break
|
||||
else:
|
||||
print_line_separator()
|
||||
console.print(
|
||||
f'[bold green]Answer:[/bold green] [bold blue]{word2num_math(string_expression)}[/bold blue]')
|
||||
print_line_separator()
|
||||
@@ -1,26 +0,0 @@
|
||||
import requests
|
||||
from rich.console import Console
|
||||
from ...business_logic.script_updater import UpdateScript
|
||||
|
||||
|
||||
console = Console()
|
||||
print_line_separator = lambda: console.print('\n[bold green]--------------------------------------[/bold green]\n')
|
||||
|
||||
|
||||
def upgrade_command():
|
||||
try:
|
||||
requests.get('https://ya.ru')
|
||||
except requests.exceptions.ConnectionError:
|
||||
console.print('[bold red]No internet connection[/bold red]')
|
||||
else:
|
||||
latest_tag = UpdateScript.start_update()
|
||||
if latest_tag:
|
||||
print_line_separator()
|
||||
console.print(f"[bold yellow]The newest version ({latest_tag}) of the script has been successfully installed![/bold yellow]")
|
||||
print_line_separator()
|
||||
console.print("[bold yellow]Rerun the script for the changes to take effect[/bold yellow]")
|
||||
print_line_separator()
|
||||
exit(0)
|
||||
else:
|
||||
console.print('[bold red]You have the latest version installed[/bold red]')
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
from rich.console import Console
|
||||
from argenta.router import Router
|
||||
|
||||
from ..handlers.handlers_implementation.help_command import help_command
|
||||
from ..handlers.handlers_implementation.solving_command import start_solving_command
|
||||
from ..handlers.handlers_implementation.upgrade_command import upgrade_command
|
||||
|
||||
|
||||
work_router: Router = Router(name='Work points:',
|
||||
ignore_command_register=False)
|
||||
settings_router: Router = Router(name='Settings points:',
|
||||
ignore_command_register=True)
|
||||
|
||||
console = Console()
|
||||
|
||||
|
||||
@work_router.command(command='0', description='Get Help')
|
||||
def command_help():
|
||||
help_command()
|
||||
|
||||
|
||||
@work_router.command(command='1', description='Start Solving')
|
||||
def command_start_solving():
|
||||
start_solving_command()
|
||||
|
||||
|
||||
@settings_router.command(command='U', description='Update WordMath')
|
||||
def command_update():
|
||||
upgrade_command()
|
||||
|
||||
|
||||
@work_router.unknown_command
|
||||
def command_unknown_command(command):
|
||||
console.print(f'[bold red]Unknown command: [/bold red]{command}')
|
||||
@@ -1,44 +0,0 @@
|
||||
{
|
||||
"minus": [
|
||||
"without",
|
||||
"lacking",
|
||||
"deprived_of",
|
||||
"bereft_of",
|
||||
"destitute_of",
|
||||
"minus"
|
||||
],
|
||||
"plus": [
|
||||
"added_to",
|
||||
"add",
|
||||
"coupled_with",
|
||||
"with_the_addition_of",
|
||||
"plus"
|
||||
],
|
||||
"divide": [
|
||||
"separate",
|
||||
"part",
|
||||
"split",
|
||||
"divide",
|
||||
"divide_by"
|
||||
],
|
||||
"multiply": [
|
||||
"extend",
|
||||
"expand",
|
||||
"spread",
|
||||
"build_up",
|
||||
"accumulate",
|
||||
"augment",
|
||||
"multiply",
|
||||
"times"
|
||||
],
|
||||
"degree": [
|
||||
"stage",
|
||||
"extent",
|
||||
"grade",
|
||||
"proportion",
|
||||
"gradation",
|
||||
"to_the_power_of",
|
||||
"degree",
|
||||
"to_the"
|
||||
]
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
{
|
||||
"tag": "v4.1.1"
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
import json
|
||||
|
||||
|
||||
def get_operator_synonyms() -> dict[str, list[str]]:
|
||||
with open("tests/mock_app/local_data/operator_synonyms.json", "r", encoding="utf-8") as file:
|
||||
operator_synonyms: dict = json.load(file)
|
||||
|
||||
return operator_synonyms
|
||||
@@ -1,8 +0,0 @@
|
||||
import json
|
||||
|
||||
|
||||
def get_script_tag() -> str:
|
||||
with open("tests/mock_app/local_data/script_release_tag.json", "r", encoding="utf-8") as file:
|
||||
script_release_tag: str = json.load(file)['tag']
|
||||
|
||||
return script_release_tag
|
||||
@@ -1,31 +0,0 @@
|
||||
from tests.mock_app.handlers.routers import work_router, settings_router
|
||||
from argenta.app.entity import App
|
||||
from art import text2art
|
||||
from rich.console import Console
|
||||
|
||||
|
||||
app: App = App(prompt='[italic white bold]What do you want to do(enter number of action)?',
|
||||
line_separate='[bold green]\n---------------------------------------------\n',
|
||||
print_func=Console().print,
|
||||
command_group_description_separate='')
|
||||
|
||||
|
||||
def main():
|
||||
ascii_name: str = text2art('WordMath', font='nancyj')
|
||||
initial_greeting: str = f'[bold red]\n\n{ascii_name}'
|
||||
|
||||
ascii_goodbye_message: str = text2art('GoodBye', font='small')
|
||||
goodbye_message: str = f'[bold red]\n{ascii_goodbye_message}{' '*12}made by kolo\n'
|
||||
|
||||
app.include_router(work_router, is_main=True)
|
||||
app.include_router(settings_router)
|
||||
|
||||
app.set_initial_greeting(initial_greeting)
|
||||
app.set_farewell_message(goodbye_message)
|
||||
|
||||
app.set_description_message_pattern('[bold red][{command}][/bold red] [blue]*=*=*[/blue] [bold yellow italic]{description}')
|
||||
|
||||
app.start_polling()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -1,30 +0,0 @@
|
||||
from rich.console import Console
|
||||
from argenta.router import Router
|
||||
|
||||
|
||||
work_router: Router = Router(name='Work points:',
|
||||
ignore_command_register=False)
|
||||
settings_router: Router = Router(name='Settings points:',
|
||||
ignore_command_register=True)
|
||||
|
||||
console = Console()
|
||||
|
||||
|
||||
@work_router.command(command='0', description='Get Help')
|
||||
def command_help():
|
||||
print('help command')
|
||||
|
||||
|
||||
@work_router.command(command='1', description='Start Solving')
|
||||
def command_start_solving():
|
||||
print('start solving')
|
||||
|
||||
|
||||
@settings_router.command(command='U', description='Update WordMath')
|
||||
def command_update():
|
||||
print('update wordmath')
|
||||
|
||||
|
||||
@work_router.unknown_command
|
||||
def command_unknown_command(command):
|
||||
console.print(f'[bold red]Unknown command: [/bold red]{command}')
|
||||
@@ -1,16 +0,0 @@
|
||||
from tests.mock_default_app.handlers.routers import work_router, settings_router
|
||||
from argenta.app.entity import App
|
||||
from art import text2art
|
||||
|
||||
|
||||
app: App = App()
|
||||
|
||||
|
||||
def main():
|
||||
app.include_router(work_router, is_main=True)
|
||||
app.include_router(settings_router)
|
||||
|
||||
app.start_polling()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,257 @@
|
||||
import _io
|
||||
from unittest.mock import patch, MagicMock
|
||||
from unittest import TestCase
|
||||
import io
|
||||
import re
|
||||
|
||||
from argenta.app import App
|
||||
from argenta.command import Command, PredefinedFlags
|
||||
from argenta.command.flag.models import ValidationStatus
|
||||
from argenta.router import Router
|
||||
from argenta.command.flag.flags.models import Flags
|
||||
from argenta.orchestrator import Orchestrator
|
||||
from argenta.response import Response
|
||||
|
||||
|
||||
|
||||
class TestSystemHandlerNormalWork(TestCase):
|
||||
@patch("builtins.input", side_effect=["help", "q"])
|
||||
@patch("sys.stdout", new_callable=io.StringIO)
|
||||
def test_input_incorrect_command(self, mock_stdout: _io.StringIO, magick_mock: MagicMock):
|
||||
router = Router()
|
||||
orchestrator = Orchestrator()
|
||||
|
||||
@router.command(Command('test'))
|
||||
def test(response: Response) -> None: # pyright: ignore[reportUnusedFunction]
|
||||
print('test command')
|
||||
|
||||
app = App(override_system_messages=True,
|
||||
print_func=print)
|
||||
app.include_router(router)
|
||||
app.set_unknown_command_handler(lambda command: print(f'Unknown command: {command.trigger}'))
|
||||
orchestrator.start_polling(app)
|
||||
|
||||
output = mock_stdout.getvalue()
|
||||
|
||||
self.assertIn("\nUnknown command: help\n", output)
|
||||
|
||||
|
||||
@patch("builtins.input", side_effect=["TeSt", "Q"])
|
||||
@patch("sys.stdout", new_callable=io.StringIO)
|
||||
def test_input_incorrect_command2(self, mock_stdout: _io.StringIO, magick_mock: MagicMock):
|
||||
router = Router()
|
||||
orchestrator = Orchestrator()
|
||||
|
||||
@router.command(Command('test'))
|
||||
def test(response: Response) -> None: # pyright: ignore[reportUnusedFunction]
|
||||
print('test command')
|
||||
|
||||
app = App(ignore_command_register=False,
|
||||
override_system_messages=True,
|
||||
print_func=print)
|
||||
app.include_router(router)
|
||||
app.set_unknown_command_handler(lambda command: print(f'Unknown command: {command.trigger}'))
|
||||
orchestrator.start_polling(app)
|
||||
|
||||
output = mock_stdout.getvalue()
|
||||
|
||||
self.assertIn('\nUnknown command: TeSt\n', output)
|
||||
|
||||
|
||||
@patch("builtins.input", side_effect=["test --help", "q"])
|
||||
@patch("sys.stdout", new_callable=io.StringIO)
|
||||
def test_input_correct_command_with_unregistered_flag(self, mock_stdout: _io.StringIO, magick_mock: MagicMock):
|
||||
router = Router()
|
||||
orchestrator = Orchestrator()
|
||||
|
||||
@router.command(Command('test'))
|
||||
def test(response: Response) -> None: # pyright: ignore[reportUnusedFunction]
|
||||
undefined_flag = response.input_flags.get_flag_by_name('help')
|
||||
if undefined_flag and undefined_flag.status == ValidationStatus.UNDEFINED:
|
||||
print(f'test command with undefined flag: {undefined_flag.string_entity}')
|
||||
|
||||
app = App(override_system_messages=True,
|
||||
print_func=print)
|
||||
app.include_router(router)
|
||||
orchestrator.start_polling(app)
|
||||
|
||||
output = mock_stdout.getvalue()
|
||||
|
||||
self.assertIn('\ntest command with undefined flag: --help\n', output)
|
||||
|
||||
|
||||
@patch("builtins.input", side_effect=["test --port 22", "q"])
|
||||
@patch("sys.stdout", new_callable=io.StringIO)
|
||||
def test_input_correct_command_with_unregistered_flag2(self, mock_stdout: _io.StringIO, magick_mock: MagicMock):
|
||||
router = Router()
|
||||
orchestrator = Orchestrator()
|
||||
|
||||
@router.command(Command('test'))
|
||||
def test(response: Response) -> None: # pyright: ignore[reportUnusedFunction]
|
||||
undefined_flag = response.input_flags.get_flag_by_name("port")
|
||||
if undefined_flag and undefined_flag.status == ValidationStatus.UNDEFINED:
|
||||
print(f'test command with undefined flag with value: {undefined_flag.string_entity} {undefined_flag.input_value}')
|
||||
else:
|
||||
raise
|
||||
|
||||
app = App(override_system_messages=True,
|
||||
print_func=print)
|
||||
app.include_router(router)
|
||||
orchestrator.start_polling(app)
|
||||
|
||||
output = mock_stdout.getvalue()
|
||||
|
||||
self.assertIn('\ntest command with undefined flag with value: --port 22\n', output)
|
||||
|
||||
|
||||
@patch("builtins.input", side_effect=["test --host 192.168.32.1 --port 132", "q"])
|
||||
@patch("sys.stdout", new_callable=io.StringIO)
|
||||
def test_input_correct_command_with_one_correct_flag_an_one_incorrect_flag(self, mock_stdout: _io.StringIO, magick_mock: MagicMock):
|
||||
router = Router()
|
||||
orchestrator = Orchestrator()
|
||||
flags = Flags([PredefinedFlags.HOST])
|
||||
|
||||
@router.command(Command('test', flags=flags))
|
||||
def test(response: Response) -> None: # pyright: ignore[reportUnusedFunction]
|
||||
undefined_flag = response.input_flags.get_flag_by_name("port")
|
||||
if undefined_flag and undefined_flag.status == ValidationStatus.UNDEFINED:
|
||||
print(f'connecting to host with flag: {undefined_flag.string_entity} {undefined_flag.input_value}')
|
||||
|
||||
app = App(override_system_messages=True,
|
||||
print_func=print)
|
||||
app.include_router(router)
|
||||
orchestrator.start_polling(app)
|
||||
|
||||
output = mock_stdout.getvalue()
|
||||
|
||||
self.assertIn('\nconnecting to host with flag: --port 132\n', output)
|
||||
|
||||
|
||||
@patch("builtins.input", side_effect=["test", "some", "q"])
|
||||
@patch("sys.stdout", new_callable=io.StringIO)
|
||||
def test_input_one_correct_command_and_one_incorrect_command(self, mock_stdout: _io.StringIO, magick_mock: MagicMock):
|
||||
router = Router()
|
||||
orchestrator = Orchestrator()
|
||||
|
||||
@router.command(Command('test'))
|
||||
def test(response: Response) -> None: # pyright: ignore[reportUnusedFunction]
|
||||
print(f'test command')
|
||||
|
||||
app = App(override_system_messages=True,
|
||||
print_func=print)
|
||||
app.include_router(router)
|
||||
app.set_unknown_command_handler(lambda command: print(f'Unknown command: {command.trigger}'))
|
||||
orchestrator.start_polling(app)
|
||||
|
||||
output = mock_stdout.getvalue()
|
||||
|
||||
self.assertRegex(output, re.compile(r'\ntest command\n(.|\n)*\nUnknown command: some'))
|
||||
|
||||
|
||||
@patch("builtins.input", side_effect=["test", "some", "more", "q"])
|
||||
@patch("sys.stdout", new_callable=io.StringIO)
|
||||
def test_input_two_correct_commands_and_one_incorrect_command(self, mock_stdout: _io.StringIO, magick_mock: MagicMock):
|
||||
router = Router()
|
||||
orchestrator = Orchestrator()
|
||||
|
||||
@router.command(Command('test'))
|
||||
def test(response: Response) -> None: # pyright: ignore[reportUnusedFunction]
|
||||
print(f'test command')
|
||||
|
||||
@router.command(Command('more'))
|
||||
def test1(response: Response) -> None: # pyright: ignore[reportUnusedFunction]
|
||||
print(f'more command')
|
||||
|
||||
app = App(override_system_messages=True,
|
||||
print_func=print)
|
||||
app.include_router(router)
|
||||
app.set_unknown_command_handler(lambda command: print(f'Unknown command: {command.trigger}'))
|
||||
orchestrator.start_polling(app)
|
||||
|
||||
output = mock_stdout.getvalue()
|
||||
|
||||
self.assertRegex(output, re.compile(r'\ntest command\n(.|\n)*\nUnknown command: some\n(.|\n)*\nmore command'))
|
||||
|
||||
|
||||
@patch("builtins.input", side_effect=["test 535 --port", "q"])
|
||||
@patch("sys.stdout", new_callable=io.StringIO)
|
||||
def test_input_correct_command_with_incorrect_flag(self, mock_stdout: _io.StringIO, magick_mock: MagicMock):
|
||||
router = Router()
|
||||
orchestrator = Orchestrator()
|
||||
|
||||
@router.command(Command('test'))
|
||||
def test(response: Response) -> None: # pyright: ignore[reportUnusedFunction]
|
||||
print(f'test command')
|
||||
|
||||
app = App(override_system_messages=True,
|
||||
print_func=print)
|
||||
app.include_router(router)
|
||||
app.set_incorrect_input_syntax_handler(lambda command: print(f'Incorrect flag syntax: "{command}"'))
|
||||
orchestrator.start_polling(app)
|
||||
|
||||
output = mock_stdout.getvalue()
|
||||
|
||||
self.assertIn("\nIncorrect flag syntax: \"test 535 --port\"\n", output)
|
||||
|
||||
|
||||
@patch("builtins.input", side_effect=["", "q"])
|
||||
@patch("sys.stdout", new_callable=io.StringIO)
|
||||
def test_input_empty_command(self, mock_stdout: _io.StringIO, magick_mock: MagicMock):
|
||||
router = Router()
|
||||
orchestrator = Orchestrator()
|
||||
|
||||
@router.command(Command('test'))
|
||||
def test(response: Response) -> None: # pyright: ignore[reportUnusedFunction]
|
||||
print(f'test command')
|
||||
|
||||
app = App(override_system_messages=True,
|
||||
print_func=print)
|
||||
app.include_router(router)
|
||||
app.set_empty_command_handler(lambda: print('Empty input command'))
|
||||
orchestrator.start_polling(app)
|
||||
|
||||
output = mock_stdout.getvalue()
|
||||
|
||||
self.assertIn("\nEmpty input command\n", output)
|
||||
|
||||
|
||||
@patch("builtins.input", side_effect=["test --port 22 --port 33", "q"])
|
||||
@patch("sys.stdout", new_callable=io.StringIO)
|
||||
def test_input_correct_command_with_repeated_flags(self, mock_stdout: _io.StringIO, magick_mock: MagicMock):
|
||||
router = Router()
|
||||
orchestrator = Orchestrator()
|
||||
|
||||
@router.command(Command('test', flags=PredefinedFlags.PORT))
|
||||
def test(response: Response) -> None: # pyright: ignore[reportUnusedFunction]
|
||||
print('test command')
|
||||
|
||||
app = App(override_system_messages=True,
|
||||
print_func=print)
|
||||
app.include_router(router)
|
||||
app.set_repeated_input_flags_handler(lambda command: print(f'Repeated input flags: "{command}"'))
|
||||
orchestrator.start_polling(app)
|
||||
|
||||
output = mock_stdout.getvalue()
|
||||
|
||||
self.assertIn('Repeated input flags: "test --port 22 --port 33"', output)
|
||||
|
||||
@patch("builtins.input", side_effect=["test --help", "q"])
|
||||
@patch("sys.stdout", new_callable=io.StringIO)
|
||||
def test_input_correct_command_with_unregistered_flag3(self, mock_stdout: _io.StringIO, magick_mock: MagicMock):
|
||||
router = Router()
|
||||
orchestrator = Orchestrator()
|
||||
|
||||
@router.command(Command('test'))
|
||||
def test(response: Response) -> None: # pyright: ignore[reportUnusedFunction]
|
||||
undefined_flag = response.input_flags.get_flag_by_name('help')
|
||||
if undefined_flag and undefined_flag.status == ValidationStatus.UNDEFINED:
|
||||
print(f'test command with undefined flag: {undefined_flag.string_entity}')
|
||||
|
||||
app = App(override_system_messages=True,
|
||||
print_func=print)
|
||||
app.include_router(router)
|
||||
orchestrator.start_polling(app)
|
||||
|
||||
output = mock_stdout.getvalue()
|
||||
|
||||
self.assertIn('\ntest command with undefined flag: --help\n', output)
|
||||
@@ -0,0 +1,247 @@
|
||||
import _io
|
||||
from unittest.mock import patch, MagicMock
|
||||
from unittest import TestCase
|
||||
import io
|
||||
import re
|
||||
|
||||
from argenta.app import App
|
||||
from argenta.command import Command, PredefinedFlags
|
||||
from argenta.command.flag.models import PossibleValues, ValidationStatus
|
||||
from argenta.response import Response
|
||||
from argenta.router import Router
|
||||
from argenta.orchestrator import Orchestrator
|
||||
from argenta.command.flag import Flag
|
||||
from argenta.command.flag.flags import Flags
|
||||
|
||||
|
||||
|
||||
class TestSystemHandlerNormalWork(TestCase):
|
||||
@patch("builtins.input", side_effect=["test", "q"])
|
||||
@patch("sys.stdout", new_callable=io.StringIO)
|
||||
def test_input_correct_command(self, mock_stdout: _io.StringIO, magick_mock: MagicMock):
|
||||
router = Router()
|
||||
orchestrator = Orchestrator()
|
||||
|
||||
@router.command(Command('test'))
|
||||
def test(response: Response) -> None: # pyright: ignore[reportUnusedFunction]
|
||||
print('test command')
|
||||
|
||||
app = App(override_system_messages=True,
|
||||
print_func=print)
|
||||
app.include_router(router)
|
||||
orchestrator.start_polling(app)
|
||||
|
||||
output = mock_stdout.getvalue()
|
||||
|
||||
self.assertIn('\ntest command\n', output)
|
||||
|
||||
|
||||
@patch("builtins.input", side_effect=["TeSt", "q"])
|
||||
@patch("sys.stdout", new_callable=io.StringIO)
|
||||
def test_input_correct_command2(self, mock_stdout: _io.StringIO, magick_mock: MagicMock):
|
||||
router = Router()
|
||||
orchestrator = Orchestrator()
|
||||
|
||||
@router.command(Command('test'))
|
||||
def test(response: Response) -> None: # pyright: ignore[reportUnusedFunction]
|
||||
print('test command')
|
||||
|
||||
app = App(ignore_command_register=True,
|
||||
override_system_messages=True,
|
||||
print_func=print)
|
||||
app.include_router(router)
|
||||
orchestrator.start_polling(app)
|
||||
|
||||
output = mock_stdout.getvalue()
|
||||
|
||||
self.assertIn('\ntest command\n', output)
|
||||
|
||||
|
||||
@patch("builtins.input", side_effect=["test --help", "q"])
|
||||
@patch("sys.stdout", new_callable=io.StringIO)
|
||||
def test_input_correct_command_with_custom_flag(self, mock_stdout: _io.StringIO, magick_mock: MagicMock):
|
||||
router = Router()
|
||||
orchestrator = Orchestrator()
|
||||
flag = Flag('help', prefix='--', possible_values=PossibleValues.NEITHER)
|
||||
|
||||
@router.command(Command('test', flags=flag))
|
||||
def test(response: Response) -> None: # pyright: ignore[reportUnusedFunction]
|
||||
valid_flag = response.input_flags.get_flag_by_name('help')
|
||||
if valid_flag and valid_flag.status == ValidationStatus.VALID:
|
||||
print(f'\nhelp for {valid_flag.name} flag\n')
|
||||
|
||||
app = App(override_system_messages=True,
|
||||
print_func=print)
|
||||
app.include_router(router)
|
||||
orchestrator.start_polling(app)
|
||||
|
||||
output = mock_stdout.getvalue()
|
||||
|
||||
self.assertIn('\nhelp for help flag\n', output)
|
||||
|
||||
@patch("builtins.input", side_effect=["test --port 22", "q"])
|
||||
@patch("sys.stdout", new_callable=io.StringIO)
|
||||
def test_input_correct_command_with_custom_flag2(self, mock_stdout: _io.StringIO, magick_mock: MagicMock):
|
||||
router = Router()
|
||||
orchestrator = Orchestrator()
|
||||
flag = Flag('port', prefix='--', possible_values=re.compile(r'^\d{1,5}$'))
|
||||
|
||||
@router.command(Command('test', flags=flag))
|
||||
def test(response: Response) -> None: # pyright: ignore[reportUnusedFunction]
|
||||
valid_flag = response.input_flags.get_flag_by_name('port')
|
||||
if valid_flag and valid_flag.status == ValidationStatus.VALID:
|
||||
print(f'flag value for {valid_flag.name} flag : {valid_flag.input_value}')
|
||||
|
||||
app = App(override_system_messages=True,
|
||||
print_func=print)
|
||||
app.include_router(router)
|
||||
orchestrator.start_polling(app)
|
||||
|
||||
output = mock_stdout.getvalue()
|
||||
|
||||
self.assertIn('\nflag value for port flag : 22\n', output)
|
||||
|
||||
|
||||
@patch("builtins.input", side_effect=["test -H", "q"])
|
||||
@patch("sys.stdout", new_callable=io.StringIO)
|
||||
def test_input_correct_command_with_default_flag(self, mock_stdout: _io.StringIO, magick_mock: MagicMock):
|
||||
router = Router()
|
||||
orchestrator = Orchestrator()
|
||||
flag = PredefinedFlags.SHORT_HELP
|
||||
|
||||
@router.command(Command('test', flags=flag))
|
||||
def test(response: Response) -> None: # pyright: ignore[reportUnusedFunction]
|
||||
valid_flag = response.input_flags.get_flag_by_name('H')
|
||||
if valid_flag and valid_flag.status == ValidationStatus.VALID:
|
||||
print(f'help for {valid_flag.name} flag')
|
||||
|
||||
app = App(override_system_messages=True,
|
||||
print_func=print)
|
||||
app.include_router(router)
|
||||
orchestrator.start_polling(app)
|
||||
|
||||
output = mock_stdout.getvalue()
|
||||
|
||||
self.assertIn('\nhelp for H flag\n', output)
|
||||
|
||||
|
||||
@patch("builtins.input", side_effect=["test --info", "q"])
|
||||
@patch("sys.stdout", new_callable=io.StringIO)
|
||||
def test_input_correct_command_with_default_flag2(self, mock_stdout: _io.StringIO, magick_mock: MagicMock):
|
||||
router = Router()
|
||||
orchestrator = Orchestrator()
|
||||
flag = PredefinedFlags.INFO
|
||||
|
||||
@router.command(Command('test', flags=flag))
|
||||
def test(response: Response) -> None: # pyright: ignore[reportUnusedFunction]
|
||||
valid_flag = response.input_flags.get_flag_by_name('info')
|
||||
if valid_flag and valid_flag.status == ValidationStatus.VALID:
|
||||
print('info about test command')
|
||||
|
||||
app = App(override_system_messages=True,
|
||||
print_func=print)
|
||||
app.include_router(router)
|
||||
orchestrator.start_polling(app)
|
||||
|
||||
output = mock_stdout.getvalue()
|
||||
|
||||
self.assertIn('\ninfo about test command\n', output)
|
||||
|
||||
|
||||
@patch("builtins.input", side_effect=["test --host 192.168.0.1", "q"])
|
||||
@patch("sys.stdout", new_callable=io.StringIO)
|
||||
def test_input_correct_command_with_default_flag3(self, mock_stdout: _io.StringIO, magick_mock: MagicMock):
|
||||
router = Router()
|
||||
orchestrator = Orchestrator()
|
||||
flag = PredefinedFlags.HOST
|
||||
|
||||
@router.command(Command('test', flags=flag))
|
||||
def test(response: Response) -> None: # pyright: ignore[reportUnusedFunction]
|
||||
valid_flag = response.input_flags.get_flag_by_name('host')
|
||||
if valid_flag and valid_flag.status == ValidationStatus.VALID:
|
||||
print(f'connecting to host {valid_flag.input_value}')
|
||||
|
||||
app = App(override_system_messages=True,
|
||||
print_func=print)
|
||||
app.include_router(router)
|
||||
orchestrator.start_polling(app)
|
||||
|
||||
output = mock_stdout.getvalue()
|
||||
|
||||
self.assertIn('\nconnecting to host 192.168.0.1\n', output)
|
||||
|
||||
|
||||
@patch("builtins.input", side_effect=["test --host 192.168.32.1 --port 132", "q"])
|
||||
@patch("sys.stdout", new_callable=io.StringIO)
|
||||
def test_input_correct_command_with_two_flags(self, mock_stdout: _io.StringIO, magick_mock: MagicMock):
|
||||
router = Router()
|
||||
orchestrator = Orchestrator()
|
||||
flags = Flags([PredefinedFlags.HOST, PredefinedFlags.PORT])
|
||||
|
||||
@router.command(Command('test', flags=flags))
|
||||
def test(response: Response) -> None: # pyright: ignore[reportUnusedFunction]
|
||||
host_flag = response.input_flags.get_flag_by_name('host')
|
||||
port_flag = response.input_flags.get_flag_by_name('port')
|
||||
if (host_flag and host_flag.status == ValidationStatus.VALID) and (port_flag and port_flag.status == ValidationStatus.VALID):
|
||||
print(f'connecting to host {host_flag.input_value} and port {port_flag.input_value}')
|
||||
|
||||
app = App(override_system_messages=True,
|
||||
print_func=print)
|
||||
app.include_router(router)
|
||||
orchestrator.start_polling(app)
|
||||
|
||||
output = mock_stdout.getvalue()
|
||||
|
||||
self.assertIn('\nconnecting to host 192.168.32.1 and port 132\n', output)
|
||||
|
||||
|
||||
@patch("builtins.input", side_effect=["test", "some", "q"])
|
||||
@patch("sys.stdout", new_callable=io.StringIO)
|
||||
def test_input_two_correct_command(self, mock_stdout: _io.StringIO, magick_mock: MagicMock):
|
||||
router = Router()
|
||||
orchestrator = Orchestrator()
|
||||
|
||||
@router.command(Command('test'))
|
||||
def test(response: Response) -> None: # pyright: ignore[reportUnusedFunction]
|
||||
print(f'test command')
|
||||
|
||||
@router.command(Command('some'))
|
||||
def test2(response: Response) -> None: # pyright: ignore[reportUnusedFunction]
|
||||
print(f'some command')
|
||||
|
||||
app = App(override_system_messages=True,
|
||||
print_func=print)
|
||||
app.include_router(router)
|
||||
orchestrator.start_polling(app)
|
||||
|
||||
output = mock_stdout.getvalue()
|
||||
|
||||
self.assertRegex(output, re.compile(r'\ntest command\n(.|\n)*\nsome command\n'))
|
||||
|
||||
|
||||
@patch("builtins.input", side_effect=["test", "some", "more", "q"])
|
||||
@patch("sys.stdout", new_callable=io.StringIO)
|
||||
def test_input_three_correct_command(self, mock_stdout: _io.StringIO, magick_mock: MagicMock):
|
||||
router = Router()
|
||||
orchestrator = Orchestrator()
|
||||
|
||||
@router.command(Command('test'))
|
||||
def test(response: Response) -> None: # pyright: ignore[reportUnusedFunction]
|
||||
print(f'test command')
|
||||
|
||||
@router.command(Command('some'))
|
||||
def test1(response: Response) -> None: # pyright: ignore[reportUnusedFunction]
|
||||
print(f'some command')
|
||||
|
||||
@router.command(Command('more'))
|
||||
def test2(response: Response) -> None: # pyright: ignore[reportUnusedFunction]
|
||||
print(f'more command')
|
||||
|
||||
app = App(override_system_messages=True,
|
||||
print_func=print)
|
||||
app.include_router(router)
|
||||
orchestrator.start_polling(app)
|
||||
|
||||
output = mock_stdout.getvalue()
|
||||
|
||||
self.assertRegex(output, re.compile(r'\ntest command\n(.|\n)*\nsome command\n(.|\n)*\nmore command'))
|
||||
@@ -0,0 +1,75 @@
|
||||
from argenta.command.models import InputCommand, Command
|
||||
from argenta.app import App
|
||||
|
||||
import unittest
|
||||
|
||||
from argenta.router import Router
|
||||
|
||||
|
||||
class MyTestCase(unittest.TestCase):
|
||||
def test_is_exit_command1(self):
|
||||
app = App()
|
||||
self.assertEqual(app._is_exit_command(InputCommand('q')), True)
|
||||
|
||||
def test_is_exit_command5(self):
|
||||
app = App()
|
||||
self.assertEqual(app._is_exit_command(InputCommand('Q')), True)
|
||||
|
||||
def test_is_exit_command2(self):
|
||||
app = App(ignore_command_register=False)
|
||||
self.assertEqual(app._is_exit_command(InputCommand('q')), False)
|
||||
|
||||
def test_is_exit_command3(self):
|
||||
app = App(exit_command=Command('quit'))
|
||||
self.assertEqual(app._is_exit_command(InputCommand('quit')), True)
|
||||
|
||||
def test_is_exit_command4(self):
|
||||
app = App(exit_command=Command('quit'))
|
||||
self.assertEqual(app._is_exit_command(InputCommand('qUIt')), True)
|
||||
|
||||
def test_is_exit_command6(self):
|
||||
app = App(ignore_command_register=False,
|
||||
exit_command=Command('quit'))
|
||||
self.assertEqual(app._is_exit_command(InputCommand('qUIt')), False)
|
||||
|
||||
def test_is_unknown_command1(self):
|
||||
app = App()
|
||||
app.set_unknown_command_handler(lambda command: None)
|
||||
app._current_matching_triggers_with_routers = {'fr': Router(), 'tr': Router(), 'de': Router()}
|
||||
self.assertEqual(app._is_unknown_command(InputCommand('fr')), False)
|
||||
|
||||
def test_is_unknown_command2(self):
|
||||
app = App()
|
||||
app.set_unknown_command_handler(lambda command: None)
|
||||
app._current_matching_triggers_with_routers = {'fr': Router(), 'tr': Router(), 'de': Router()}
|
||||
self.assertEqual(app._is_unknown_command(InputCommand('cr')), True)
|
||||
|
||||
def test_is_unknown_command3(self):
|
||||
app = App(ignore_command_register=False)
|
||||
app.set_unknown_command_handler(lambda command: None)
|
||||
app._current_matching_triggers_with_routers = {'Pr': Router(), 'tW': Router(), 'deQW': Router()}
|
||||
self.assertEqual(app._is_unknown_command(InputCommand('pr')), True)
|
||||
|
||||
def test_is_unknown_command4(self):
|
||||
app = App(ignore_command_register=False)
|
||||
app.set_unknown_command_handler(lambda command: None)
|
||||
app._current_matching_triggers_with_routers = {'Pr': Router(), 'tW': Router(), 'deQW': Router()}
|
||||
self.assertEqual(app._is_unknown_command(InputCommand('tW')), False)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
from argenta.command.flag import Flag, InputFlag
|
||||
from argenta.command.flag.flags import Flags
|
||||
from argenta.command.flag.models import PossibleValues
|
||||
from argenta.command.models import InputCommand, Command, ValidationStatus
|
||||
from argenta.command.exceptions import (UnprocessedInputFlagException,
|
||||
RepeatedInputFlagsException,
|
||||
EmptyInputCommandException)
|
||||
|
||||
import unittest
|
||||
import re
|
||||
|
||||
|
||||
class TestInputCommand(unittest.TestCase):
|
||||
def test_parse_correct_raw_command(self):
|
||||
self.assertEqual(InputCommand.parse('ssh --host 192.168.0.3').trigger, 'ssh')
|
||||
|
||||
def test_parse_raw_command_without_flag_name_with_value(self):
|
||||
with self.assertRaises(UnprocessedInputFlagException):
|
||||
InputCommand.parse('ssh 192.168.0.3')
|
||||
|
||||
def test_parse_raw_command_with_repeated_flag_name(self):
|
||||
with self.assertRaises(RepeatedInputFlagsException):
|
||||
InputCommand.parse('ssh --host 192.168.0.3 --host 172.198.0.43')
|
||||
|
||||
def test_parse_empty_raw_command(self):
|
||||
with self.assertRaises(EmptyInputCommandException):
|
||||
InputCommand.parse('')
|
||||
|
||||
def test_validate_valid_input_flag1(self):
|
||||
command = Command('some', flags=Flag('test'))
|
||||
self.assertEqual(command.validate_input_flag(InputFlag('test', input_value=None, status=None)), ValidationStatus.VALID)
|
||||
|
||||
def test_validate_valid_input_flag2(self):
|
||||
command = Command('some', flags=Flags([Flag('test'), Flag('more')]))
|
||||
self.assertEqual(command.validate_input_flag(InputFlag('more', input_value=None, status=None)), ValidationStatus.VALID)
|
||||
|
||||
def test_validate_undefined_input_flag1(self):
|
||||
command = Command('some', flags=Flag('test'))
|
||||
self.assertEqual(command.validate_input_flag(InputFlag('more', input_value=None, status=None)), ValidationStatus.UNDEFINED)
|
||||
|
||||
def test_validate_undefined_input_flag2(self):
|
||||
command = Command('some', flags=Flags([Flag('test'), Flag('more')]))
|
||||
self.assertEqual(command.validate_input_flag(InputFlag('case', input_value=None, status=None)), ValidationStatus.UNDEFINED)
|
||||
|
||||
def test_validate_undefined_input_flag3(self):
|
||||
command = Command('some')
|
||||
self.assertEqual(command.validate_input_flag(InputFlag('case', input_value=None, status=None)), ValidationStatus.UNDEFINED)
|
||||
|
||||
def test_invalid_input_flag1(self):
|
||||
command = Command('some', flags=Flag('test', possible_values=PossibleValues.NEITHER))
|
||||
self.assertEqual(command.validate_input_flag(InputFlag('test', input_value='example', status=None)), ValidationStatus.INVALID)
|
||||
|
||||
def test_invalid_input_flag2(self):
|
||||
command = Command('some', flags=Flag('test', possible_values=['some', 'case']))
|
||||
self.assertEqual(command.validate_input_flag(InputFlag('test', input_value='slay', status=None)), ValidationStatus.INVALID)
|
||||
|
||||
def test_invalid_input_flag3(self):
|
||||
command = Command('some', flags=Flag('test', possible_values=re.compile(r'^ex\d{, 2}op$')))
|
||||
self.assertEqual(command.validate_input_flag(InputFlag('test', input_value='example', status=None)), ValidationStatus.INVALID)
|
||||
|
||||
def test_isinstance_parse_correct_raw_command(self):
|
||||
cmd = InputCommand.parse('ssh --host 192.168.0.3')
|
||||
self.assertIsInstance(cmd, InputCommand)
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
from argenta.app.dividing_line import DynamicDividingLine, StaticDividingLine
|
||||
|
||||
import unittest
|
||||
|
||||
|
||||
class TestDividingLine(unittest.TestCase):
|
||||
def test_get_static_dividing_line_full_line(self):
|
||||
line = StaticDividingLine('-')
|
||||
self.assertEqual(line.get_full_static_line(is_override=True).count('-'), 25)
|
||||
|
||||
def test_get_dynamic_dividing_line_full_line(self):
|
||||
line = DynamicDividingLine()
|
||||
self.assertEqual(line.get_full_dynamic_line(length=20, is_override=True).count('-'), 20)
|
||||
|
||||
def test_get_dividing_line_unit_part(self):
|
||||
line = StaticDividingLine('')
|
||||
self.assertEqual(line.get_unit_part(), ' ')
|
||||
|
||||
def test_get_dividing_line2_unit_part(self):
|
||||
line = StaticDividingLine('+-0987654321!@#$%^&*()_')
|
||||
self.assertEqual(line.get_unit_part(), '+')
|
||||
@@ -0,0 +1,129 @@
|
||||
from argenta.command.flag import Flag, InputFlag, PossibleValues
|
||||
from argenta.command.flag.flags import InputFlags, Flags
|
||||
|
||||
import unittest
|
||||
import re
|
||||
|
||||
|
||||
class TestFlag(unittest.TestCase):
|
||||
def test_get_string_entity(self):
|
||||
self.assertEqual(Flag(name='test').string_entity,
|
||||
'--test')
|
||||
|
||||
def test_get_string_entity2(self):
|
||||
self.assertEqual(Flag(name='test',
|
||||
prefix='---').string_entity,
|
||||
'---test')
|
||||
|
||||
def test_get_flag_name(self):
|
||||
self.assertEqual(Flag(name='test').name,
|
||||
'test')
|
||||
|
||||
def test_get_flag_prefix(self):
|
||||
self.assertEqual(Flag(name='test').prefix,
|
||||
'--')
|
||||
|
||||
def test_get_flag_prefix2(self):
|
||||
self.assertEqual(Flag(name='test',
|
||||
prefix='--').prefix,
|
||||
'--')
|
||||
|
||||
def test_get_flag_value_without_set(self):
|
||||
self.assertEqual(InputFlag(name='test', input_value=None, status=None).input_value,
|
||||
None)
|
||||
|
||||
def test_get_flag_value_with_set(self):
|
||||
flag = InputFlag(name='test', input_value='example', status=None)
|
||||
self.assertEqual(flag.input_value, 'example')
|
||||
|
||||
def test_validate_incorrect_flag_value_with_list_of_possible_flag_values(self):
|
||||
flag = Flag(name='test', possible_values=['1', '2', '3'])
|
||||
self.assertEqual(flag.validate_input_flag_value('bad value'), False)
|
||||
|
||||
def test_validate_correct_flag_value_with_list_of_possible_flag_values(self):
|
||||
flag = Flag(name='test', possible_values=['1', '2', '3'])
|
||||
self.assertEqual(flag.validate_input_flag_value('1'), True)
|
||||
|
||||
def test_validate_incorrect_flag_value_with_pattern_of_possible_flag_values(self):
|
||||
flag = Flag(name='test', possible_values=re.compile(r'192.168.\d+.\d+'))
|
||||
self.assertEqual(flag.validate_input_flag_value('152.123.9.8'), False)
|
||||
|
||||
def test_validate_correct_flag_value_with_pattern_of_possible_flag_values(self):
|
||||
flag = Flag(name='test', possible_values=re.compile(r'192.168.\d+.\d+'))
|
||||
self.assertEqual(flag.validate_input_flag_value('192.168.9.8'), True)
|
||||
|
||||
def test_validate_correct_empty_flag_value_without_possible_flag_values(self):
|
||||
flag = Flag(name='test', possible_values=PossibleValues.NEITHER)
|
||||
self.assertEqual(flag.validate_input_flag_value(None), True)
|
||||
|
||||
def test_validate_correct_empty_flag_value_with_possible_flag_values(self):
|
||||
flag = Flag(name='test', possible_values=PossibleValues.NEITHER)
|
||||
self.assertEqual(flag.validate_input_flag_value(None), True)
|
||||
|
||||
def test_validate_incorrect_random_flag_value_without_possible_flag_values(self):
|
||||
flag = Flag(name='test', possible_values=PossibleValues.NEITHER)
|
||||
self.assertEqual(flag.validate_input_flag_value('random value'), False)
|
||||
|
||||
def test_validate_correct_random_flag_value_with_possible_flag_values(self):
|
||||
flag = Flag(name='test', possible_values=PossibleValues.ALL)
|
||||
self.assertEqual(flag.validate_input_flag_value('random value'), True)
|
||||
|
||||
def test_get_input_flag1(self):
|
||||
flag = InputFlag(name='test', input_value=None, status=None)
|
||||
input_flags = InputFlags([flag])
|
||||
self.assertEqual(input_flags.get_flag_by_name('test'), flag)
|
||||
|
||||
def test_get_input_flag2(self):
|
||||
flag = InputFlag(name='test', input_value=None, status=None)
|
||||
flag2 = InputFlag(name='some', input_value=None, status=None)
|
||||
input_flags = InputFlags([flag, flag2])
|
||||
self.assertEqual(input_flags.get_flag_by_name('some'), flag2)
|
||||
|
||||
def test_get_undefined_input_flag(self):
|
||||
flag = InputFlag(name='test', input_value=None, status=None)
|
||||
flag2 = InputFlag(name='some', input_value=None, status=None)
|
||||
input_flags = InputFlags([flag, flag2])
|
||||
self.assertEqual(input_flags.get_flag_by_name('case'), None)
|
||||
|
||||
def test_get_flags(self):
|
||||
flags = Flags()
|
||||
list_of_flags = [
|
||||
Flag('test1'),
|
||||
Flag('test2'),
|
||||
Flag('test3'),
|
||||
]
|
||||
flags.add_flags(list_of_flags)
|
||||
self.assertEqual(flags.flags,
|
||||
list_of_flags)
|
||||
|
||||
def test_add_flag(self):
|
||||
flags = Flags()
|
||||
flags.add_flag(Flag('test'))
|
||||
self.assertEqual(len(flags.flags), 1)
|
||||
|
||||
def test_add_flags(self):
|
||||
flags = Flags()
|
||||
flags.add_flags([Flag('test'), Flag('test2')])
|
||||
self.assertEqual(len(flags.flags), 2)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,119 @@
|
||||
from argenta.command.flag import InputFlag, Flag
|
||||
from argenta.command.flag.flags import Flags, InputFlags
|
||||
from argenta.command.flag.models import PossibleValues, ValidationStatus
|
||||
from argenta.response.entity import Response
|
||||
from argenta.router import Router
|
||||
from argenta.command import Command
|
||||
from argenta.router.entity import _structuring_input_flags, _validate_command, _validate_func_args # pyright: ignore[reportPrivateUsage]
|
||||
from argenta.router.exceptions import (TriggerContainSpacesException,
|
||||
RepeatedFlagNameException,
|
||||
TooManyTransferredArgsException,
|
||||
RequiredArgumentNotPassedException)
|
||||
|
||||
import unittest
|
||||
import re
|
||||
|
||||
|
||||
class TestRouter(unittest.TestCase):
|
||||
def test_register_command_with_spaces_in_trigger(self):
|
||||
with self.assertRaises(TriggerContainSpacesException):
|
||||
_validate_command(Command(trigger='command with spaces'))
|
||||
|
||||
def test_register_command_with_repeated_flags(self):
|
||||
with self.assertRaises(RepeatedFlagNameException):
|
||||
_validate_command(Command(trigger='command', flags=Flags([Flag('test'), Flag('test')])))
|
||||
|
||||
def test_structuring_input_flags1(self):
|
||||
cmd = Command('cmd')
|
||||
input_flags = InputFlags([InputFlag('ssh', input_value=None, status=None)])
|
||||
self.assertEqual(_structuring_input_flags(cmd, input_flags).input_flags, InputFlags([InputFlag('ssh', input_value=None, status=ValidationStatus.UNDEFINED)]))
|
||||
|
||||
def test_structuring_input_flags2(self):
|
||||
cmd = Command('cmd')
|
||||
input_flags = InputFlags([InputFlag('ssh', input_value='some', status=None)])
|
||||
self.assertEqual(_structuring_input_flags(cmd, input_flags).input_flags, InputFlags([InputFlag('ssh', input_value='some', status=ValidationStatus.UNDEFINED)]))
|
||||
|
||||
def test_structuring_input_flags3(self):
|
||||
cmd = Command('cmd', flags=Flag('port'))
|
||||
input_flags = InputFlags([InputFlag('ssh', input_value='some2', status=None)])
|
||||
self.assertEqual(_structuring_input_flags(cmd, input_flags).input_flags, InputFlags([InputFlag('ssh', input_value='some2', status=ValidationStatus.UNDEFINED)]))
|
||||
|
||||
def test_structuring_input_flags4(self):
|
||||
command = Command('cmd', flags=Flag('ssh', possible_values=PossibleValues.NEITHER))
|
||||
input_flags = InputFlags([InputFlag('ssh', input_value='some3', status=None)])
|
||||
self.assertEqual(_structuring_input_flags(command, input_flags).input_flags, InputFlags([InputFlag('ssh', input_value='some3', status=ValidationStatus.INVALID)]))
|
||||
|
||||
def test_structuring_input_flags5(self):
|
||||
command = Command('cmd', flags=Flag('ssh', possible_values=re.compile(r'some[1-5]$')))
|
||||
input_flags = InputFlags([InputFlag('ssh', input_value='some40', status=None)])
|
||||
self.assertEqual(_structuring_input_flags(command, input_flags).input_flags, InputFlags([InputFlag('ssh', input_value='some40', status=ValidationStatus.INVALID)]))
|
||||
|
||||
def test_structuring_input_flags6(self):
|
||||
command = Command('cmd', flags=Flag('ssh', possible_values=['example']))
|
||||
input_flags = InputFlags([InputFlag('ssh', input_value='example2', status=None)])
|
||||
self.assertEqual(_structuring_input_flags(command, input_flags).input_flags, InputFlags([InputFlag('ssh', input_value='example2', status=ValidationStatus.INVALID)]))
|
||||
|
||||
def test_structuring_input_flags7(self):
|
||||
command = Command('cmd', flags=Flag('port'))
|
||||
input_flags = InputFlags([InputFlag('port', input_value='some2', status=None)])
|
||||
self.assertEqual(_structuring_input_flags(command, input_flags).input_flags, InputFlags([InputFlag('port', input_value='some2', status=ValidationStatus.VALID)]))
|
||||
|
||||
def test_structuring_input_flags8(self):
|
||||
command = Command('cmd', flags=Flag('port', possible_values=['some2', 'some3']))
|
||||
input_flags = InputFlags([InputFlag('port', input_value='some2', status=None)])
|
||||
self.assertEqual(_structuring_input_flags(command, input_flags).input_flags, InputFlags([InputFlag('port', input_value='some2', status=ValidationStatus.VALID)]))
|
||||
|
||||
def test_structuring_input_flags9(self):
|
||||
command = Command('cmd', flags=Flag('ssh', possible_values=re.compile(r'more[1-5]$')))
|
||||
input_flags = InputFlags([InputFlag('ssh', input_value='more5', status=None)])
|
||||
self.assertEqual(_structuring_input_flags(command, input_flags).input_flags, InputFlags([InputFlag('ssh', input_value='more5', status=ValidationStatus.VALID)]))
|
||||
|
||||
def test_structuring_input_flags10(self):
|
||||
command = Command('cmd', flags=Flag('ssh', possible_values=PossibleValues.NEITHER))
|
||||
input_flags = InputFlags([InputFlag('ssh', input_value=None, status=None)])
|
||||
self.assertEqual(_structuring_input_flags(command, input_flags).input_flags, InputFlags([InputFlag('ssh', input_value=None, status=ValidationStatus.VALID)]))
|
||||
|
||||
def test_validate_incorrect_func_args1(self):
|
||||
def handler():
|
||||
pass
|
||||
with self.assertRaises(RequiredArgumentNotPassedException):
|
||||
_validate_func_args(handler) # pyright: ignore[reportArgumentType]
|
||||
|
||||
def test_validate_incorrect_func_args2(self):
|
||||
def handler(args, kwargs): # pyright: ignore[reportMissingParameterType, reportUnknownParameterType]
|
||||
pass
|
||||
with self.assertRaises(TooManyTransferredArgsException):
|
||||
_validate_func_args(handler) # pyright: ignore[reportArgumentType]
|
||||
|
||||
def test_get_router_aliases(self):
|
||||
router = Router()
|
||||
@router.command(Command('some', aliases=['test', 'case']))
|
||||
def handler(response: Response) -> None: # pyright: ignore[reportUnusedFunction]
|
||||
pass
|
||||
self.assertListEqual(router.aliases, ['test', 'case'])
|
||||
|
||||
def test_get_router_aliases2(self):
|
||||
router = Router()
|
||||
@router.command(Command('some', aliases=['test', 'case']))
|
||||
def handler(response: Response): # pyright: ignore[reportUnusedFunction]
|
||||
pass
|
||||
@router.command(Command('ext', aliases=['more', 'foo']))
|
||||
def handler2(response: Response): # pyright: ignore[reportUnusedFunction]
|
||||
pass
|
||||
self.assertListEqual(router.aliases, ['test', 'case', 'more', 'foo'])
|
||||
|
||||
def test_get_router_aliases3(self):
|
||||
router = Router()
|
||||
@router.command(Command('some'))
|
||||
def handler(response: Response): # pyright: ignore[reportUnusedFunction]
|
||||
pass
|
||||
self.assertListEqual(router.aliases, [])
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||