2020from cppython .plugins .conan .builder import Builder
2121from cppython .plugins .conan .resolution import resolve_conan_data , resolve_conan_dependency
2222from cppython .plugins .conan .schema import ConanData
23- from cppython .utility .exception import NotSupportedError
23+ from cppython .utility .exception import NotSupportedError , ProviderConfigurationError , ProviderInstallationError
2424from cppython .utility .utility import TypeName
2525
2626
@@ -69,21 +69,64 @@ def information() -> Information:
6969 """
7070 return Information ()
7171
72- def install (self ) -> None :
73- """Installs the provider"""
74- resolved_dependencies = [resolve_conan_dependency (req ) for req in self .core_data .cppython_data .dependencies ]
72+ def _install_dependencies (self , * , update : bool = False ) -> None :
73+ """Common implementation for installing/updating dependencies.
74+
75+ Args:
76+ update: If True, check remotes for newer versions/revisions and install those.
77+ If False, use cached versions when available.
78+ """
79+ try :
80+ resolved_dependencies = [resolve_conan_dependency (req ) for req in self .core_data .cppython_data .dependencies ]
81+
82+ self .builder .generate_conanfile (self .core_data .project_data .project_root , resolved_dependencies )
83+
84+ self .core_data .cppython_data .build_path .mkdir (parents = True , exist_ok = True )
85+
86+ # Install/update dependencies using Conan API
87+ project_root = self .core_data .project_data .project_root
88+ conanfile_path = project_root / 'conanfile.py'
89+
90+ if conanfile_path .exists ():
91+ # Initialize Conan API
92+ conan_api = ConanAPI ()
93+
94+ # Get default profiles
95+ profile_host_path = conan_api .profiles .get_default_host ()
96+ profile_build_path = conan_api .profiles .get_default_build ()
97+ profile_host = conan_api .profiles .get_profile ([profile_host_path ])
98+ profile_build = conan_api .profiles .get_profile ([profile_build_path ])
99+
100+ # Build dependency graph for the package
101+ deps_graph = conan_api .graph .load_graph_consumer (
102+ path = str (conanfile_path ),
103+ name = None ,
104+ version = None ,
105+ user = None ,
106+ channel = None ,
107+ profile_host = profile_host ,
108+ profile_build = profile_build ,
109+ lockfile = None ,
110+ remotes = conan_api .remotes .list (),
111+ update = update ,
112+ check_updates = update ,
113+ is_build_require = False ,
114+ )
75115
76- self .builder .generate_conanfile (self .core_data .project_data .project_root , resolved_dependencies )
116+ # Install dependencies
117+ conan_api .install .install_binaries (deps_graph = deps_graph , remotes = conan_api .remotes .list ())
118+ except Exception as e :
119+ operation = 'update' if update else 'install'
120+ error_msg = str (e )
121+ raise ProviderInstallationError ('conan' , f'Failed to { operation } dependencies: { error_msg } ' , e ) from e
77122
78- self .core_data .cppython_data .build_path .mkdir (parents = True , exist_ok = True )
123+ def install (self ) -> None :
124+ """Installs the provider"""
125+ self ._install_dependencies (update = False )
79126
80127 def update (self ) -> None :
81128 """Updates the provider"""
82- resolved_dependencies = [resolve_conan_dependency (req ) for req in self .core_data .cppython_data .dependencies ]
83-
84- self .builder .generate_conanfile (self .core_data .project_data .project_root , resolved_dependencies )
85-
86- self .core_data .cppython_data .build_path .mkdir (parents = True , exist_ok = True )
129+ self ._install_dependencies (update = True )
87130
88131 @staticmethod
89132 def supported_sync_type (sync_type : type [SyncData ]) -> bool :
@@ -148,7 +191,10 @@ def publish(self) -> None:
148191 )
149192
150193 # Step 2: Get default profiles
151- profile_host , profile_build = conan_api .profiles .get_profiles_from_args ([])
194+ profile_host_path = conan_api .profiles .get_default_host ()
195+ profile_build_path = conan_api .profiles .get_default_build ()
196+ profile_host = conan_api .profiles .get_profile ([profile_host_path ])
197+ profile_build = conan_api .profiles .get_profile ([profile_build_path ])
152198
153199 # Step 3: Build dependency graph for the package
154200 deps_graph = conan_api .graph .load_graph_consumer (
@@ -188,7 +234,7 @@ def publish(self) -> None:
188234 # Get the first configured remote or raise an error
189235 remotes = conan_api .remotes .list ()
190236 if not remotes :
191- raise RuntimeError ( ' No remotes configured for upload' )
237+ raise ProviderConfigurationError ( 'conan' , ' No remotes configured for upload' , 'remotes ' )
192238
193239 remote = remotes [0 ] # Use first remote
194240
@@ -203,4 +249,4 @@ def publish(self) -> None:
203249 dry_run = False ,
204250 )
205251 else :
206- raise RuntimeError ( 'No packages found to upload' )
252+ raise ProviderInstallationError ( 'conan' , 'No packages found to upload' )
0 commit comments