Skip to content

Commit fc67ca2

Browse files
committed
Update Profile Detection
1 parent 5020ad0 commit fc67ca2

File tree

3 files changed

+31
-30
lines changed

3 files changed

+31
-30
lines changed

cppython/plugins/conan/plugin.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -115,21 +115,21 @@ def _install_dependencies(self, *, update: bool = False) -> None:
115115

116116
# Ensure we have valid profile paths
117117
if profile_host_path is None:
118-
# Create a minimal default profile if none exists
119-
profile_host = conan_api.profiles.get_profile([])
118+
# Create a minimal default profile with basic settings if none exists
119+
profile_host = conan_api.profiles.detect()
120120
else:
121121
profile_host = conan_api.profiles.get_profile([profile_host_path])
122122

123123
if profile_build_path is None:
124-
# Create a minimal default profile if none exists
125-
profile_build = conan_api.profiles.get_profile([])
124+
# Create a minimal default profile with basic settings if none exists
125+
profile_build = conan_api.profiles.detect()
126126
else:
127127
profile_build = conan_api.profiles.get_profile([profile_build_path])
128128

129129
except Exception:
130-
# If profile operations fail, create minimal default profiles
131-
profile_host = conan_api.profiles.get_profile([])
132-
profile_build = conan_api.profiles.get_profile([])
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()
133133

134134
logger.debug('Using profiles: host=%s, build=%s', profile_host, profile_build)
135135

@@ -273,21 +273,21 @@ def publish(self) -> None:
273273

274274
# Ensure we have valid profile paths
275275
if profile_host_path is None:
276-
# Create a minimal default profile if none exists
277-
profile_host = conan_api.profiles.get_profile([])
276+
# Create a minimal default profile with basic settings if none exists
277+
profile_host = conan_api.profiles.detect()
278278
else:
279279
profile_host = conan_api.profiles.get_profile([profile_host_path])
280280

281281
if profile_build_path is None:
282-
# Create a minimal default profile if none exists
283-
profile_build = conan_api.profiles.get_profile([])
282+
# Create a minimal default profile with basic settings if none exists
283+
profile_build = conan_api.profiles.detect()
284284
else:
285285
profile_build = conan_api.profiles.get_profile([profile_build_path])
286286

287287
except Exception:
288-
# If profile operations fail, create minimal default profiles
289-
profile_host = conan_api.profiles.get_profile([])
290-
profile_build = conan_api.profiles.get_profile([])
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()
291291

292292
# Step 3: Build dependency graph for the package
293293
deps_graph = conan_api.graph.load_graph_consumer(

tests/fixtures/conan.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ def fixture_conan_mock_api(mocker: MockerFixture) -> Mock:
4343
mock_api.profiles.get_default_host = mocker.Mock(return_value=None)
4444
mock_api.profiles.get_default_build = mocker.Mock(return_value=None)
4545
mock_api.profiles.get_profile = mocker.Mock(return_value=mock_profile)
46+
mock_api.profiles.detect = mocker.Mock(return_value=mock_profile)
4647

4748
return mock_api
4849

@@ -90,6 +91,7 @@ def fixture_conan_mock_api_publish(mocker: MockerFixture) -> Mock:
9091
mock_api.profiles.get_default_host = mocker.Mock(return_value='/path/to/default/host')
9192
mock_api.profiles.get_default_build = mocker.Mock(return_value='/path/to/default/build')
9293
mock_api.profiles.get_profile = mocker.Mock(return_value=mock_profile)
94+
mock_api.profiles.detect = mocker.Mock(return_value=mock_profile)
9395

9496
return mock_api
9597

tests/unit/plugins/conan/test_install.py

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def test_install_conan_command_failure(
108108

109109
# Configure the API mock to fail on graph loading
110110
conan_mock_api.graph.load_graph_consumer.side_effect = Exception('Conan API error: package not found')
111-
111+
112112
# Mock ConanAPI constructor to return our configured mock
113113
mock_conan_api_constructor = mocker.patch('cppython.plugins.conan.plugin.ConanAPI', return_value=conan_mock_api)
114114

@@ -123,8 +123,7 @@ def mock_resolve(requirement: Requirement) -> ConanDependency:
123123

124124
# Execute and verify exception is raised
125125
with pytest.raises(
126-
ProviderInstallationError,
127-
match='Failed to install dependencies: Conan API error: package not found'
126+
ProviderInstallationError, match='Failed to install dependencies: Conan API error: package not found'
128127
):
129128
plugin.install()
130129

@@ -164,10 +163,10 @@ def test_install_with_profile_exception_fallback(
164163
conan_setup_mocks['conan_api_constructor'].assert_called_once()
165164
conan_mock_api.profiles.get_default_host.assert_called_once()
166165
# Note: get_default_build is not called because get_default_host throws exception first
167-
168-
# Verify fallback profile creation was called (should be called twice for empty profiles)
169-
assert conan_mock_api.profiles.get_profile.call_count >= EXPECTED_PROFILE_CALLS
170-
166+
167+
# Verify fallback profile creation was called (should be called twice for detect)
168+
assert conan_mock_api.profiles.detect.call_count >= EXPECTED_PROFILE_CALLS
169+
171170
# Verify the rest of the process continued
172171
conan_mock_api.graph.load_graph_consumer.assert_called_once()
173172
conan_mock_api.install.install_binaries.assert_called_once()
@@ -195,7 +194,7 @@ def test_publish_with_profile_exception_fallback(
195194

196195
# Configure the API mock to throw exception on first profile call
197196
conan_mock_api_publish.profiles.get_default_host.side_effect = Exception('Profile configuration error')
198-
197+
199198
# Mock ConanAPI constructor to return our configured mock
200199
mock_conan_api_constructor = mocker.patch(
201200
'cppython.plugins.conan.plugin.ConanAPI', return_value=conan_mock_api_publish
@@ -208,10 +207,10 @@ def test_publish_with_profile_exception_fallback(
208207
mock_conan_api_constructor.assert_called_once()
209208
conan_mock_api_publish.profiles.get_default_host.assert_called_once()
210209
# Note: get_default_build is not called because get_default_host throws exception first
211-
212-
# Verify fallback profile creation was called (should be called twice for empty profiles)
213-
assert conan_mock_api_publish.profiles.get_profile.call_count >= EXPECTED_PROFILE_CALLS
214-
210+
211+
# Verify fallback profile creation was called (should be called twice for detect)
212+
assert conan_mock_api_publish.profiles.detect.call_count >= EXPECTED_PROFILE_CALLS
213+
215214
# Verify the rest of the process continued
216215
conan_mock_api_publish.export.export.assert_called_once()
217216
conan_mock_api_publish.graph.load_graph_consumer.assert_called_once()
@@ -248,10 +247,10 @@ def test_install_with_second_profile_exception_fallback(
248247
conan_setup_mocks['conan_api_constructor'].assert_called_once()
249248
conan_mock_api.profiles.get_default_host.assert_called_once()
250249
conan_mock_api.profiles.get_default_build.assert_called_once()
251-
252-
# Verify fallback profile creation was called (should be called twice for empty profiles)
253-
assert conan_mock_api.profiles.get_profile.call_count >= EXPECTED_PROFILE_CALLS
254-
250+
251+
# Verify fallback profile creation was called (should be called twice for detect)
252+
assert conan_mock_api.profiles.detect.call_count >= EXPECTED_PROFILE_CALLS
253+
255254
# Verify the rest of the process continued
256255
conan_mock_api.graph.load_graph_consumer.assert_called_once()
257256
conan_mock_api.install.install_binaries.assert_called_once()

0 commit comments

Comments
 (0)