diff --git a/.gitignore b/.gitignore index 084165a..66a2d03 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ .venv .idea dist -poetry.lock +uv.lock *__pycache__/ *.hist* build diff --git a/README.md b/README.md index 4c21710..2c0ce86 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,7 @@ - [**RequiredArgumentNotPassedException** Objects](#requiredargumentnotpassedexception-objects) - [**IncorrectNumberOfHandlerArgsException** Objects](#incorrectnumberofhandlerargsexception-objects) - [**TriggerContainSpacesException** Objects](#triggercontainspacesexception-objects) +- [**Tests**](#tests) --- diff --git a/pyproject.toml b/pyproject.toml index 1ed90b5..04d2473 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,15 +1,21 @@ [project] name = "argenta" -version = "0.5.0" +version = "1.0.0-alpha" description = "Python library for creating TUI" -authors = [ - {name = "kolo", email = "kolo.is.main@gmail.com"} -] -license = {text = "MIT"} -readme = "README.md" +authors = [{ name = "kolo", email = "kolo.is.main@gmail.com" }] requires-python = ">=3.11, <4.0" -dependencies = ["rich (>=14.0.0,<15.0.0)", "art (>=6.4,<7.0)", "pyreadline3 (>=3.5.4,<4.0.0)"] +readme = "README.md" +license = { text = "MIT" } +dependencies = [ + "rich (>=14.0.0,<15.0.0)", + "art (>=6.4,<7.0)", + "pyreadline3 (>=3.5.4,<4.0.0)", +] +[dependency-groups] +dev = [ + "pydoc-markdown>=4.8.2,<5", +] [tool.ruff] exclude = [ @@ -21,12 +27,7 @@ exclude = [ "tests" ] - [build-system] -requires = ["poetry-core>=2.0.0,<3.0.0"] -build-backend = "poetry.core.masonry.api" - -[tool.poetry.group.dev.dependencies] -sphinx = "^8.2.3" -pydoc-markdown = "^4.8.2" +requires = ["hatchling"] +build-backend = "hatchling.build" diff --git a/argenta/app/registered_routers/__init__.py b/src/__init__.py similarity index 100% rename from argenta/app/registered_routers/__init__.py rename to src/__init__.py diff --git a/argenta/router/command_handler/__init__.py b/src/argenta/__init__.py similarity index 100% rename from argenta/router/command_handler/__init__.py rename to src/argenta/__init__.py diff --git a/argenta/app/__init__.py b/src/argenta/app/__init__.py similarity index 100% rename from argenta/app/__init__.py rename to src/argenta/app/__init__.py diff --git a/argenta/app/autocompleter/__init__.py b/src/argenta/app/autocompleter/__init__.py similarity index 100% rename from argenta/app/autocompleter/__init__.py rename to src/argenta/app/autocompleter/__init__.py diff --git a/argenta/app/autocompleter/entity.py b/src/argenta/app/autocompleter/entity.py similarity index 100% rename from argenta/app/autocompleter/entity.py rename to src/argenta/app/autocompleter/entity.py diff --git a/argenta/app/defaults.py b/src/argenta/app/defaults.py similarity index 100% rename from argenta/app/defaults.py rename to src/argenta/app/defaults.py diff --git a/argenta/app/dividing_line/__init__.py b/src/argenta/app/dividing_line/__init__.py similarity index 100% rename from argenta/app/dividing_line/__init__.py rename to src/argenta/app/dividing_line/__init__.py diff --git a/argenta/app/dividing_line/models.py b/src/argenta/app/dividing_line/models.py similarity index 100% rename from argenta/app/dividing_line/models.py rename to src/argenta/app/dividing_line/models.py diff --git a/argenta/app/exceptions.py b/src/argenta/app/exceptions.py similarity index 100% rename from argenta/app/exceptions.py rename to src/argenta/app/exceptions.py diff --git a/argenta/app/models.py b/src/argenta/app/models.py similarity index 99% rename from argenta/app/models.py rename to src/argenta/app/models.py index c1a9bf7..64f9187 100644 --- a/argenta/app/models.py +++ b/src/argenta/app/models.py @@ -346,7 +346,7 @@ class App(BaseApp): continue if self._is_exit_command(input_command): - system_router.input_command_handler(input_command) + system_router.finds_appropriate_handler(input_command) self._autocompleter.exit_setup() return @@ -355,7 +355,7 @@ class App(BaseApp): with redirect_stdout(io.StringIO()) as f: for registered_router in self._registered_routers: - registered_router.input_command_handler(input_command) + registered_router.finds_appropriate_handler(input_command) res: str = f.getvalue() self._print_framed_text(res) diff --git a/src/argenta/app/registered_routers/__init__.py b/src/argenta/app/registered_routers/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/argenta/app/registered_routers/entity.py b/src/argenta/app/registered_routers/entity.py similarity index 100% rename from argenta/app/registered_routers/entity.py rename to src/argenta/app/registered_routers/entity.py diff --git a/argenta/command/__init__.py b/src/argenta/command/__init__.py similarity index 100% rename from argenta/command/__init__.py rename to src/argenta/command/__init__.py diff --git a/argenta/command/exceptions.py b/src/argenta/command/exceptions.py similarity index 100% rename from argenta/command/exceptions.py rename to src/argenta/command/exceptions.py diff --git a/argenta/command/flag/__init__.py b/src/argenta/command/flag/__init__.py similarity index 100% rename from argenta/command/flag/__init__.py rename to src/argenta/command/flag/__init__.py diff --git a/argenta/command/flag/defaults.py b/src/argenta/command/flag/defaults.py similarity index 100% rename from argenta/command/flag/defaults.py rename to src/argenta/command/flag/defaults.py diff --git a/argenta/command/flag/models.py b/src/argenta/command/flag/models.py similarity index 100% rename from argenta/command/flag/models.py rename to src/argenta/command/flag/models.py diff --git a/argenta/command/models.py b/src/argenta/command/models.py similarity index 78% rename from argenta/command/models.py rename to src/argenta/command/models.py index 7ebf472..7f4e17d 100644 --- a/argenta/command/models.py +++ b/src/argenta/command/models.py @@ -42,12 +42,25 @@ class Command(BaseCommand): self._aliases = aliases if isinstance(aliases, list) else [] def get_registered_flags(self) -> Flags: + """ + Private. Returns the registered flags + :return: the registered flags as Flags + """ return self._registered_flags - def get_aliases(self) -> list[str] | None: + def get_aliases(self) -> list[str] | list: + """ + Public. Returns the aliases of the command + :return: the aliases of the command as list[str] | list + """ return self._aliases - def validate_input_flag(self, flag: InputFlag): + def validate_input_flag(self, flag: InputFlag) -> bool: + """ + Private. Validates the input flag + :param flag: input flag for validation + :return: is input flag valid as bool + """ registered_flags: Flags | None = self.get_registered_flags() if registered_flags: if isinstance(registered_flags, Flag): @@ -64,6 +77,10 @@ class Command(BaseCommand): return False def get_description(self) -> str: + """ + Private. Returns the description of the command + :return: the description of the command as str + """ return self._description @@ -71,18 +88,38 @@ class Command(BaseCommand): class InputCommand(BaseCommand, Generic[InputCommandType]): def __init__(self, trigger: str, input_flags: InputFlag | InputFlags = None): + """ + Private. The model of the input command, after parsing + :param trigger:the trigger of the command + :param input_flags: the input flags + :return: None + """ super().__init__(trigger) self._input_flags: InputFlags = input_flags if isinstance(input_flags, InputFlags) else InputFlags(input_flags) if isinstance(input_flags, InputFlag) else InputFlags() - def _set_input_flags(self, input_flags: InputFlags): + def _set_input_flags(self, input_flags: InputFlags) -> None: + """ + Private. Sets the input flags + :param input_flags: the input flags to set + :return: None + """ self._input_flags = input_flags def get_input_flags(self) -> InputFlags: + """ + Private. Returns the input flags + :return: the input flags as InputFlags + """ return self._input_flags @staticmethod def parse(raw_command: str) -> InputCommandType: + """ + Private. Parse the raw input command + :param raw_command: raw input command + :return: model of the input command, after parsing as InputCommand + """ if not raw_command: raise EmptyInputCommandException() diff --git a/argenta/orchestrator/__init__.py b/src/argenta/orchestrator/__init__.py similarity index 100% rename from argenta/orchestrator/__init__.py rename to src/argenta/orchestrator/__init__.py diff --git a/argenta/orchestrator/argparser/__init__.py b/src/argenta/orchestrator/argparser/__init__.py similarity index 100% rename from argenta/orchestrator/argparser/__init__.py rename to src/argenta/orchestrator/argparser/__init__.py diff --git a/argenta/orchestrator/argparser/arguments/__init__.py b/src/argenta/orchestrator/argparser/arguments/__init__.py similarity index 100% rename from argenta/orchestrator/argparser/arguments/__init__.py rename to src/argenta/orchestrator/argparser/arguments/__init__.py diff --git a/argenta/orchestrator/argparser/arguments/models.py b/src/argenta/orchestrator/argparser/arguments/models.py similarity index 100% rename from argenta/orchestrator/argparser/arguments/models.py rename to src/argenta/orchestrator/argparser/arguments/models.py diff --git a/argenta/orchestrator/argparser/entity.py b/src/argenta/orchestrator/argparser/entity.py similarity index 100% rename from argenta/orchestrator/argparser/entity.py rename to src/argenta/orchestrator/argparser/entity.py diff --git a/argenta/orchestrator/entity.py b/src/argenta/orchestrator/entity.py similarity index 100% rename from argenta/orchestrator/entity.py rename to src/argenta/orchestrator/entity.py diff --git a/argenta/router/__init__.py b/src/argenta/router/__init__.py similarity index 100% rename from argenta/router/__init__.py rename to src/argenta/router/__init__.py diff --git a/src/argenta/router/command_handler/__init__.py b/src/argenta/router/command_handler/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/argenta/router/command_handler/entity.py b/src/argenta/router/command_handler/entity.py similarity index 100% rename from argenta/router/command_handler/entity.py rename to src/argenta/router/command_handler/entity.py diff --git a/argenta/router/defaults.py b/src/argenta/router/defaults.py similarity index 100% rename from argenta/router/defaults.py rename to src/argenta/router/defaults.py diff --git a/argenta/router/entity.py b/src/argenta/router/entity.py similarity index 84% rename from argenta/router/entity.py rename to src/argenta/router/entity.py index 20ce841..50c6088 100644 --- a/argenta/router/entity.py +++ b/src/argenta/router/entity.py @@ -1,14 +1,14 @@ from typing import Callable from inspect import getfullargspec -from argenta.command import Command -from argenta.command.models import InputCommand -from argenta.router.command_handler.entity import CommandHandlers, CommandHandler -from argenta.command.flag.models import Flag, Flags, InputFlags -from argenta.router.exceptions import (RepeatedFlagNameException, - TooManyTransferredArgsException, - RequiredArgumentNotPassedException, - IncorrectNumberOfHandlerArgsException, - TriggerContainSpacesException) +from src.argenta.command import Command +from src.argenta.command.models import InputCommand +from src.argenta.router.command_handler.entity import CommandHandlers, CommandHandler +from src.argenta.command.flag.models import Flag, Flags, InputFlags +from src.argenta.router.exceptions import (RepeatedFlagNameException, + TooManyTransferredArgsException, + RequiredArgumentNotPassedException, + IncorrectNumberOfHandlerArgsException, + TriggerContainSpacesException) class Router: @@ -58,9 +58,9 @@ class Router: self._not_valid_flag_handler = func - def input_command_handler(self, input_command: InputCommand) -> None: + def finds_appropriate_handler(self, input_command: InputCommand) -> None: """ - Private. One handler for all input commands + Private. Finds the appropriate handler for given input command and passes control to it :param input_command: input command as InputCommand :return: None """ @@ -70,15 +70,14 @@ class Router: for command_handler in self._command_handlers: handle_command = command_handler.get_handled_command() if input_command_name.lower() == handle_command.get_trigger().lower(): - self._validate_input_command(input_command_flags, command_handler) - elif handle_command.get_aliases(): - if input_command_name.lower() in handle_command.get_aliases(): - self._validate_input_command(input_command_flags, command_handler) + self.process_input_command(input_command_flags, command_handler) + if input_command_name.lower() in handle_command.get_aliases(): + self.process_input_command(input_command_flags, command_handler) - def _validate_input_command(self, input_command_flags: InputFlags, command_handler: CommandHandler) -> None: + def process_input_command(self, input_command_flags: InputFlags, command_handler: CommandHandler) -> None: """ - Private. Validates flags of input command + 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 diff --git a/argenta/router/exceptions.py b/src/argenta/router/exceptions.py similarity index 100% rename from argenta/router/exceptions.py rename to src/argenta/router/exceptions.py diff --git a/tests/unit_tests/test_router.py b/tests/unit_tests/test_router.py index 4a434cf..4e9bc9c 100644 --- a/tests/unit_tests/test_router.py +++ b/tests/unit_tests/test_router.py @@ -1,6 +1,6 @@ -from argenta.router import Router -from argenta.command import Command -from argenta.router.exceptions import TriggerContainSpacesException +from src.argenta.router import Router +from src.argenta.command import Command +from src.argenta.router import TriggerContainSpacesException import unittest