xmipp3-installer 1.0.1__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.
- xmipp3_installer/__main__.py +1 -1
- xmipp3_installer/api_client/api_client.py +35 -34
- xmipp3_installer/api_client/assembler/installation_info_assembler.py +140 -145
- xmipp3_installer/application/cli/arguments/__init__.py +3 -2
- xmipp3_installer/application/cli/arguments/modes.py +112 -95
- xmipp3_installer/application/cli/arguments/params.py +63 -53
- xmipp3_installer/application/cli/cli.py +171 -190
- xmipp3_installer/application/cli/parsers/base_help_formatter.py +256 -235
- xmipp3_installer/application/cli/parsers/error_handler_parser.py +53 -53
- xmipp3_installer/application/cli/parsers/format.py +22 -22
- xmipp3_installer/application/cli/parsers/general_help_formatter.py +102 -84
- xmipp3_installer/application/cli/parsers/mode_help_formatter.py +144 -105
- xmipp3_installer/application/logger/__init__.py +5 -0
- xmipp3_installer/application/logger/errors.py +8 -8
- xmipp3_installer/application/logger/logger.py +218 -215
- xmipp3_installer/application/logger/predefined_messages.py +42 -35
- xmipp3_installer/application/user_interactions.py +6 -0
- xmipp3_installer/installer/constants/paths.py +6 -0
- xmipp3_installer/installer/handlers/cmake/cmake_handler.py +49 -53
- xmipp3_installer/installer/handlers/conda_handler.py +6 -6
- xmipp3_installer/installer/handlers/generic_package_handler.py +9 -9
- xmipp3_installer/installer/handlers/git_handler.py +152 -153
- xmipp3_installer/installer/handlers/shell_handler.py +87 -88
- xmipp3_installer/installer/handlers/versions_manager.py +20 -6
- xmipp3_installer/installer/installer_service.py +22 -8
- xmipp3_installer/installer/modes/mode_all_executor.py +61 -51
- xmipp3_installer/installer/modes/mode_clean/mode_clean_all_executor.py +44 -36
- xmipp3_installer/installer/modes/mode_clean/mode_clean_bin_executor.py +84 -74
- xmipp3_installer/installer/modes/mode_clean/mode_clean_executor.py +48 -34
- xmipp3_installer/installer/modes/mode_cmake/mode_cmake_executor.py +60 -47
- xmipp3_installer/installer/modes/mode_cmake/mode_compile_and_install_executor.py +52 -39
- xmipp3_installer/installer/modes/mode_cmake/mode_config_build_executor.py +68 -49
- xmipp3_installer/installer/modes/mode_config_executor.py +44 -33
- xmipp3_installer/installer/modes/mode_executor.py +14 -13
- xmipp3_installer/installer/modes/mode_get_sources_executor.py +121 -112
- xmipp3_installer/installer/modes/mode_git_executor.py +43 -31
- xmipp3_installer/installer/modes/mode_selector.py +6 -0
- xmipp3_installer/installer/modes/mode_sync/mode_add_model_executor.py +97 -83
- xmipp3_installer/installer/modes/mode_sync/mode_get_models_executor.py +53 -41
- xmipp3_installer/installer/modes/mode_sync/mode_sync_executor.py +41 -35
- xmipp3_installer/installer/modes/mode_sync/mode_test_executor.py +144 -77
- xmipp3_installer/installer/modes/mode_version_executor.py +161 -150
- xmipp3_installer/installer/orquestrator.py +24 -24
- xmipp3_installer/installer/urls.py +4 -3
- xmipp3_installer/repository/config.py +225 -227
- xmipp3_installer/repository/config_vars/__init__.py +5 -0
- xmipp3_installer/repository/config_vars/config_values_adapter.py +97 -91
- xmipp3_installer/repository/config_vars/default_values.py +24 -24
- xmipp3_installer/repository/config_vars/variables.py +9 -9
- xmipp3_installer/repository/invalid_config_line.py +17 -0
- xmipp3_installer/shared/file_operations.py +14 -12
- xmipp3_installer/shared/singleton.py +16 -17
- xmipp3_installer-1.1.0.dist-info/METADATA +86 -0
- xmipp3_installer-1.1.0.dist-info/RECORD +70 -0
- {xmipp3_installer-1.0.1.dist-info → xmipp3_installer-1.1.0.dist-info}/WHEEL +1 -1
- xmipp3_installer-1.0.1.dist-info/METADATA +0 -729
- xmipp3_installer-1.0.1.dist-info/RECORD +0 -70
- {xmipp3_installer-1.0.1.dist-info → xmipp3_installer-1.1.0.dist-info}/entry_points.txt +0 -0
- /xmipp3_installer-1.0.1.dist-info/LICENSE → /xmipp3_installer-1.1.0.dist-info/licenses/LICENSE.txt +0 -0
- {xmipp3_installer-1.0.1.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
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
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
|