Skip to content

Commit bcb18f2

Browse files
committed
Merge Detection Strat
1 parent b244022 commit bcb18f2

File tree

1 file changed

+41
-44
lines changed

1 file changed

+41
-44
lines changed

cppython/plugins/conan/plugin.py

Lines changed: 41 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -109,30 +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 profiles with fallback to auto-detection
112-
try:
113-
profile_host_path = conan_api.profiles.get_default_host()
114-
profile_build_path = conan_api.profiles.get_default_build()
115-
116-
# Check if profile paths exist
117-
if profile_host_path is None or profile_build_path is None:
118-
logger.warning('Default profile paths not available, using auto-detection')
119-
raise ValueError('Profile paths are None')
120-
121-
# Load the actual profile objects
122-
profile_host = conan_api.profiles.get_profile([profile_host_path])
123-
profile_build = conan_api.profiles.get_profile([profile_build_path])
124-
125-
# Check if profiles are valid (not None)
126-
if profile_host is None or profile_build is None:
127-
logger.warning('Default profiles are corrupted/invalid, using auto-detection')
128-
raise ValueError('Profile loading returned None')
129-
130-
logger.debug('Using existing default profiles')
131-
except Exception as e:
132-
logger.warning('Default profiles not available (%s), using auto-detection', str(e))
133-
# Use Conan's auto-detection to create minimal profiles
134-
profile_host = conan_api.profiles.detect()
135-
profile_build = conan_api.profiles.detect()
112+
profile_host, profile_build = self._get_profiles(conan_api)
136113

137114
path = str(conanfile_path)
138115
remotes = all_remotes
@@ -272,26 +249,7 @@ def publish(self) -> None:
272249
)
273250

274251
# Step 2: Get profiles with fallback to auto-detection
275-
try:
276-
profile_host_path = conan_api.profiles.get_default_host()
277-
profile_build_path = conan_api.profiles.get_default_build()
278-
279-
# Check if profile paths exist
280-
if profile_host_path is None or profile_build_path is None:
281-
raise ValueError('Profile paths are None')
282-
283-
# Load the actual profile objects
284-
profile_host = conan_api.profiles.get_profile([profile_host_path])
285-
profile_build = conan_api.profiles.get_profile([profile_build_path])
286-
287-
# Check if profiles are valid
288-
if profile_host is None or profile_build is None:
289-
raise ValueError('Profile loading returned None')
290-
291-
except Exception:
292-
# Use Conan's auto-detection to create minimal profiles
293-
profile_host = conan_api.profiles.detect()
294-
profile_build = conan_api.profiles.detect()
252+
profile_host, profile_build = self._get_profiles(conan_api)
295253

296254
# Step 3: Build dependency graph for the package - prepare parameters
297255
path = str(conanfile_path)
@@ -346,3 +304,42 @@ def publish(self) -> None:
346304
)
347305
else:
348306
raise ProviderInstallationError('conan', 'No packages found to upload')
307+
308+
def _get_profiles(self, conan_api: ConanAPI) -> tuple[Any, Any]:
309+
"""Get Conan profiles with fallback to auto-detection.
310+
311+
Args:
312+
conan_api: The Conan API instance
313+
314+
Returns:
315+
A tuple of (profile_host, profile_build) objects
316+
"""
317+
logger = logging.getLogger('cppython.conan')
318+
319+
try:
320+
profile_host_path = conan_api.profiles.get_default_host()
321+
profile_build_path = conan_api.profiles.get_default_build()
322+
323+
# Check if profile paths exist
324+
if profile_host_path is None or profile_build_path is None:
325+
logger.warning('Default profile paths not available, using auto-detection')
326+
raise ValueError('Profile paths are None')
327+
328+
# Load the actual profile objects
329+
profile_host = conan_api.profiles.get_profile([profile_host_path])
330+
profile_build = conan_api.profiles.get_profile([profile_build_path])
331+
332+
# Check if profiles are valid (not None)
333+
if profile_host is None or profile_build is None:
334+
logger.warning('Default profiles are corrupted/invalid, using auto-detection')
335+
raise ValueError('Profile loading returned None')
336+
337+
logger.debug('Using existing default profiles')
338+
return profile_host, profile_build
339+
340+
except Exception as e:
341+
logger.warning('Default profiles not available (%s), using auto-detection', str(e))
342+
# Use Conan's auto-detection to create minimal profiles
343+
profile_host = conan_api.profiles.detect()
344+
profile_build = conan_api.profiles.detect()
345+
return profile_host, profile_build

0 commit comments

Comments
 (0)