@@ -109,27 +109,7 @@ def _install_dependencies(self, *, update: bool = False) -> None:
109109 logger .debug ('Available remotes: %s' , [remote .name for remote in all_remotes ])
110110
111111 # Get default profiles, handle case when no default profile exists
112- try :
113- profile_host_path = conan_api .profiles .get_default_host ()
114- profile_build_path = conan_api .profiles .get_default_build ()
115-
116- # Ensure we have valid profile paths
117- if profile_host_path is None :
118- # Create a minimal default profile with basic settings if none exists
119- profile_host = conan_api .profiles .detect ()
120- else :
121- profile_host = conan_api .profiles .get_profile ([profile_host_path ])
122-
123- if profile_build_path is None :
124- # Create a minimal default profile with basic settings if none exists
125- profile_build = conan_api .profiles .detect ()
126- else :
127- profile_build = conan_api .profiles .get_profile ([profile_build_path ])
128-
129- except Exception :
130- # If profile operations fail, create minimal default profiles with basic settings
131- profile_host = conan_api .profiles .detect ()
132- profile_build = conan_api .profiles .detect ()
112+ profile_host , profile_build = self ._resolve_profiles (conan_api )
133113
134114 logger .debug ('Using profiles: host=%s, build=%s' , profile_host , profile_build )
135115
@@ -267,27 +247,7 @@ def publish(self) -> None:
267247 )
268248
269249 # Step 2: Get default profiles, handle case when no default profile exists
270- try :
271- profile_host_path = conan_api .profiles .get_default_host ()
272- profile_build_path = conan_api .profiles .get_default_build ()
273-
274- # Ensure we have valid profile paths
275- if profile_host_path is None :
276- # Create a minimal default profile with basic settings if none exists
277- profile_host = conan_api .profiles .detect ()
278- else :
279- profile_host = conan_api .profiles .get_profile ([profile_host_path ])
280-
281- if profile_build_path is None :
282- # Create a minimal default profile with basic settings if none exists
283- profile_build = conan_api .profiles .detect ()
284- else :
285- profile_build = conan_api .profiles .get_profile ([profile_build_path ])
286-
287- except Exception :
288- # If profile operations fail, create minimal default profiles with basic settings
289- profile_host = conan_api .profiles .detect ()
290- profile_build = conan_api .profiles .detect ()
250+ profile_host , profile_build = self ._resolve_profiles (conan_api )
291251
292252 # Step 3: Build dependency graph for the package
293253 deps_graph = conan_api .graph .load_graph_consumer (
@@ -339,3 +299,40 @@ def publish(self) -> None:
339299 )
340300 else :
341301 raise ProviderInstallationError ('conan' , 'No packages found to upload' )
302+
303+ def _resolve_profiles (self , conan_api ) -> tuple :
304+ """Resolve host and build profiles with fallback to detect().
305+
306+ Args:
307+ conan_api: The Conan API instance
308+
309+ Returns:
310+ Tuple of (profile_host, profile_build)
311+ """
312+ try :
313+ profile_host_path = conan_api .profiles .get_default_host ()
314+ profile_build_path = conan_api .profiles .get_default_build ()
315+
316+ # Resolve host profile
317+ if profile_host_path is None :
318+ profile_host = conan_api .profiles .detect ()
319+ else :
320+ profile_host = conan_api .profiles .get_profile ([profile_host_path ])
321+ if profile_host is None :
322+ profile_host = conan_api .profiles .detect ()
323+
324+ # Resolve build profile
325+ if profile_build_path is None :
326+ profile_build = conan_api .profiles .detect ()
327+ else :
328+ profile_build = conan_api .profiles .get_profile ([profile_build_path ])
329+ if profile_build is None :
330+ profile_build = conan_api .profiles .detect ()
331+
332+ return profile_host , profile_build
333+
334+ except Exception :
335+ # If profile operations fail, create minimal default profiles with basic settings
336+ profile_host = conan_api .profiles .detect ()
337+ profile_build = conan_api .profiles .detect ()
338+ return profile_host , profile_build
0 commit comments