argenta 1.0.0b2__py3-none-any.whl → 1.0.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,3 @@
1
1
  __all__ = ["Command"]
2
2
 
3
- from argenta.command.models import Command
3
+ from argenta.command.models import Command
@@ -5,6 +5,7 @@ class BaseInputCommandException(Exception):
5
5
  """
6
6
  Private. Base exception class for all exceptions raised when parse input command
7
7
  """
8
+
8
9
  pass
9
10
 
10
11
 
@@ -12,6 +13,7 @@ class UnprocessedInputFlagException(BaseInputCommandException):
12
13
  """
13
14
  Private. Raised when an unprocessed input flag is detected
14
15
  """
16
+
15
17
  def __str__(self):
16
18
  return "Unprocessed Input Flags"
17
19
 
@@ -20,16 +22,21 @@ class RepeatedInputFlagsException(BaseInputCommandException):
20
22
  """
21
23
  Private. Raised when repeated input flags are detected
22
24
  """
25
+
23
26
  def __init__(self, flag: Flag | InputFlag):
24
27
  self.flag = flag
28
+
25
29
  def __str__(self):
26
- return ("Repeated Input Flags\n"
27
- f"Duplicate flag was detected in the input: '{self.flag.get_string_entity()}'")
30
+ return (
31
+ "Repeated Input Flags\n"
32
+ f"Duplicate flag was detected in the input: '{self.flag.get_string_entity()}'"
33
+ )
28
34
 
29
35
 
30
36
  class EmptyInputCommandException(BaseInputCommandException):
31
37
  """
32
38
  Private. Raised when an empty input command is detected
33
39
  """
40
+
34
41
  def __str__(self):
35
42
  return "Input Command is empty"
@@ -8,17 +8,24 @@ class PredefinedFlags:
8
8
  """
9
9
  Public. A dataclass with predefined flags and most frequently used flags for quick use
10
10
  """
11
- HELP = Flag(name='help', possible_values=False)
12
- SHORT_HELP = Flag(name='H', prefix='-', possible_values=False)
13
11
 
14
- INFO = Flag(name='info', possible_values=False)
15
- SHORT_INFO = Flag(name='I', prefix='-', possible_values=False)
12
+ HELP = Flag(name="help", possible_values=False)
13
+ SHORT_HELP = Flag(name="H", prefix="-", possible_values=False)
16
14
 
17
- ALL = Flag(name='all', possible_values=False)
18
- SHORT_ALL = Flag(name='A', prefix='-', possible_values=False)
15
+ INFO = Flag(name="info", possible_values=False)
16
+ SHORT_INFO = Flag(name="I", prefix="-", possible_values=False)
19
17
 
20
- HOST = Flag(name='host', possible_values=re.compile(r'^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$'))
21
- SHORT_HOST = Flag(name='H', prefix='-', possible_values=re.compile(r'^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$'))
18
+ ALL = Flag(name="all", possible_values=False)
19
+ SHORT_ALL = Flag(name="A", prefix="-", possible_values=False)
22
20
 
23
- PORT = Flag(name='port', possible_values=re.compile(r'^\d{1,5}$'))
24
- SHORT_PORT = Flag(name='P', prefix='-', possible_values=re.compile(r'^\d{1,5}$'))
21
+ HOST = Flag(
22
+ name="host", possible_values=re.compile(r"^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$")
23
+ )
24
+ SHORT_HOST = Flag(
25
+ name="H",
26
+ prefix="-",
27
+ possible_values=re.compile(r"^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$"),
28
+ )
29
+
30
+ PORT = Flag(name="port", possible_values=re.compile(r"^\d{1,5}$"))
31
+ SHORT_PORT = Flag(name="P", prefix="-", possible_values=re.compile(r"^\d{1,5}$"))
@@ -1,10 +1,8 @@
1
1
  from typing import Literal, Pattern
2
2
 
3
3
 
4
-
5
4
  class BaseFlag:
6
- def __init__(self, name: str,
7
- prefix: Literal['-', '--', '---'] = '--') -> None:
5
+ def __init__(self, name: str, prefix: Literal["-", "--", "---"] = "--") -> None:
8
6
  """
9
7
  Private. Base class for flags
10
8
  :param name: the name of the flag
@@ -41,9 +39,12 @@ class BaseFlag:
41
39
 
42
40
 
43
41
  class Flag(BaseFlag):
44
- def __init__(self, name: str,
45
- prefix: Literal['-', '--', '---'] = '--',
46
- possible_values: list[str] | Pattern[str] | False = True) -> None:
42
+ def __init__(
43
+ self,
44
+ name: str,
45
+ prefix: Literal["-", "--", "---"] = "--",
46
+ possible_values: list[str] | Pattern[str] | False = True,
47
+ ) -> None:
47
48
  """
48
49
  Public. The entity of the flag being registered for subsequent processing
49
50
  :param name: The name of the flag
@@ -85,9 +86,9 @@ class Flag(BaseFlag):
85
86
 
86
87
 
87
88
  class InputFlag(BaseFlag):
88
- def __init__(self, name: str,
89
- prefix: Literal['-', '--', '---'] = '--',
90
- value: str = None):
89
+ def __init__(
90
+ self, name: str, prefix: Literal["-", "--", "---"] = "--", value: str = None
91
+ ):
91
92
  """
92
93
  Public. The entity of the flag of the entered command
93
94
  :param name: the name of the input flag
@@ -114,5 +115,7 @@ class InputFlag(BaseFlag):
114
115
  self._flag_value = value
115
116
 
116
117
  def __eq__(self, other) -> bool:
117
- return self.get_string_entity() == other.get_string_entity() and self.get_value() == other.get_value()
118
-
118
+ return (
119
+ self.get_string_entity() == other.get_string_entity()
120
+ and self.get_value() == other.get_value()
121
+ )
@@ -1,10 +1,16 @@
1
- __all__ = ["Flags", "InputFlags",
2
- "UndefinedInputFlags",
3
- "InvalidValueInputFlags",
4
- "ValidInputFlags"]
1
+ __all__ = [
2
+ "Flags",
3
+ "InputFlags",
4
+ "UndefinedInputFlags",
5
+ "InvalidValueInputFlags",
6
+ "ValidInputFlags",
7
+ ]
5
8
 
6
9
 
7
- from argenta.command.flags.models import (Flags, InputFlags,
8
- UndefinedInputFlags,
9
- InvalidValueInputFlags,
10
- ValidInputFlags)
10
+ from argenta.command.flags.models import (
11
+ Flags,
12
+ InputFlags,
13
+ UndefinedInputFlags,
14
+ InvalidValueInputFlags,
15
+ ValidInputFlags,
16
+ )
@@ -2,8 +2,7 @@ from argenta.command.flag.models import InputFlag, Flag
2
2
  from typing import Generic, TypeVar
3
3
 
4
4
 
5
-
6
- FlagType = TypeVar('FlagType')
5
+ FlagType = TypeVar("FlagType")
7
6
 
8
7
 
9
8
  class BaseFlags(Generic[FlagType]):
@@ -71,17 +70,21 @@ class BaseFlags(Generic[FlagType]):
71
70
  return True
72
71
 
73
72
 
74
- class Flags(BaseFlags[Flag]): pass
75
-
73
+ class Flags(BaseFlags[Flag]):
74
+ pass
76
75
 
77
- class InputFlags(BaseFlags[InputFlag]): pass
78
76
 
77
+ class InputFlags(BaseFlags[InputFlag]):
78
+ pass
79
79
 
80
- class ValidInputFlags(InputFlags): pass
81
80
 
81
+ class ValidInputFlags(InputFlags):
82
+ pass
82
83
 
83
- class UndefinedInputFlags(InputFlags): pass
84
84
 
85
+ class UndefinedInputFlags(InputFlags):
86
+ pass
85
87
 
86
- class InvalidValueInputFlags(InputFlags): pass
87
88
 
89
+ class InvalidValueInputFlags(InputFlags):
90
+ pass
argenta/command/models.py CHANGED
@@ -1,12 +1,14 @@
1
1
  from argenta.command.flag.models import Flag, InputFlag
2
2
  from argenta.command.flags.models import InputFlags, Flags
3
- from argenta.command.exceptions import (UnprocessedInputFlagException,
4
- RepeatedInputFlagsException,
5
- EmptyInputCommandException)
3
+ from argenta.command.exceptions import (
4
+ UnprocessedInputFlagException,
5
+ RepeatedInputFlagsException,
6
+ EmptyInputCommandException,
7
+ )
6
8
  from typing import Generic, TypeVar, cast, Literal
7
9
 
8
10
 
9
- InputCommandType = TypeVar('InputCommandType')
11
+ InputCommandType = TypeVar("InputCommandType")
10
12
 
11
13
 
12
14
  class BaseCommand:
@@ -26,10 +28,13 @@ class BaseCommand:
26
28
 
27
29
 
28
30
  class Command(BaseCommand):
29
- def __init__(self, trigger: str,
30
- description: str = None,
31
- flags: Flag | Flags = None,
32
- aliases: list[str] = None):
31
+ def __init__(
32
+ self,
33
+ trigger: str,
34
+ description: str = None,
35
+ flags: Flag | Flags = None,
36
+ aliases: list[str] = None,
37
+ ):
33
38
  """
34
39
  Public. The command that can and should be registered in the Router
35
40
  :param trigger: A string trigger, which, when entered by the user, indicates that the input corresponds to the command
@@ -38,8 +43,14 @@ class Command(BaseCommand):
38
43
  :param aliases: string synonyms for the main trigger
39
44
  """
40
45
  super().__init__(trigger)
41
- self._registered_flags: Flags = flags if isinstance(flags, Flags) else Flags(flags) if isinstance(flags, Flag) else Flags()
42
- self._description = f'Very useful command' if not description else description
46
+ self._registered_flags: Flags = (
47
+ flags
48
+ if isinstance(flags, Flags)
49
+ else Flags(flags)
50
+ if isinstance(flags, Flag)
51
+ else Flags()
52
+ )
53
+ self._description = "Very useful command" if not description else description
43
54
  self._aliases = aliases if isinstance(aliases, list) else []
44
55
 
45
56
  def get_registered_flags(self) -> Flags:
@@ -56,7 +67,9 @@ class Command(BaseCommand):
56
67
  """
57
68
  return self._aliases
58
69
 
59
- def validate_input_flag(self, flag: InputFlag) -> Literal['Undefined', 'Valid', 'Invalid']:
70
+ def validate_input_flag(
71
+ self, flag: InputFlag
72
+ ) -> Literal["Undefined", "Valid", "Invalid"]:
60
73
  """
61
74
  Private. Validates the input flag
62
75
  :param flag: input flag for validation
@@ -66,23 +79,27 @@ class Command(BaseCommand):
66
79
  if registered_flags:
67
80
  if isinstance(registered_flags, Flag):
68
81
  if registered_flags.get_string_entity() == flag.get_string_entity():
69
- is_valid = registered_flags.validate_input_flag_value(flag.get_value())
82
+ is_valid = registered_flags.validate_input_flag_value(
83
+ flag.get_value()
84
+ )
70
85
  if is_valid:
71
- return 'Valid'
86
+ return "Valid"
72
87
  else:
73
- return 'Invalid'
88
+ return "Invalid"
74
89
  else:
75
- return 'Undefined'
90
+ return "Undefined"
76
91
  else:
77
92
  for registered_flag in registered_flags:
78
93
  if registered_flag.get_string_entity() == flag.get_string_entity():
79
- is_valid = registered_flag.validate_input_flag_value(flag.get_value())
94
+ is_valid = registered_flag.validate_input_flag_value(
95
+ flag.get_value()
96
+ )
80
97
  if is_valid:
81
- return 'Valid'
98
+ return "Valid"
82
99
  else:
83
- return 'Invalid'
84
- return 'Undefined'
85
- return 'Undefined'
100
+ return "Invalid"
101
+ return "Undefined"
102
+ return "Undefined"
86
103
 
87
104
  def get_description(self) -> str:
88
105
  """
@@ -92,10 +109,8 @@ class Command(BaseCommand):
92
109
  return self._description
93
110
 
94
111
 
95
-
96
112
  class InputCommand(BaseCommand, Generic[InputCommandType]):
97
- def __init__(self, trigger: str,
98
- input_flags: InputFlag | InputFlags = None):
113
+ def __init__(self, trigger: str, input_flags: InputFlag | InputFlags = None):
99
114
  """
100
115
  Private. The model of the input command, after parsing
101
116
  :param trigger:the trigger of the command
@@ -103,7 +118,13 @@ class InputCommand(BaseCommand, Generic[InputCommandType]):
103
118
  :return: None
104
119
  """
105
120
  super().__init__(trigger)
106
- self._input_flags: InputFlags = input_flags if isinstance(input_flags, InputFlags) else InputFlags(input_flags) if isinstance(input_flags, InputFlag) else InputFlags()
121
+ self._input_flags: InputFlags = (
122
+ input_flags
123
+ if isinstance(input_flags, InputFlags)
124
+ else InputFlags(input_flags)
125
+ if isinstance(input_flags, InputFlag)
126
+ else InputFlags()
127
+ )
107
128
 
108
129
  def _set_input_flags(self, input_flags: InputFlags) -> None:
109
130
  """
@@ -120,7 +141,6 @@ class InputCommand(BaseCommand, Generic[InputCommandType]):
120
141
  """
121
142
  return self._input_flags
122
143
 
123
-
124
144
  @staticmethod
125
145
  def parse(raw_command: str) -> InputCommandType:
126
146
  """
@@ -138,8 +158,8 @@ class InputCommand(BaseCommand, Generic[InputCommandType]):
138
158
  current_flag_name, current_flag_value = None, None
139
159
 
140
160
  for k, _ in enumerate(list_of_tokens):
141
- if _.startswith('-'):
142
- if len(_) < 2 or len(_[:_.rfind('-')]) > 3:
161
+ if _.startswith("-"):
162
+ if len(_) < 2 or len(_[: _.rfind("-")]) > 3:
143
163
  raise UnprocessedInputFlagException()
144
164
  current_flag_name = _
145
165
  else:
@@ -148,16 +168,22 @@ class InputCommand(BaseCommand, Generic[InputCommandType]):
148
168
  current_flag_value = _
149
169
 
150
170
  if current_flag_name:
151
- if not len(list_of_tokens) == k+1:
152
- if not list_of_tokens[k+1].startswith('-'):
171
+ if not len(list_of_tokens) == k + 1:
172
+ if not list_of_tokens[k + 1].startswith("-"):
153
173
  continue
154
174
 
155
- input_flag = InputFlag(name=current_flag_name[current_flag_name.rfind('-') + 1:],
156
- prefix=cast(Literal['-', '--', '---'],
157
- current_flag_name[:current_flag_name.rfind('-')+1]),
158
- value=current_flag_value)
159
-
160
- all_flags = [flag.get_string_entity() for flag in input_flags.get_flags()]
175
+ input_flag = InputFlag(
176
+ name=current_flag_name[current_flag_name.rfind("-") + 1 :],
177
+ prefix=cast(
178
+ Literal["-", "--", "---"],
179
+ current_flag_name[: current_flag_name.rfind("-") + 1],
180
+ ),
181
+ value=current_flag_value,
182
+ )
183
+
184
+ all_flags = [
185
+ flag.get_string_entity() for flag in input_flags.get_flags()
186
+ ]
161
187
  if input_flag.get_string_entity() not in all_flags:
162
188
  input_flags.add_flag(input_flag)
163
189
  else:
@@ -169,4 +195,3 @@ class InputCommand(BaseCommand, Generic[InputCommandType]):
169
195
  raise UnprocessedInputFlagException()
170
196
  else:
171
197
  return InputCommand(trigger=command, input_flags=input_flags)
172
-
@@ -1,4 +1,4 @@
1
1
  __all__ = ["ArgParser"]
2
2
 
3
3
 
4
- from argenta.orchestrator.argparser.entity import ArgParser
4
+ from argenta.orchestrator.argparser.entity import ArgParser
@@ -1,6 +1,8 @@
1
1
  __all__ = ["BooleanArgument", "PositionalArgument", "OptionalArgument"]
2
2
 
3
3
 
4
- from argenta.orchestrator.argparser.arguments.models import (BooleanArgument,
5
- PositionalArgument,
6
- OptionalArgument)
4
+ from argenta.orchestrator.argparser.arguments.models import (
5
+ BooleanArgument,
6
+ PositionalArgument,
7
+ OptionalArgument,
8
+ )
@@ -6,6 +6,7 @@ class BaseArgument(ABC):
6
6
  """
7
7
  Private. Base class for all arguments
8
8
  """
9
+
9
10
  @abstractmethod
10
11
  def get_string_entity(self) -> str:
11
12
  """
@@ -28,7 +29,7 @@ class PositionalArgument(BaseArgument):
28
29
 
29
30
 
30
31
  class OptionalArgument(BaseArgument):
31
- def __init__(self, name: str, prefix: Literal['-', '--', '---'] = '--'):
32
+ def __init__(self, name: str, prefix: Literal["-", "--", "---"] = "--"):
32
33
  """
33
34
  Public. Optional argument, must have the value
34
35
  :param name: name of the argument
@@ -42,7 +43,7 @@ class OptionalArgument(BaseArgument):
42
43
 
43
44
 
44
45
  class BooleanArgument(BaseArgument):
45
- def __init__(self, name: str, prefix: Literal['-', '--', '---'] = '--'):
46
+ def __init__(self, name: str, prefix: Literal["-", "--", "---"] = "--"):
46
47
  """
47
48
  Public. Boolean argument, does not require a value
48
49
  :param name: name of the argument
@@ -1,16 +1,20 @@
1
1
  from argparse import ArgumentParser
2
2
 
3
- from argenta.orchestrator.argparser.arguments.models import (BooleanArgument,
4
- OptionalArgument,
5
- PositionalArgument)
3
+ from argenta.orchestrator.argparser.arguments.models import (
4
+ BooleanArgument,
5
+ OptionalArgument,
6
+ PositionalArgument,
7
+ )
6
8
 
7
9
 
8
10
  class ArgParser:
9
- def __init__(self,
10
- processed_args: list[PositionalArgument | OptionalArgument | BooleanArgument],
11
- name: str = 'Argenta',
12
- description: str = 'Argenta available arguments',
13
- epilog: str = 'github.com/koloideal/Argenta | made by kolo') -> None:
11
+ def __init__(
12
+ self,
13
+ processed_args: list[PositionalArgument | OptionalArgument | BooleanArgument],
14
+ name: str = "Argenta",
15
+ description: str = "Argenta available arguments",
16
+ epilog: str = "github.com/koloideal/Argenta | made by kolo",
17
+ ) -> None:
14
18
  """
15
19
  Public. Cmd argument parser and configurator at startup
16
20
  :param name: the name of the ArgParse instance
@@ -22,10 +26,16 @@ class ArgParser:
22
26
  self.description = description
23
27
  self.epilog = epilog
24
28
 
25
- self.entity: ArgumentParser = ArgumentParser(prog=name, description=description, epilog=epilog)
26
- self.args: list[PositionalArgument | OptionalArgument | BooleanArgument] | None = processed_args
29
+ self.entity: ArgumentParser = ArgumentParser(
30
+ prog=name, description=description, epilog=epilog
31
+ )
32
+ self.args: (
33
+ list[PositionalArgument | OptionalArgument | BooleanArgument] | None
34
+ ) = processed_args
27
35
 
28
- def set_args(self, *args: PositionalArgument | OptionalArgument | BooleanArgument) -> None:
36
+ def set_args(
37
+ self, *args: PositionalArgument | OptionalArgument | BooleanArgument
38
+ ) -> None:
29
39
  """
30
40
  Public. Sets the arguments to be processed
31
41
  :param args: processed arguments
@@ -46,4 +56,4 @@ class ArgParser:
46
56
  elif type(arg) is OptionalArgument:
47
57
  self.entity.add_argument(arg.get_string_entity())
48
58
  elif type(arg) is BooleanArgument:
49
- self.entity.add_argument(arg.get_string_entity(), action='store_true')
59
+ self.entity.add_argument(arg.get_string_entity(), action="store_true")
@@ -33,4 +33,3 @@ class Orchestrator:
33
33
  return self.arg_parser.entity.parse_args()
34
34
  else:
35
35
  return None
36
-
@@ -1,19 +1,21 @@
1
1
  from argenta.response.status import Status
2
- from argenta.command.flags import (ValidInputFlags,
3
- UndefinedInputFlags,
4
- InvalidValueInputFlags)
2
+ from argenta.command.flags import (
3
+ ValidInputFlags,
4
+ UndefinedInputFlags,
5
+ InvalidValueInputFlags,
6
+ )
5
7
 
6
8
 
7
9
  class Response:
8
- __slots__ = ('status',
9
- 'valid_flags',
10
- 'undefined_flags',
11
- 'invalid_value_flags')
10
+ __slots__ = ("status", "valid_flags", "undefined_flags", "invalid_value_flags")
12
11
 
13
- def __init__(self, status: Status = None,
14
- valid_flags: ValidInputFlags = ValidInputFlags(),
15
- undefined_flags: UndefinedInputFlags = UndefinedInputFlags(),
16
- invalid_value_flags: InvalidValueInputFlags = InvalidValueInputFlags()):
12
+ def __init__(
13
+ self,
14
+ status: Status = None,
15
+ valid_flags: ValidInputFlags = ValidInputFlags(),
16
+ undefined_flags: UndefinedInputFlags = UndefinedInputFlags(),
17
+ invalid_value_flags: InvalidValueInputFlags = InvalidValueInputFlags(),
18
+ ):
17
19
  """
18
20
  Public. The entity of the user input sent to the handler
19
21
  :param status: the status of the response
@@ -2,8 +2,7 @@ from enum import Enum
2
2
 
3
3
 
4
4
  class Status(Enum):
5
- ALL_FLAGS_VALID = 'ALL_FLAGS_VALID'
6
- UNDEFINED_FLAGS = 'UNDEFINED_FLAGS'
7
- INVALID_VALUE_FLAGS = 'INVALID_VALUE_FLAGS'
8
- UNDEFINED_AND_INVALID_FLAGS = 'UNDEFINED_AND_INVALID_FLAGS'
9
-
5
+ ALL_FLAGS_VALID = "ALL_FLAGS_VALID"
6
+ UNDEFINED_FLAGS = "UNDEFINED_FLAGS"
7
+ INVALID_VALUE_FLAGS = "INVALID_VALUE_FLAGS"
8
+ UNDEFINED_AND_INVALID_FLAGS = "UNDEFINED_AND_INVALID_FLAGS"
@@ -1,4 +1,4 @@
1
1
  __all__ = ["Router"]
2
2
 
3
3
 
4
- from argenta.router.entity import Router
4
+ from argenta.router.entity import Router
@@ -64,4 +64,4 @@ class CommandHandlers:
64
64
  return iter(self.command_handlers)
65
65
 
66
66
  def __next__(self) -> CommandHandler:
67
- return next(iter(self.command_handlers))
67
+ return next(iter(self.command_handlers))
@@ -1,4 +1,4 @@
1
1
  from argenta.router import Router
2
2
 
3
3
 
4
- system_router = Router(title='System points:')
4
+ system_router = Router(title="System points:")