@@ -76,6 +76,32 @@ def _install_dependencies(self, *, update: bool = False) -> None:
7676 update: If True, check remotes for newer versions/revisions and install those.
7777 If False, use cached versions when available.
7878 """
79+ try :
80+ # Setup environment and generate conanfile
81+ conan_api , conanfile_path = self ._prepare_installation ()
82+
83+ # Load dependency graph
84+ deps_graph = self ._load_dependency_graph (conan_api , conanfile_path , update )
85+
86+ # Install dependencies
87+ self ._install_binaries (conan_api , deps_graph , update )
88+
89+ # Generate consumer files
90+ self ._generate_consumer_files (conan_api , deps_graph )
91+
92+ except Exception as e :
93+ operation = 'update' if update else 'install'
94+ raise ProviderInstallationError ('conan' , f'Failed to { operation } dependencies: { e } ' , e ) from e
95+
96+ def _prepare_installation (self ) -> tuple [ConanAPI , Path ]:
97+ """Prepare the installation environment and generate conanfile.
98+
99+ Returns:
100+ Tuple of (ConanAPI instance, conanfile path)
101+
102+ Raises:
103+ ProviderInstallationError: If conanfile generation or setup fails
104+ """
79105 try :
80106 # Resolve dependencies and generate conanfile.py
81107 resolved_dependencies = [resolve_conan_dependency (req ) for req in self .core_data .cppython_data .dependencies ]
@@ -92,11 +118,30 @@ def _install_dependencies(self, *, update: bool = False) -> None:
92118 if not conanfile_path .exists ():
93119 raise ProviderInstallationError ('conan' , 'Generated conanfile.py not found' )
94120
121+ return conan_api , conanfile_path
122+
123+ except Exception as e :
124+ raise ProviderInstallationError ('conan' , f'Failed to prepare installation environment: { e } ' , e ) from e
125+
126+ def _load_dependency_graph (self , conan_api : ConanAPI , conanfile_path : Path , update : bool ):
127+ """Load and build the dependency graph.
128+
129+ Args:
130+ conan_api: The Conan API instance
131+ conanfile_path: Path to the conanfile.py
132+ update: Whether to check for updates
133+
134+ Returns:
135+ The loaded dependency graph
136+
137+ Raises:
138+ ProviderInstallationError: If dependency graph loading fails
139+ """
140+ try :
95141 all_remotes = conan_api .remotes .list ()
96142 profile_host , profile_build = self .data .host_profile , self .data .build_profile
97143
98- # Load dependency graph
99- deps_graph = conan_api .graph .load_graph_consumer (
144+ return conan_api .graph .load_graph_consumer (
100145 path = str (conanfile_path ),
101146 name = None ,
102147 version = None ,
@@ -111,7 +156,24 @@ def _install_dependencies(self, *, update: bool = False) -> None:
111156 profile_build = profile_build ,
112157 )
113158
114- # Analyze and install binaries
159+ except Exception as e :
160+ raise ProviderInstallationError ('conan' , f'Failed to load dependency graph: { e } ' , e ) from e
161+
162+ def _install_binaries (self , conan_api : ConanAPI , deps_graph , update : bool ) -> None :
163+ """Analyze and install binary dependencies.
164+
165+ Args:
166+ conan_api: The Conan API instance
167+ deps_graph: The dependency graph
168+ update: Whether to check for updates
169+
170+ Raises:
171+ ProviderInstallationError: If binary analysis or installation fails
172+ """
173+ try :
174+ all_remotes = conan_api .remotes .list ()
175+
176+ # Analyze binaries to determine what needs to be built/downloaded
115177 conan_api .graph .analyze_binaries (
116178 graph = deps_graph ,
117179 build_mode = ['missing' ],
@@ -120,9 +182,25 @@ def _install_dependencies(self, *, update: bool = False) -> None:
120182 lockfile = None ,
121183 )
122184
185+ # Install all dependencies
123186 conan_api .install .install_binaries (deps_graph = deps_graph , remotes = all_remotes )
124187
125- # Generate consumer files
188+ except Exception as e :
189+ raise ProviderInstallationError ('conan' , f'Failed to install binary dependencies: { e } ' , e ) from e
190+
191+ def _generate_consumer_files (self , conan_api : ConanAPI , deps_graph ) -> None :
192+ """Generate consumer files (CMake toolchain, deps, etc.).
193+
194+ Args:
195+ conan_api: The Conan API instance
196+ deps_graph: The dependency graph
197+
198+ Raises:
199+ ProviderInstallationError: If consumer file generation fails
200+ """
201+ try :
202+ project_root = self .core_data .project_data .project_root
203+
126204 conan_api .install .install_consumer (
127205 deps_graph = deps_graph ,
128206 generators = ['CMakeToolchain' , 'CMakeDeps' ],
@@ -131,8 +209,7 @@ def _install_dependencies(self, *, update: bool = False) -> None:
131209 )
132210
133211 except Exception as e :
134- operation = 'update' if update else 'install'
135- raise ProviderInstallationError ('conan' , f'Failed to { operation } dependencies: { e } ' , e ) from e
212+ raise ProviderInstallationError ('conan' , f'Failed to generate consumer files: { e } ' , e ) from e
136213
137214 def install (self ) -> None :
138215 """Installs the provider"""
0 commit comments