xmipp3-installer 1.0.0__py3-none-any.whl → 1.1.0__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.
Files changed (60) hide show
  1. xmipp3_installer/__main__.py +1 -1
  2. xmipp3_installer/api_client/api_client.py +35 -34
  3. xmipp3_installer/api_client/assembler/installation_info_assembler.py +140 -145
  4. xmipp3_installer/application/cli/arguments/__init__.py +3 -2
  5. xmipp3_installer/application/cli/arguments/modes.py +112 -95
  6. xmipp3_installer/application/cli/arguments/params.py +63 -53
  7. xmipp3_installer/application/cli/cli.py +171 -190
  8. xmipp3_installer/application/cli/parsers/base_help_formatter.py +256 -235
  9. xmipp3_installer/application/cli/parsers/error_handler_parser.py +53 -53
  10. xmipp3_installer/application/cli/parsers/format.py +22 -22
  11. xmipp3_installer/application/cli/parsers/general_help_formatter.py +102 -84
  12. xmipp3_installer/application/cli/parsers/mode_help_formatter.py +144 -105
  13. xmipp3_installer/application/logger/__init__.py +5 -0
  14. xmipp3_installer/application/logger/errors.py +8 -8
  15. xmipp3_installer/application/logger/logger.py +218 -215
  16. xmipp3_installer/application/logger/predefined_messages.py +42 -35
  17. xmipp3_installer/application/user_interactions.py +6 -0
  18. xmipp3_installer/installer/constants/paths.py +6 -1
  19. xmipp3_installer/installer/handlers/cmake/cmake_handler.py +49 -53
  20. xmipp3_installer/installer/handlers/conda_handler.py +6 -6
  21. xmipp3_installer/installer/handlers/generic_package_handler.py +9 -9
  22. xmipp3_installer/installer/handlers/git_handler.py +152 -153
  23. xmipp3_installer/installer/handlers/shell_handler.py +87 -88
  24. xmipp3_installer/installer/handlers/versions_manager.py +20 -6
  25. xmipp3_installer/installer/installer_service.py +22 -8
  26. xmipp3_installer/installer/modes/mode_all_executor.py +61 -51
  27. xmipp3_installer/installer/modes/mode_clean/mode_clean_all_executor.py +44 -36
  28. xmipp3_installer/installer/modes/mode_clean/mode_clean_bin_executor.py +84 -74
  29. xmipp3_installer/installer/modes/mode_clean/mode_clean_executor.py +48 -34
  30. xmipp3_installer/installer/modes/mode_cmake/mode_cmake_executor.py +60 -47
  31. xmipp3_installer/installer/modes/mode_cmake/mode_compile_and_install_executor.py +52 -39
  32. xmipp3_installer/installer/modes/mode_cmake/mode_config_build_executor.py +68 -49
  33. xmipp3_installer/installer/modes/mode_config_executor.py +44 -33
  34. xmipp3_installer/installer/modes/mode_executor.py +14 -13
  35. xmipp3_installer/installer/modes/mode_get_sources_executor.py +121 -112
  36. xmipp3_installer/installer/modes/mode_git_executor.py +43 -31
  37. xmipp3_installer/installer/modes/mode_selector.py +6 -0
  38. xmipp3_installer/installer/modes/mode_sync/mode_add_model_executor.py +97 -83
  39. xmipp3_installer/installer/modes/mode_sync/mode_get_models_executor.py +53 -41
  40. xmipp3_installer/installer/modes/mode_sync/mode_sync_executor.py +41 -35
  41. xmipp3_installer/installer/modes/mode_sync/mode_test_executor.py +144 -77
  42. xmipp3_installer/installer/modes/mode_version_executor.py +161 -150
  43. xmipp3_installer/installer/orquestrator.py +24 -24
  44. xmipp3_installer/installer/urls.py +4 -3
  45. xmipp3_installer/repository/config.py +225 -227
  46. xmipp3_installer/repository/config_vars/__init__.py +5 -0
  47. xmipp3_installer/repository/config_vars/config_values_adapter.py +97 -91
  48. xmipp3_installer/repository/config_vars/default_values.py +24 -24
  49. xmipp3_installer/repository/config_vars/variables.py +9 -9
  50. xmipp3_installer/repository/invalid_config_line.py +17 -0
  51. xmipp3_installer/shared/file_operations.py +14 -12
  52. xmipp3_installer/shared/singleton.py +16 -17
  53. xmipp3_installer-1.1.0.dist-info/METADATA +86 -0
  54. xmipp3_installer-1.1.0.dist-info/RECORD +70 -0
  55. {xmipp3_installer-1.0.0.dist-info → xmipp3_installer-1.1.0.dist-info}/WHEEL +1 -1
  56. xmipp3_installer-1.0.0.dist-info/METADATA +0 -729
  57. xmipp3_installer-1.0.0.dist-info/RECORD +0 -70
  58. {xmipp3_installer-1.0.0.dist-info → xmipp3_installer-1.1.0.dist-info}/entry_points.txt +0 -0
  59. /xmipp3_installer-1.0.0.dist-info/LICENSE → /xmipp3_installer-1.1.0.dist-info/licenses/LICENSE.txt +0 -0
  60. {xmipp3_installer-1.0.0.dist-info → xmipp3_installer-1.1.0.dist-info}/top_level.txt +0 -0
@@ -2,243 +2,264 @@
2
2
 
3
3
  import argparse
4
4
  import shutil
5
- from typing import List, Tuple
5
+ from typing import List, Tuple, Union
6
6
 
7
7
  from xmipp3_installer.application.cli.arguments import modes, params
8
8
  from xmipp3_installer.application.cli.parsers import format
9
9
 
10
10
  class BaseHelpFormatter(argparse.HelpFormatter):
11
- """
12
- ### Extendes the available functions of the generic help formatter.
13
- """
14
- __SECTION_N_DASH = 45
15
- __SECTION_SPACE_MODE_HELP = 2
16
- __SECTION_HELP_START = format.TAB_SIZE + __SECTION_N_DASH + __SECTION_SPACE_MODE_HELP
17
- __LINE_SIZE_LOWER_LIMIT = int(__SECTION_HELP_START * 1.5)
18
-
19
- def _get_mode_help(self, mode: str, general: bool=True) -> str:
20
- """
21
- ### Returns the help message of a given mode.
22
-
23
- ### Params:
24
- - mode (str): Mode to get help text for.
25
- - general (bool). Optional. If True, only the general help message is displayed.
26
-
27
- ### Returns:
28
- - (str): Help of the mode (empty if mode not found).
29
- """
30
- for group in list(modes.MODES.keys()):
31
- if mode in list(modes.MODES[group].keys()):
32
- messages = modes.MODES[group][mode]
33
- return self.__get_message_from_list(messages, general)
34
- return ''
35
-
36
- def _get_param_first_name(self, param_key: str) -> str:
37
- """
38
- ### Returns the first name of the given param key. Short name has priority over long name.
39
-
40
- ### Params:
41
- - param_key (str): Key to identify the param.
42
-
43
- ### Returns:
44
- - (str): Formatted text.
45
- """
46
- param = params.PARAMS[param_key]
47
- return param.get(params.SHORT_VERSION, param.get(params.LONG_VERSION, ''))
48
-
49
- def _get_help_separator(self) -> str:
50
- """
51
- ### Returns the line that separates sections inside the help message.
52
-
53
- ### Returns:
54
- - (str): Line that separates sections inside the help message.
55
- """
56
- dashes = ['-' for _ in range(self.__SECTION_N_DASH)]
57
- return format.get_formatting_tabs(f"\t{''.join(dashes)}\n")
58
-
59
- def _text_with_limits(self, previous_text: str, text: str) -> str:
60
- """
61
- ### Returns the given text, formatted so that it does not exceed the character limit by line for the param help section.
62
-
63
- ### Params:
64
- - previous_text (str): Text inserted before the one to be returned.
65
- - text (str): The text to be formatted.
66
-
67
- ### Returns:
68
- - (str): Formatted text.
69
- """
70
- remaining_space, fill_in_space = self.__get_spaces(previous_text)
71
- formatted_help = self.__multi_line_help_text(
72
- text,
73
- remaining_space,
74
- self.__get_start_section_fill_in_space('')
75
- )
76
- return f"{previous_text}{fill_in_space}{formatted_help}\n"
77
-
78
- def _get_text_length(self, text: str) -> int:
79
- """
80
- ### Returns the length of a text that might contain tabs.
81
-
82
- #### Params:
83
- - text (str): Text to measure.
84
-
85
- #### Returns:
86
- - (int): Text's length.
87
- """
88
- return len(format.get_formatting_tabs(text))
89
-
90
- def __get_message_from_list(self, messages: List[str], only_general: bool) -> str:
91
- """
92
- ### Return the appropiate message given a list of them and a condition.
93
-
94
- #### Params:
95
- - messages (list[str]): List of messages.
96
- - only_general (bool): If True, only the general (first) message is returned.
97
-
98
- #### Returns:
99
- - (str): Expected messages in a string.
100
- """
101
- return messages[0] if only_general else '\n'.join(messages)
102
-
103
- def __get_line_size(self) -> int:
104
- """
105
- ### Returns the maximum size for a line.
106
-
107
- ### Returns:
108
- - (int): Maximum line size.
109
- """
110
- size = shutil.get_terminal_size().columns
111
- return self.__LINE_SIZE_LOWER_LIMIT if size < self.__LINE_SIZE_LOWER_LIMIT else size
112
-
113
- def __multi_line_help_text(self, text: str, size_limit: int, left_fill: str) -> str:
114
- """
115
- ### This function returns the given text, formatted in several lines so that it does not exceed the given character limit.
116
-
117
- ### Params:
118
- - text (str): The text to be formatted.
119
- - size_limit (int): Size limit for the text.
120
- - left_fill (str): String to add at the left of each new line.
121
-
122
- ### Returns:
123
- - (str): Formatted text.
124
- """
125
- return (
126
- text
127
- if len(text) <= size_limit else
128
- self.__format_text_in_lines(text, size_limit, left_fill)
129
- )
130
-
131
- def __fit_words_in_line(self, words: List[str], size_limit: int) -> Tuple[str, List[str]]:
132
- """
133
- ### Returns a tuple containig a line with the words from the given list that could fit given the size limit, and the list with the remaining words.
134
-
135
- ### Params:
136
- - words (list[str]): List of words to try to fit into a line.
137
- - size_limit (int): Size limit for the text.
138
-
139
- ### Returns:
140
- - (str): Line with the words that were able to fit in it.
141
- - (list[str]): List containing the words that could not fit in the line.
142
- """
143
- line = ''
144
- remaining_words = words
145
- for word in words:
146
- if self.__word_fits_in_line(line, word, size_limit):
147
- line, remaining_words = self.__add_word_to_line(line, word, remaining_words)
148
- else:
149
- break
150
- return line, remaining_words
151
-
152
- def __word_fits_in_line(self, line: str, word: str, size_limit: int) -> bool:
153
- """
154
- ### Checks if a word can fit in the current line without exceeding the size limit.
155
-
156
- ### Params:
157
- - line (str): The current line of text.
158
- - word (str): The word to check.
159
- - size_limit (int): The maximum allowed size for the line.
160
-
161
- ### Returns:
162
- - (bool): True if the word fits in the line, False otherwise.
163
- """
164
- if line:
165
- return len(f"{line} {word}") <= size_limit
166
- return len(word) <= size_limit
167
-
168
- def __add_word_to_line(self, line: str, word: str, remaining_words: List[str]) -> Tuple[str, List[str]]:
169
- """
170
- ### Adds a word to the current line and updates the list of remaining words.
171
-
172
- ### Params:
173
- - line (str): The current line of text.
174
- - word (str): The word to add to the line.
175
- - remaining_words (list[str]): The list of words yet to be added to the line.
176
-
177
- ### Returns:
178
- - (str): The updated line with the new word added.
179
- - (list[str]): The updated list of remaining words.
180
- """
181
- if line:
182
- line += f" {word}"
183
- else:
184
- line = word
185
- return line, remaining_words[1:]
186
-
187
- def __format_text_in_lines(self, text: str, size_limit: int, left_fill: str):
188
- """
189
- ### Returns the text formatted into size-limited lines.
190
-
191
- #### Params:
192
- - text (str): Text to format.
193
- - size_limit (int): Max number of characters allowed in a single line.
194
- - left_fill (str): Starting characters of each line.
195
-
196
- #### Returns:
197
- - (str): Text formatted into lines.
198
- """
199
- words = text.split(' ')
200
- lines = []
201
- while words:
202
- iteration_size_limit = size_limit if size_limit >= len(words[0]) else len(words[0])
203
- line, words = self.__fit_words_in_line(words, iteration_size_limit)
204
- line = left_fill + line if lines else line
205
- lines.append(line)
206
- return '\n'.join(lines)
207
-
208
- def __get_spaces(self, start_section_text: str) -> Tuple[str, str]:
209
- if self.__is_start_section_text_exceeding_size_limit(start_section_text):
210
- # If text exceeds size limit, it means that section space for modes and params
211
- # is too low and should be set to a higher number, but for now we need to print anyways,
212
- # so we reduce space from the one reserved for mode help and add minimum fill-in space
213
- remaining_space = self.__get_line_size() - self._get_text_length(start_section_text)
214
- fill_in_space = ' '
215
- else:
216
- remaining_space = self.__get_line_size() - self.__SECTION_HELP_START
217
- fill_in_space = self.__get_start_section_fill_in_space(start_section_text)
218
- return remaining_space, fill_in_space
219
-
220
- def __get_start_section_fill_in_space(self, text: str) -> str:
221
- """
222
- ### Returns the fill-in space for the start section.
223
-
224
- #### Params:
225
- - text (str): Text inside the start section.
226
-
227
- #### Returns:
228
- - (str): The required number of spaces to generate the start section's fill-in.
229
- """
230
- return ''.join(
231
- [' ' for _ in range(self.__SECTION_HELP_START - self._get_text_length(text))]
232
- )
233
-
234
- def __is_start_section_text_exceeding_size_limit(self, start_section_text: str) -> bool:
235
- """
236
- ### Indicates if the given start section text exceedes allowed size limit.
237
-
238
- #### Params:
239
- - start_section_text (str): Text to measure.
240
-
241
- #### Returns:
242
- - (bool): True if the text exceedes allowed size limit.
243
- """
244
- return self._get_text_length(start_section_text) >= self.__SECTION_HELP_START
11
+ """### Extendes the available functions of the generic help formatter."""
12
+
13
+ __SECTION_N_DASH = 68
14
+ __SECTION_SPACE_MODE_HELP = 2
15
+ __SECTION_HELP_START = format.TAB_SIZE + __SECTION_N_DASH + __SECTION_SPACE_MODE_HELP
16
+ __LINE_SIZE_LOWER_LIMIT = int(__SECTION_HELP_START * 1.5)
17
+
18
+ @staticmethod
19
+ def _get_mode_help(mode: str, general: bool=True) -> str:
20
+ """
21
+ ### Returns the help message of a given mode.
22
+
23
+ ### Params:
24
+ - mode (str): Mode to get help text for.
25
+ - general (bool). Optional. If True, only the general help message is displayed.
26
+
27
+ ### Returns:
28
+ - (str): Help of the mode (empty if mode not found).
29
+ """
30
+ for group in modes.MODES.keys():
31
+ if mode in modes.MODES[group].keys():
32
+ messages = modes.MODES[group][mode]
33
+ return BaseHelpFormatter.__get_message_from_list(messages, general)
34
+ return ''
35
+
36
+ @staticmethod
37
+ def _get_param_first_name(param_key: str) -> str:
38
+ """
39
+ ### Returns the first name of the given param key. Short name has priority over long name.
40
+
41
+ ### Params:
42
+ - param_key (str): Key to identify the param.
43
+
44
+ ### Returns:
45
+ - (str): Formatted text.
46
+ """
47
+ param = params.PARAMS[param_key]
48
+ return param.get(params.SHORT_VERSION, param.get(params.LONG_VERSION, ''))
49
+
50
+ def _get_help_separator(self) -> str:
51
+ """
52
+ ### Returns the line that separates sections inside the help message.
53
+
54
+ ### Returns:
55
+ - (str): Line that separates sections inside the help message.
56
+ """
57
+ dashes = ['-' for _ in range(self.__SECTION_N_DASH)]
58
+ return format.get_formatting_tabs(f"\t{''.join(dashes)}\n")
59
+
60
+ def _text_with_limits(self, previous_text: str, text: str) -> str:
61
+ """
62
+ ### Returns the given text, formatted so that it does not exceed the character limit by line for the param help section.
63
+
64
+ ### Params:
65
+ - previous_text (str): Text inserted before the one to be returned.
66
+ - text (str): The text to be formatted.
67
+
68
+ ### Returns:
69
+ - (str): Formatted text.
70
+ """
71
+ remaining_space, fill_in_space = self.__get_spaces(previous_text)
72
+ formatted_help = BaseHelpFormatter.__multi_line_help_text(
73
+ text,
74
+ remaining_space,
75
+ self.__get_start_section_fill_in_space('')
76
+ )
77
+ return f"{previous_text}{fill_in_space}{formatted_help}\n"
78
+
79
+ @staticmethod
80
+ def _has_mutually_exclusive_groups(arg_list: List[Union[str, List[str]]]) -> bool:
81
+ """
82
+ ### Checks if the param list provided contains mutually exclusive groups.
83
+
84
+ ### Params:
85
+ - arg_list (list[str | list[str]]): List of arguments, which can be strings or lists of strings.
86
+
87
+ ### Returns:
88
+ - (bool): True if all elements in the list are strings, False otherwise.
89
+ """
90
+ return any(isinstance(arg, list) for arg in arg_list)
91
+
92
+ @staticmethod
93
+ def __get_text_length(text: str) -> int:
94
+ """
95
+ ### Returns the length of a text that might contain tabs.
96
+
97
+ #### Params:
98
+ - text (str): Text to measure.
99
+
100
+ #### Returns:
101
+ - (int): Text's length.
102
+ """
103
+ return len(format.get_formatting_tabs(text))
104
+
105
+ @staticmethod
106
+ def __get_message_from_list(messages: List[str], only_general: bool) -> str:
107
+ """
108
+ ### Return the appropiate message given a list of them and a condition.
109
+
110
+ #### Params:
111
+ - messages (list[str]): List of messages.
112
+ - only_general (bool): If True, only the general (first) message is returned.
113
+
114
+ #### Returns:
115
+ - (str): Expected messages in a string.
116
+ """
117
+ return messages[0] if only_general else '\n'.join(messages)
118
+
119
+ def __get_line_size(self) -> int:
120
+ """
121
+ ### Returns the maximum size for a line.
122
+
123
+ ### Returns:
124
+ - (int): Maximum line size.
125
+ """
126
+ size = shutil.get_terminal_size().columns
127
+ return self.__LINE_SIZE_LOWER_LIMIT if size < self.__LINE_SIZE_LOWER_LIMIT else size
128
+
129
+ @staticmethod
130
+ def __multi_line_help_text(text: str, size_limit: int, left_fill: str) -> str:
131
+ """
132
+ ### This function returns the given text, formatted in several lines so that it does not exceed the given character limit.
133
+
134
+ ### Params:
135
+ - text (str): The text to be formatted.
136
+ - size_limit (int): Size limit for the text.
137
+ - left_fill (str): String to add at the left of each new line.
138
+
139
+ ### Returns:
140
+ - (str): Formatted text.
141
+ """
142
+ return (
143
+ text
144
+ if len(text) <= size_limit else
145
+ BaseHelpFormatter.__format_text_in_lines(text, size_limit, left_fill)
146
+ )
147
+
148
+ @staticmethod
149
+ def __fit_words_in_line(words: List[str], size_limit: int) -> Tuple[str, List[str]]:
150
+ """
151
+ ### Returns a tuple containig a line with the words from the given list that could fit given the size limit, and the list with the remaining words.
152
+
153
+ ### Params:
154
+ - words (list[str]): List of words to try to fit into a line.
155
+ - size_limit (int): Size limit for the text.
156
+
157
+ ### Returns:
158
+ - (str): Line with the words that were able to fit in it.
159
+ - (list[str]): List containing the words that could not fit in the line.
160
+ """
161
+ line = ''
162
+ remaining_words = words
163
+ for word in words:
164
+ if BaseHelpFormatter.__word_fits_in_line(line, word, size_limit):
165
+ line, remaining_words = BaseHelpFormatter.__add_word_to_line(line, word, remaining_words)
166
+ else:
167
+ break
168
+ return line, remaining_words
169
+
170
+ @staticmethod
171
+ def __word_fits_in_line(line: str, word: str, size_limit: int) -> bool:
172
+ """
173
+ ### Checks if a word can fit in the current line without exceeding the size limit.
174
+
175
+ ### Params:
176
+ - line (str): The current line of text.
177
+ - word (str): The word to check.
178
+ - size_limit (int): The maximum allowed size for the line.
179
+
180
+ ### Returns:
181
+ - (bool): True if the word fits in the line, False otherwise.
182
+ """
183
+ if line:
184
+ return len(f"{line} {word}") <= size_limit
185
+ return len(word) <= size_limit
186
+
187
+ @staticmethod
188
+ def __add_word_to_line(line: str, word: str, remaining_words: List[str]) -> Tuple[str, List[str]]:
189
+ """
190
+ ### Adds a word to the current line and updates the list of remaining words.
191
+
192
+ ### Params:
193
+ - line (str): The current line of text.
194
+ - word (str): The word to add to the line.
195
+ - remaining_words (list[str]): The list of words yet to be added to the line.
196
+
197
+ ### Returns:
198
+ - (str): The updated line with the new word added.
199
+ - (list[str]): The updated list of remaining words.
200
+ """
201
+ if line:
202
+ line += f" {word}"
203
+ else:
204
+ line = word
205
+ return line, remaining_words[1:]
206
+
207
+ @staticmethod
208
+ def __format_text_in_lines(text: str, size_limit: int, left_fill: str):
209
+ """
210
+ ### Returns the text formatted into size-limited lines.
211
+
212
+ #### Params:
213
+ - text (str): Text to format.
214
+ - size_limit (int): Max number of characters allowed in a single line.
215
+ - left_fill (str): Starting characters of each line.
216
+
217
+ #### Returns:
218
+ - (str): Text formatted into lines.
219
+ """
220
+ words = text.split(' ')
221
+ lines = []
222
+ while words:
223
+ iteration_size_limit = size_limit if size_limit >= len(words[0]) else len(words[0])
224
+ line, words = BaseHelpFormatter.__fit_words_in_line(words, iteration_size_limit)
225
+ line = left_fill + line if lines else line
226
+ lines.append(line)
227
+ return '\n'.join(lines)
228
+
229
+ def __get_spaces(self, start_section_text: str) -> Tuple[int, str]:
230
+ if self.__is_start_section_text_exceeding_size_limit(start_section_text):
231
+ # If text exceeds size limit, it means that section space for modes and params
232
+ # is too low and should be set to a higher number, but for now we need to print anyways,
233
+ # so we reduce space from the one reserved for mode help and add minimum fill-in space
234
+ remaining_space = self.__get_line_size() - BaseHelpFormatter.__get_text_length(start_section_text)
235
+ fill_in_space = ' '
236
+ else:
237
+ remaining_space = self.__get_line_size() - self.__SECTION_HELP_START
238
+ fill_in_space = self.__get_start_section_fill_in_space(start_section_text)
239
+ return remaining_space, fill_in_space
240
+
241
+ def __get_start_section_fill_in_space(self, text: str) -> str:
242
+ """
243
+ ### Returns the fill-in space for the start section.
244
+
245
+ #### Params:
246
+ - text (str): Text inside the start section.
247
+
248
+ #### Returns:
249
+ - (str): The required number of spaces to generate the start section's fill-in.
250
+ """
251
+ return ''.join(
252
+ [' ' for _ in range(self.__SECTION_HELP_START - BaseHelpFormatter.__get_text_length(text))]
253
+ )
254
+
255
+ def __is_start_section_text_exceeding_size_limit(self, start_section_text: str) -> bool:
256
+ """
257
+ ### Indicates if the given start section text exceedes allowed size limit.
258
+
259
+ #### Params:
260
+ - start_section_text (str): Text to measure.
261
+
262
+ #### Returns:
263
+ - (bool): True if the text exceedes allowed size limit.
264
+ """
265
+ return BaseHelpFormatter.__get_text_length(start_section_text) >= self.__SECTION_HELP_START
@@ -7,62 +7,62 @@ from xmipp3_installer.application.cli.parsers import format
7
7
  from xmipp3_installer.application.logger.logger import logger
8
8
 
9
9
  class ErrorHandlerArgumentParser(argparse.ArgumentParser):
10
- """
11
- Overrides the error function of the standard argument parser
12
- to display better error messages.
13
- """
14
- def error(self, message):
15
- """
16
- ### Prints through stderr the error message and exits with specific return code.
17
-
18
- #### Params:
19
- - message (str): Error message.
20
- """
21
- args = self.__get_args()
22
- mode = self.__get_mode(args)
10
+ """### Overrides the error function of the standard argument parser to display better error messages."""
23
11
 
24
- if self.__is_mode_generic(args):
25
- args = ' '.join(args[:-1])
26
- extra_line_break = '\n'
27
- else:
28
- args = self.format_help()
29
- extra_line_break = ''
12
+ def error(self, message):
13
+ """
14
+ ### Prints through stderr the error message and exits with specific return code.
15
+
16
+ #### Params:
17
+ - message (str): Error message.
18
+ """
19
+ args = self.__get_args()
20
+ mode = ErrorHandlerArgumentParser.__get_mode(args)
30
21
 
31
- error_message = logger.red(f"{mode}: error: {message}\n")
32
- self.exit(
33
- 1,
34
- format.get_formatting_tabs(f"{args}{extra_line_break}{error_message}")
35
- )
36
-
37
- def __get_args(self) -> List[str]:
38
- """
39
- ### Obtains args from stored class data.
22
+ if ErrorHandlerArgumentParser.__is_mode_generic(args):
23
+ args = ' '.join(args[:-1])
24
+ extra_line_break = '\n'
25
+ else:
26
+ args = self.format_help()
27
+ extra_line_break = ''
40
28
 
41
- #### Returns:
42
- - (list[str]): List of arguments.
43
- """
44
- return self.prog.split(' ')
45
-
46
- def __get_mode(self, args: List[str]) -> str:
47
- """
48
- ### Obtains the usage mode from the received args.
29
+ error_message = logger.red(f"{mode}: error: {message}\n")
30
+ self.exit(
31
+ 1,
32
+ format.get_formatting_tabs(f"{args}{extra_line_break}{error_message}")
33
+ )
34
+
35
+ def __get_args(self) -> List[str]:
36
+ """
37
+ ### Obtains args from stored class data.
49
38
 
50
- #### Params:
51
- - args (list[str]): List of args received by the parser.
52
-
53
- #### Returns:
54
- - (str): Usage mode.
55
- """
56
- return args[-1]
57
-
58
- def __is_mode_generic(self, args: List[str]) -> bool:
59
- """
60
- ### Returns True if the usage mode selected is the generic one.
39
+ #### Returns:
40
+ - (list[str]): List of arguments.
41
+ """
42
+ return self.prog.split(' ')
43
+
44
+ @staticmethod
45
+ def __get_mode(args: List[str]) -> str:
46
+ """
47
+ ### Obtains the usage mode from the received args.
61
48
 
62
- #### Params:
63
- - args (list[str]): List of received args.
49
+ #### Params:
50
+ - args (list[str]): List of args received by the parser.
51
+
52
+ #### Returns:
53
+ - (str): Usage mode.
54
+ """
55
+ return args[-1]
56
+
57
+ @staticmethod
58
+ def __is_mode_generic(args: List[str]) -> bool:
59
+ """
60
+ ### Returns True if the usage mode selected is the generic one.
64
61
 
65
- #### Returns:
66
- - (bool): True if the received mode is the generic one.
67
- """
68
- return len(args) > 1
62
+ #### Params:
63
+ - args (list[str]): List of received args.
64
+
65
+ #### Returns:
66
+ - (bool): True if the received mode is the generic one.
67
+ """
68
+ return len(args) > 1