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,68 +2,64 @@
2
2
 
3
3
  import os
4
4
  import shutil
5
- from typing import Dict, Any
5
+ from typing import Any, Dict, Optional, Tuple, Union, List
6
6
 
7
7
  from xmipp3_installer.installer.handlers.cmake import cmake_constants
8
- from xmipp3_installer.repository.config_vars import variables
9
8
 
10
- def get_cmake_path(config: Dict[str, Any]) -> str:
11
- """
12
- ### Retrieves information about the CMake package and updates the dictionary accordingly.
9
+ def get_cmake_path() -> Optional[str]:
10
+ """
11
+ ### Returns the path to the CMake executable.
13
12
 
14
- #### Params:
15
- - packages (dict): Dictionary containing package information.
13
+ #### Returns:
14
+ - (str | None): Path to the CMake executable if found, None otherwise.
15
+ """
16
+ return shutil.which(cmake_constants.DEFAULT_CMAKE)
16
17
 
17
- #### Returns:
18
- - (dict): Param 'packages' with the 'CMAKE' key updated based on the availability of 'cmake'.
19
- """
20
- return config.get(variables.CMAKE) or shutil.which(cmake_constants.DEFAULT_CMAKE)
18
+ def get_cmake_params(variables: List[Tuple[str, Union[str, bool]]]) -> str:
19
+ """
20
+ ### Converts the given list of variable names into CMake parameters.
21
21
 
22
- def get_cmake_vars_str(config: Dict[str, Any]) -> str:
23
- """
24
- ### Converts the variables in the config dictionary into a list as CMake args.
25
-
26
- #### Params:
27
- - config (dict): Dictionary to obtain the parameters from.
28
- """
29
- result = []
30
- for (key, value) in config.items():
31
- if key not in variables.INTERNAL_LOGIC_VARS and bool(value):
32
- result.append(f"-D{key}={value}")
33
- return ' '.join(result)
22
+ #### Params:
23
+ - variables (list): List of variable names to obtain the parameters from.
24
+ """
25
+ result = []
26
+ for key, value in variables:
27
+ result.append(f"-D{key}={value}")
28
+ return ' '.join(result)
34
29
 
35
30
  def get_library_versions_from_cmake_file(path: str) -> Dict[str, Any]:
36
- """
37
- ### Obtains the library versions from the CMake cache file.
31
+ """
32
+ ### Obtains the library versions from the CMake cache file.
38
33
 
39
- #### Params:
40
- - path (str): Path to the file containing all versions.
34
+ #### Params:
35
+ - path (str): Path to the file containing all versions.
41
36
 
42
- #### Returns:
43
- - (dict(str, any)): Dictionary containing all the library versions in the file.
44
- """
45
- if not os.path.exists(path):
46
- return {}
47
-
48
- result = {}
49
- with open(path, 'r') as versions_file:
50
- for line in versions_file.readlines():
51
- result.update(__get_library_version_from_line(line))
52
- return result
37
+ #### Returns:
38
+ - (dict(str, any)): Dictionary containing all the library versions in the file.
39
+ """
40
+ if not os.path.exists(path):
41
+ return {}
42
+
43
+ result = {}
44
+ with open(path, encoding="utf-8") as versions_file:
45
+ for line in versions_file.readlines():
46
+ result.update(__get_library_version_from_line(line))
47
+ return result
53
48
 
54
49
  def __get_library_version_from_line(version_line: str) -> Dict[str, Any]:
55
- """
56
- ### Retrieves the name and version of the library in the given line.
57
-
58
- #### Params:
59
- - version_line (str): Text line containing the name and version of the library.
60
-
61
- #### Returns:
62
- - (dict(str, any)): Dictionary where the key is the name and the value is the version.
63
- """
64
- library_with_version = {}
65
- name_and_version = version_line.replace("\n", "").split('=')
66
- if len(name_and_version) == 2:
67
- version = name_and_version[1] if name_and_version[1] else None
68
- library_with_version[name_and_version[0]] = version
69
- return library_with_version
50
+ """
51
+ ### Retrieves the name and version of the library in the given line.
52
+
53
+ #### Params:
54
+ - version_line (str): Text line containing the name and version of the library.
55
+
56
+ #### Returns:
57
+ - (dict(str, any)): Dictionary where the key is the name and the value is the version.
58
+ """
59
+ TOKEN_NUMBER = 2 # Two tokens separated by a =
60
+ library_with_version = {}
61
+ name_and_version = version_line.replace("\n", "").split('=')
62
+ if len(name_and_version) == TOKEN_NUMBER:
63
+ version = name_and_version[1] if name_and_version[1] else None
64
+ library_with_version[name_and_version[0]] = version
65
+ return library_with_version
@@ -4,10 +4,10 @@ import os
4
4
  from typing import Optional
5
5
 
6
6
  def get_conda_prefix_path() -> Optional[str]:
7
- """
8
- ### Returns the path for the current Conda enviroment.
7
+ """
8
+ ### Returns the path for the current Conda enviroment.
9
9
 
10
- #### Returns:
11
- - (str | None): Path for current Conda enviroment.
12
- """
13
- return os.environ.get('CONDA_PREFIX')
10
+ #### Returns:
11
+ - (str | None): Path for current Conda enviroment.
12
+ """
13
+ return os.environ.get('CONDA_PREFIX')
@@ -5,14 +5,14 @@ from typing import Optional
5
5
  from xmipp3_installer.installer.handlers import shell_handler
6
6
 
7
7
  def get_package_version(package_name: str) -> Optional[str]:
8
- """
9
- ### Retrieves the version of a package or program by executing '[package_name] --version' command.
8
+ """
9
+ ### Retrieves the version of a package or program by executing '[package_name] --version' command.
10
10
 
11
- Params:
12
- - package_name (str): Name of the package or program.
11
+ Params:
12
+ - package_name (str): Name of the package or program.
13
13
 
14
- Returns:
15
- - (str | None): Version information of the package or None if not found or errors happened.
16
- """
17
- ret_code, output = shell_handler.run_shell_command(f'{package_name} --version')
18
- return output if ret_code == 0 else None
14
+ Returns:
15
+ - (str | None): Version information of the package or None if not found or errors happened.
16
+ """
17
+ ret_code, output = shell_handler.run_shell_command(f'{package_name} --version')
18
+ return output if ret_code == 0 else None
@@ -8,178 +8,177 @@ from xmipp3_installer.installer.constants import paths
8
8
  from xmipp3_installer.installer.handlers import shell_handler
9
9
 
10
10
  def get_current_branch(dir: str='./') -> str:
11
- """
12
- ### Returns the current branch of the repository of the given directory or empty string if it is not a repository or a recognizable tag.
13
-
14
- #### Params:
15
- - dir (str): Optional. Directory of the repository to get current branch from. Default is current directory.
16
-
17
- #### Returns:
18
- - (str): The name of the branch, 'HEAD' if a tag, or empty string if given directory is not a repository or a recognizable tag.
19
- """
20
- ret_code, branch_name = shell_handler.run_shell_command("git rev-parse --abbrev-ref HEAD", cwd=dir)
21
- # If there was an error, we are in no branch
22
- return branch_name if not ret_code else ''
11
+ """
12
+ ### Returns the current branch of the repository of the given directory or empty string if it is not a repository or a recognizable tag.
13
+
14
+ #### Params:
15
+ - dir (str): Optional. Directory of the repository to get current branch from. Default is current directory.
16
+
17
+ #### Returns:
18
+ - (str): The name of the branch, 'HEAD' if a tag, or empty string if given directory is not a repository or a recognizable tag.
19
+ """
20
+ ret_code, branch_name = shell_handler.run_shell_command("git rev-parse --abbrev-ref HEAD", cwd=dir)
21
+ # If there was an error, we are in no branch
22
+ return branch_name if not ret_code else ''
23
23
 
24
24
  def is_tag(dir: str='./') -> bool:
25
- """
26
- ### Returns True if the current Xmipp repository is in a tag.
27
-
28
- #### Params:
29
- - dir (str): Optional. Directory of the repository where the check will happen. Default is current directory.
30
-
31
- #### Returns:
32
- - (bool): True if the repository is a tag. False otherwise.
33
- """
34
- current_branch = get_current_branch(dir=dir)
35
- return not current_branch or current_branch == "HEAD"
25
+ """
26
+ ### Returns True if the current Xmipp repository is in a tag.
27
+
28
+ #### Params:
29
+ - dir (str): Optional. Directory of the repository where the check will happen. Default is current directory.
30
+
31
+ #### Returns:
32
+ - (bool): True if the repository is a tag. False otherwise.
33
+ """
34
+ current_branch = get_current_branch(dir=dir)
35
+ return not current_branch or current_branch == "HEAD"
36
36
 
37
37
  def is_branch_up_to_date(dir: str='./') -> bool:
38
- """
39
- ### Returns True if the current branch is up to date, or False otherwise or if some error happened.
40
-
41
- #### Params:
42
- - dir (str): Optional. Directory of the repository to get current branch from. Default is current directory.
43
-
44
- #### Returns:
45
- - (bool): True if the current branch is up to date, or False otherwise or if some error happened.
46
- """
47
- current_branch = get_current_branch(dir=dir)
48
- if not current_branch:
49
- return False
50
-
51
- ret_code = shell_handler.run_shell_command("git fetch", cwd=dir)[0]
52
- if ret_code != 0:
53
- return False
54
-
55
- latest_local_commit = shell_handler.run_shell_command(f"git rev-parse {current_branch}", cwd=dir)[1]
56
- ret_code, latest_remote_commit = shell_handler.run_shell_command(f"git rev-parse origin/{current_branch}")
57
- if ret_code != 0:
58
- return False
59
-
60
- return latest_local_commit == latest_remote_commit
38
+ """
39
+ ### Returns True if the current branch is up to date, or False otherwise or if some error happened.
40
+
41
+ #### Params:
42
+ - dir (str): Optional. Directory of the repository to get current branch from. Default is current directory.
43
+
44
+ #### Returns:
45
+ - (bool): True if the current branch is up to date, or False otherwise or if some error happened.
46
+ """
47
+ current_branch = get_current_branch(dir=dir)
48
+ if not current_branch:
49
+ return False
50
+
51
+ ret_code = shell_handler.run_shell_command("git fetch", cwd=dir)[0]
52
+ if ret_code != 0:
53
+ return False
54
+
55
+ latest_local_commit = shell_handler.run_shell_command(f"git rev-parse {current_branch}", cwd=dir)[1]
56
+ ret_code, latest_remote_commit = shell_handler.run_shell_command(f"git rev-parse origin/{current_branch}")
57
+ if ret_code != 0:
58
+ return False
59
+
60
+ return latest_local_commit == latest_remote_commit
61
61
 
62
62
  def get_current_commit(dir: str="./") -> str:
63
- """
64
- ### Rreturns the current commit short hash of a given repository:
63
+ """
64
+ ### Returns the current commit short hash of a given repository.
65
65
 
66
- #### Params:
67
- - dir (str): Optional. Directory of repository.
66
+ #### Params:
67
+ - dir (str): Optional. Directory of repository.
68
68
 
69
- #### Returns:
70
- - (str): Current commit short hash, or empty string if it is not a repo or there were errors.
71
- """
72
- ret_code, output = shell_handler.run_shell_command("git rev-parse --short HEAD", cwd=dir)
73
- if ret_code or not output:
74
- return ''
75
- return output
69
+ #### Returns:
70
+ - (str): Current commit short hash, or empty string if it is not a repo or there were errors.
71
+ """
72
+ ret_code, output = shell_handler.run_shell_command("git rev-parse --short HEAD", cwd=dir)
73
+ if ret_code or not output:
74
+ return ''
75
+ return output
76
76
 
77
77
  def get_commit_branch(commit: str, dir: str="./") -> str:
78
- """
79
- ### Returns the name of the commit branch. It can be a branch name or a release name.
78
+ """
79
+ ### Returns the name of the commit branch. It can be a branch name or a release name.
80
80
 
81
- #### Params:
82
- - commit (str): Commit hash.
83
- - dir (str): Optional. Directory to repository.
81
+ #### Params:
82
+ - commit (str): Commit hash.
83
+ - dir (str): Optional. Directory to repository.
84
84
 
85
- #### Returns:
86
- - (str): Name of the commit branch or release.
87
- """
88
- ret_code, output = shell_handler.run_shell_command(f"git name-rev {commit}", cwd=dir)
89
- if ret_code or not output:
90
- return ''
91
- return output.replace(commit, "").replace(" ", "")
85
+ #### Returns:
86
+ - (str): Name of the commit branch or release.
87
+ """
88
+ ret_code, output = shell_handler.run_shell_command(f"git name-rev {commit}", cwd=dir)
89
+ if ret_code or not output:
90
+ return ''
91
+ return output.replace(commit, "").replace(" ", "")
92
92
 
93
93
  def branch_exists_in_repo(repo_url: str, branch: str) -> bool:
94
- """
95
- ### Checks if the given branch exists in the given repository.
94
+ """
95
+ ### Checks if the given branch exists in the given repository.
96
96
 
97
- #### Params:
98
- - repo (str): Repository to check from.
99
- - branch (str): Name of the branch to check for.
97
+ #### Params:
98
+ - repo (str): Repository to check from.
99
+ - branch (str): Name of the branch to check for.
100
100
 
101
- #### Returns:
102
- - (bool): True if the branch exists, False otherwise.
103
- """
104
- return __ref_exists_in_repo(repo_url, branch, True)
101
+ #### Returns:
102
+ - (bool): True if the branch exists, False otherwise.
103
+ """
104
+ return __ref_exists_in_repo(repo_url, branch, True)
105
105
 
106
106
  def tag_exists_in_repo(repo_url: str, tag: str) -> bool:
107
- """
108
- ### Checks if the given tag exists in the given repository.
109
-
110
- #### Params:
111
- - repo_url (str): Repository to check from.
112
- - tag (str): Name of the tag to check for.
113
-
114
- #### Returns:
115
- - (bool): True if the tag exists, False otherwise.
116
- """
117
- return __ref_exists_in_repo(repo_url, tag, False)
118
-
119
- def get_clonable_branch(repo_url: str, preferred_branch: str, viable_tag: str) -> Optional[str]:
120
- """
121
- ### Decides the target to be cloned from a given repository.
122
-
123
- The preferred branch will be selected if exists,
124
- followed in priority by the viable tag if provided.
125
- Finally, if no branch could be selected, None is returned,
126
- meaning that repository's default branch will be used.
127
-
128
- #### Params:
129
- - repo_url (str): Url of the repositori to be cloned.
130
- - preferred_branch (str): Preferred branch to clone into.
131
- - viable_tag (str): If exists, it is returned if branch does not.
132
-
133
- #### Returns:
134
- - (str): Name of the branch to clone the repository into.
135
- """
136
- if preferred_branch and branch_exists_in_repo(repo_url, preferred_branch):
137
- return preferred_branch
138
- if viable_tag and tag_exists_in_repo(repo_url, viable_tag):
139
- return viable_tag
140
- return None
107
+ """
108
+ ### Checks if the given tag exists in the given repository.
109
+
110
+ #### Params:
111
+ - repo_url (str): Repository to check from.
112
+ - tag (str): Name of the tag to check for.
113
+
114
+ #### Returns:
115
+ - (bool): True if the tag exists, False otherwise.
116
+ """
117
+ return __ref_exists_in_repo(repo_url, tag, False)
118
+
119
+ def get_clonable_branch(repo_url: str, preferred_branch: str, viable_tag: Optional[str]) -> Optional[str]:
120
+ """
121
+ ### Decides the target to be cloned from a given repository.
122
+
123
+ The preferred branch will be selected if exists,
124
+ followed in priority by the viable tag if provided.
125
+ Finally, if no branch could be selected, None is returned,
126
+ meaning that repository's default branch will be used.
127
+
128
+ #### Params:
129
+ - repo_url (str): Url of the repositori to be cloned.
130
+ - preferred_branch (str): Preferred branch to clone into.
131
+ - viable_tag (str | None): If exists, it is returned if branch does not.
132
+
133
+ #### Returns:
134
+ - (str | None): Name of the branch to clone the repository into, or None if not found.
135
+ """
136
+ if preferred_branch and branch_exists_in_repo(repo_url, preferred_branch):
137
+ return preferred_branch
138
+ if viable_tag and tag_exists_in_repo(repo_url, viable_tag):
139
+ return viable_tag
141
140
 
142
141
  def execute_git_command_for_source(command: str, source: str) -> Tuple[int, str]:
143
- """
144
- ### Executes the git command for a specific source.
145
-
146
- #### Params:
147
- - command (str): Command to execute on the source.
148
- - source (str): The source repository name.
149
-
150
- #### Returns:
151
- - (tuple(int, str)): Tuple containing the return code and output message.
152
- """
153
- source_path = paths.get_source_path(source)
154
- if not os.path.exists(source_path):
155
- logger(logger.yellow(
156
- f"WARNING: Source {source} does not exist in path {source_path}. Skipping."
157
- ))
158
- return 0, ""
159
-
160
- return shell_handler.run_shell_command(
161
- f"git {command}",
162
- cwd=source_path,
163
- show_output=True,
164
- show_error=True
165
- )
142
+ """
143
+ ### Executes the git command for a specific source.
144
+
145
+ #### Params:
146
+ - command (str): Command to execute on the source.
147
+ - source (str): The source repository name.
148
+
149
+ #### Returns:
150
+ - (tuple(int, str)): Tuple containing the return code and output message.
151
+ """
152
+ source_path = paths.get_source_path(source)
153
+ if not os.path.exists(source_path):
154
+ logger(logger.yellow(
155
+ f"WARNING: Source {source} does not exist in path {source_path}. Skipping."
156
+ ))
157
+ return 0, ""
158
+
159
+ return shell_handler.run_shell_command(
160
+ f"git {command}",
161
+ cwd=source_path,
162
+ show_output=True,
163
+ show_error=True
164
+ )
166
165
 
167
166
  def __ref_exists_in_repo(repo_url: str, ref: str, is_branch: bool) -> bool:
168
- """
169
- ### Checks if a given reference exists in the given repository.
170
-
171
- #### Params:
172
- - repo_url (str): Repository to check from.
173
- - ref (str): Reference to check for.
174
- - is_branch (bool): If True, the reference is a branch. If False, it is a tag.
175
-
176
- #### Returns:
177
- - (bool): True if the ref exists, False otherwise.
178
- """
179
- ref_type = "heads" if is_branch else "tags"
180
- ret_code, output = shell_handler.run_shell_command(
181
- f"git ls-remote --{ref_type} {repo_url}.git refs/{ref_type}/{ref}"
182
- )
183
- if ret_code:
184
- return False
185
- return f"refs/{ref_type}/{ref}" in output
167
+ """
168
+ ### Checks if a given reference exists in the given repository.
169
+
170
+ #### Params:
171
+ - repo_url (str): Repository to check from.
172
+ - ref (str): Reference to check for.
173
+ - is_branch (bool): If True, the reference is a branch. If False, it is a tag.
174
+
175
+ #### Returns:
176
+ - (bool): True if the ref exists, False otherwise.
177
+ """
178
+ ref_type = "heads" if is_branch else "tags"
179
+ ret_code, output = shell_handler.run_shell_command(
180
+ f"git ls-remote --{ref_type} {repo_url}.git refs/{ref_type}/{ref}"
181
+ )
182
+ if ret_code:
183
+ return False
184
+ return f"refs/{ref_type}/{ref}" in output