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
@@ -12,230 +12,228 @@ from xmipp3_installer.repository.config_vars import default_values, variables, c
12
12
  from xmipp3_installer.repository.invalid_config_line import InvalidConfigLineError
13
13
 
14
14
  class ConfigurationFileHandler(Singleton):
15
- """
16
- ### Configuration file class for loading and storing the installation configuration.
17
- """
18
- __COMMENT_ESCAPE = '#'
19
- __ASSIGNMENT_SEPARATOR = '='
20
- __LAST_MODIFIED_TEXT = "Config file automatically generated on"
21
-
22
- def __init__(self, path: str=paths.CONFIG_FILE, show_errors: bool=True):
23
- """
24
- ### Constructor.
25
-
26
- #### Params:
27
- - path (str): Optional. Path to the configuration file.
28
- """
29
- self.__path = path
30
- self.show_errors = show_errors
31
- self.values = {}
32
- self.read_config()
33
- self.last_modified = self.__read_config_date()
34
-
35
- def read_config(self):
36
- """
37
- ### Reads the config file and stores a dictionary with all the parsed variables.
38
- """
39
- file_lines = self.__get_file_content()
40
- result = {}
41
- for line_number, line in enumerate(file_lines):
42
- new_result = self.__add_line_values(result.copy(), line, line_number + 1)
43
- if new_result is None:
44
- result = {}
45
- break
46
- result = new_result
47
- self.values = {
48
- **config_values_adapter.get_context_values_from_file_values(
49
- default_values.CONFIG_DEFAULT_VALUES
50
- ),
51
- **config_values_adapter.get_context_values_from_file_values(
52
- result,
53
- show_warnings=self.show_errors
54
- )
55
- }
56
-
57
- def write_config(self, overwrite: bool=False):
58
- """
59
- ### Writes a template config file with stored variables, leaving the rest with default values.
60
-
61
- #### Params:
62
- - overwrite (bool): Optional. If True, default values are written, overwriting the existing file.
63
- """
64
- if overwrite:
65
- self.values = default_values.CONFIG_DEFAULT_VALUES
66
- values = config_values_adapter.get_file_values_from_context_values(self.values.copy())
67
- self.last_modified = datetime.today().strftime('%d-%m-%Y %H:%M.%S')
68
-
69
- lines = ["##### TOGGLE SECTION #####\n"]
70
- lines.append(f"# Activate or deactivate this features using values {default_values.ON}/{default_values.OFF}\n")
71
- lines.extend(self.__get_section_lines(variables.TOGGLES, values))
72
-
73
- lines.append("\n##### PACKAGE HOME SECTION #####\n")
74
- lines.append("# Use this variables to use custom installation paths for the required packages.\n")
75
- lines.append("# If left empty, CMake will search for those packages within your system.\n")
76
- lines.extend(self.__get_section_lines(variables.LOCATIONS, values))
77
-
78
- lines.append("\n##### COMPILATION FLAGS #####\n")
79
- lines.append("# We recommend not modifying this variables unless you know what you are doing.\n")
80
- lines.extend(self.__get_section_lines(variables.COMPILATION_FLAGS, values))
81
-
82
- if values:
83
- lines.append("\n##### UNKNOWN VARIABLES #####\n")
84
- lines.append("# This variables were not expected, but are kept here in case they might be needed.\n")
85
- lines.extend(self.__get_unkown_variable_lines(values))
86
-
87
- lines.append(f"\n# {self.__LAST_MODIFIED_TEXT} {self.last_modified}\n")
88
- with open(self.__path, 'w') as config_file:
89
- config_file.writelines(lines)
90
-
91
- def get_config_date(self) -> str:
92
- """
93
- ### Returns the date of the last modification of the configuration file.
94
-
95
- #### Returns:
96
- - (str): Date in dd-mm-yyyy format.
97
- """
98
- if not self.last_modified:
99
- self.last_modified = self.__read_config_date()
100
- return self.last_modified
101
-
102
- def __get_file_content(self) -> List[str]:
103
- """
104
- ### Reads the whole unparsed content of the given file.
105
-
106
- #### Returns:
107
- - (list(str)): Content of the file, where each line is a string in the result list.
108
- """
109
- if not os.path.exists(self.__path):
110
- return []
111
- lines = []
112
- with open(self.__path, "r") as config_file:
113
- lines = config_file.readlines()
114
- return lines
115
-
116
- def __read_config_date(self) -> str:
117
- """
118
- ### Reads from the config file the date of its last modification.
119
-
120
- #### Returns:
121
- - (str): Date in dd-mm-yyyy format.
122
- """
123
- config_lines = self.__get_file_content()
124
- for line in config_lines:
125
- if self.__LAST_MODIFIED_TEXT not in line:
126
- continue
127
- match = re.search(r'\d{2}-\d{2}-\d{4} \d{2}:\d{2}.\d{2}', line)
128
- if match:
129
- return match.group()
130
- return ""
131
-
132
- def __add_line_values(self, config: Dict, line: str, line_number: int) -> Optional[Dict]:
133
- """
134
- ### Adds the config values present in the current line to the given dictionary.
135
-
136
- #### Params:
137
- - config (dict): Dictionary with all the present variables.
138
- - line (str): Current line to extract values from.
139
- - line_number (int): Line index in the list of lines that compose the file.
140
-
141
- #### Returns:
142
- - (dict | None): An updated dictionary with the newly obtained variable, or None if there was an error.
143
- """
144
- try:
145
- key_value_pair = self.__parse_config_line(line, line_number)
146
- except InvalidConfigLineError as error:
147
- if self.show_errors:
148
- logger(str(error))
149
- config = {}
150
- return
151
- if key_value_pair:
152
- key, value = key_value_pair
153
- config[key] = value
154
- return config
155
-
156
- def __parse_config_line(self, line: str, line_number: int) -> Optional[Tuple[str, str]]:
157
- """
158
- ### Reads the given line from the config file and returns the key-value pair as a tuple.
159
-
160
- #### Params:
161
- - line_number (int): Line number inside the config file.
162
- - line (str): Line to parse.
163
-
164
- #### Returns:
165
- - (tuple(str, str) | None): Tuple containing the read key-value pair if line contains valid data.
166
-
167
- #### Raises:
168
- - RuntimeError: Raised when a line has an invalid format and cannot be parsed.
169
- """
170
- line_without_comments = line.split(self.__COMMENT_ESCAPE, maxsplit=2)[0].strip()
171
- if not line_without_comments:
172
- return None
173
-
174
- tokens = line_without_comments.split(self.__ASSIGNMENT_SEPARATOR, maxsplit=1)
175
- if len(tokens) != 2:
176
- raise InvalidConfigLineError(
177
- InvalidConfigLineError.generate_error_message(
178
- paths.CONFIG_FILE,
179
- line_number,
180
- line
181
- )
182
- )
183
-
184
- return tokens[0].strip(), tokens[1].strip()
185
-
186
- def __make_config_line(self, key: str, value: str, default_value: str) -> str:
187
- """
188
- ### Composes a config file line given a key-value pair to write.
189
-
190
- #### Params:
191
- - key (int): Name of the variable.
192
- - value (str): Value of the variable found in the config file.
193
- - default_value (str): Default value of the variable.
194
-
195
- #### Returns:
196
- - (str): String containing the appropiately formatted key-value pair.
197
- """
198
- default_value = '' if default_value is None else default_value
199
- value = default_value if value is None else value
200
- return f"{key}{self.__ASSIGNMENT_SEPARATOR}{value}" if key else ""
201
-
202
- def __get_section_lines(self, section_type: str, config_variables: Dict[str, Any]) -> List[str]:
203
- """
204
- ### Returns the lines composed by the given section's variables in the dictionary, and deletes them from it.
205
-
206
- #### Params:
207
- - section_type (str): Section to extract variables from.
208
- - config_variables (dict(str, any)): Dictionary containing all variables.
209
-
210
- #### Returns:
211
- - (list(str)): Config file lines created from the dictionary variables.
212
- """
213
- lines = []
214
- for section_variable in variables.CONFIG_VARIABLES[section_type]:
215
- lines.append(''.join([
216
- self.__make_config_line(
217
- section_variable,
218
- config_variables.get(section_variable),
219
- default_values.CONFIG_DEFAULT_VALUES[section_variable]
220
- ),
221
- "\n"
222
- ]))
223
- config_variables.pop(section_variable, None)
224
- return lines
225
-
226
- def __get_unkown_variable_lines(self, config_variables: Dict[str, Any]) -> List[str]:
227
- """
228
- ### Returns the lines composed by the unkown variables in the dictionary.
229
-
230
- #### Params:
231
- - config_variables (dict(str, any)): Dictionary containing all unknown variables.
232
-
233
- #### Returns:
234
- - (list(str)): Config file lines created from the dictionary variables.
235
- """
236
- lines = []
237
- for variable in config_variables.keys():
238
- lines.append(
239
- f"{self.__make_config_line(variable, config_variables[variable], '')}\n"
240
- )
241
- return lines
15
+ """### Configuration file class for loading and storing the installation configuration."""
16
+
17
+ __COMMENT_ESCAPE = '#'
18
+ __ASSIGNMENT_SEPARATOR = '='
19
+ __LAST_MODIFIED_TEXT = "Config file automatically generated on"
20
+
21
+ def __init__(self, path: str=paths.CONFIG_FILE, show_errors: bool=True):
22
+ """
23
+ ### Constructor.
24
+
25
+ #### Params:
26
+ - path (str): Optional. Path to the configuration file.
27
+ """
28
+ self.__path = path
29
+ self.show_errors = show_errors
30
+ self.values = {}
31
+ self.read_config()
32
+ self.last_modified = self.__read_config_date()
33
+
34
+ def read_config(self):
35
+ """### Reads the config file and stores a dictionary with all the parsed variables."""
36
+ file_lines = self.__get_file_content()
37
+ result = {}
38
+ for line_number, line in enumerate(file_lines):
39
+ new_result = self.__add_line_values(result.copy(), line, line_number + 1)
40
+ if new_result is None:
41
+ result = {}
42
+ break
43
+ result = new_result
44
+ self.values = {
45
+ **config_values_adapter.get_context_values_from_file_values(
46
+ default_values.CONFIG_DEFAULT_VALUES
47
+ ),
48
+ **config_values_adapter.get_context_values_from_file_values(
49
+ result,
50
+ show_warnings=self.show_errors
51
+ )
52
+ }
53
+
54
+ def write_config(self, overwrite: bool=False):
55
+ """
56
+ ### Writes a template config file with stored variables, leaving the rest with default values.
57
+
58
+ #### Params:
59
+ - overwrite (bool): Optional. If True, default values are written, overwriting the existing file.
60
+ """
61
+ if overwrite:
62
+ self.values = config_values_adapter.get_context_values_from_file_values(default_values.CONFIG_DEFAULT_VALUES)
63
+ values = config_values_adapter.get_file_values_from_context_values(self.values.copy())
64
+ self.last_modified = datetime.today().strftime('%d-%m-%Y %H:%M.%S')
65
+
66
+ lines = ["##### TOGGLE SECTION #####\n"]
67
+ lines.append(f"# Activate or deactivate this features using values {default_values.ON}/{default_values.OFF}\n")
68
+ lines.extend(self.__get_section_lines(variables.TOGGLES, values))
69
+
70
+ lines.append("\n##### PACKAGE HOME SECTION #####\n")
71
+ lines.append("# Use this variables to use custom installation paths for the required packages.\n")
72
+ lines.append("# If left empty, CMake will search for those packages within your system.\n")
73
+ lines.extend(self.__get_section_lines(variables.LOCATIONS, values))
74
+
75
+ lines.append("\n##### COMPILATION FLAGS #####\n")
76
+ lines.append("# We recommend not modifying this variables unless you know what you are doing.\n")
77
+ lines.extend(self.__get_section_lines(variables.COMPILATION_FLAGS, values))
78
+
79
+ if values:
80
+ lines.append("\n##### UNKNOWN VARIABLES #####\n")
81
+ lines.append("# This variables were not expected, but are kept here in case they might be needed.\n")
82
+ lines.extend(self.__get_unkown_variable_lines(values))
83
+
84
+ lines.append(f"\n# {self.__LAST_MODIFIED_TEXT} {self.last_modified}\n")
85
+ with open(self.__path, 'w', encoding="utf-8") as config_file:
86
+ config_file.writelines(lines)
87
+
88
+ def get_config_date(self) -> str:
89
+ """
90
+ ### Returns the date of the last modification of the configuration file.
91
+
92
+ #### Returns:
93
+ - (str): Date in dd-mm-yyyy format.
94
+ """
95
+ if not self.last_modified:
96
+ self.last_modified = self.__read_config_date()
97
+ return self.last_modified
98
+
99
+ def __get_file_content(self) -> List[str]:
100
+ """
101
+ ### Reads the whole unparsed content of the given file.
102
+
103
+ #### Returns:
104
+ - (list(str)): Content of the file, where each line is a string in the result list.
105
+ """
106
+ if not os.path.exists(self.__path):
107
+ return []
108
+ lines = []
109
+ with open(self.__path, encoding="utf-8") as config_file:
110
+ lines = config_file.readlines()
111
+ return lines
112
+
113
+ def __read_config_date(self) -> str:
114
+ """
115
+ ### Reads from the config file the date of its last modification.
116
+
117
+ #### Returns:
118
+ - (str): Date in dd-mm-yyyy format.
119
+ """
120
+ config_lines = self.__get_file_content()
121
+ for line in config_lines:
122
+ if self.__LAST_MODIFIED_TEXT not in line:
123
+ continue
124
+ match = re.search(r'\d{2}-\d{2}-\d{4} \d{2}:\d{2}.\d{2}', line)
125
+ if match:
126
+ return match.group()
127
+ return ""
128
+
129
+ def __add_line_values(self, config: Dict, line: str, line_number: int) -> Optional[Dict]:
130
+ """
131
+ ### Adds the config values present in the current line to the given dictionary.
132
+
133
+ #### Params:
134
+ - config (dict): Dictionary with all the present variables.
135
+ - line (str): Current line to extract values from.
136
+ - line_number (int): Line index in the list of lines that compose the file.
137
+
138
+ #### Returns:
139
+ - (dict | None): An updated dictionary with the newly obtained variable, or None if there was an error.
140
+ """
141
+ try:
142
+ key_value_pair = self.__parse_config_line(line, line_number)
143
+ except InvalidConfigLineError as error:
144
+ if self.show_errors:
145
+ logger(str(error))
146
+ config = {}
147
+ return
148
+ if key_value_pair:
149
+ key, value = key_value_pair
150
+ config[key] = value
151
+ return config
152
+
153
+ def __parse_config_line(self, line: str, line_number: int) -> Optional[Tuple[str, str]]:
154
+ """
155
+ ### Reads the given line from the config file and returns the key-value pair as a tuple.
156
+
157
+ #### Params:
158
+ - line_number (int): Line number inside the config file.
159
+ - line (str): Line to parse.
160
+
161
+ #### Returns:
162
+ - (tuple(str, str) | None): Tuple containing the read key-value pair if line contains valid data.
163
+
164
+ #### Raises:
165
+ - RuntimeError: Raised when a line has an invalid format and cannot be parsed.
166
+ """
167
+ N_TOKENS = 2
168
+ line_without_comments = line.split(self.__COMMENT_ESCAPE, maxsplit=2)[0].strip()
169
+ if not line_without_comments:
170
+ return None
171
+
172
+ tokens = line_without_comments.split(self.__ASSIGNMENT_SEPARATOR, maxsplit=1)
173
+ if len(tokens) != N_TOKENS:
174
+ raise InvalidConfigLineError(
175
+ InvalidConfigLineError.generate_error_message(
176
+ paths.CONFIG_FILE,
177
+ line_number,
178
+ line
179
+ )
180
+ )
181
+
182
+ return tokens[0].strip(), tokens[1].strip()
183
+
184
+ def __make_config_line(self, key: str, value: Optional[str], default_value: str) -> str:
185
+ """
186
+ ### Composes a config file line given a key-value pair to write.
187
+
188
+ #### Params:
189
+ - key (int): Name of the variable.
190
+ - value (str | None): Value of the variable found in the config file.
191
+ - default_value (str): Default value of the variable.
192
+
193
+ #### Returns:
194
+ - (str): String containing the appropiately formatted key-value pair.
195
+ """
196
+ default_value = '' if default_value is None else default_value
197
+ value = default_value if value is None else value
198
+ return f"{key}{self.__ASSIGNMENT_SEPARATOR}{value}" if key else ""
199
+
200
+ def __get_section_lines(self, section_type: str, config_variables: Dict[str, str]) -> List[str]:
201
+ """
202
+ ### Returns the lines composed by the given section's variables in the dictionary, and deletes them from it.
203
+
204
+ #### Params:
205
+ - section_type (str): Section to extract variables from.
206
+ - config_variables (dict(str, str)): Dictionary containing all variables.
207
+
208
+ #### Returns:
209
+ - (list(str)): Config file lines created from the dictionary variables.
210
+ """
211
+ lines = []
212
+ for section_variable in variables.CONFIG_VARIABLES[section_type]:
213
+ lines.append(''.join([
214
+ self.__make_config_line(
215
+ section_variable,
216
+ config_variables.get(section_variable),
217
+ default_values.CONFIG_DEFAULT_VALUES[section_variable]
218
+ ),
219
+ "\n"
220
+ ]))
221
+ config_variables.pop(section_variable, None)
222
+ return lines
223
+
224
+ def __get_unkown_variable_lines(self, config_variables: Dict[str, Any]) -> List[str]:
225
+ """
226
+ ### Returns the lines composed by the unkown variables in the dictionary.
227
+
228
+ #### Params:
229
+ - config_variables (dict(str, any)): Dictionary containing all unknown variables.
230
+
231
+ #### Returns:
232
+ - (list(str)): Config file lines created from the dictionary variables.
233
+ """
234
+ lines = []
235
+ for variable_name, value in config_variables.items():
236
+ lines.append(
237
+ f"{self.__make_config_line(variable_name, value, '')}\n"
238
+ )
239
+ return lines
@@ -0,0 +1,5 @@
1
+ """
2
+ ### Configuration Variables Module.
3
+
4
+ This module contains configuration variables used throughout the application.
5
+ """