Skip to content

Commit f46fbec

Browse files
committed
Skip_Upload
1 parent 7899d31 commit f46fbec

File tree

10 files changed

+57
-30
lines changed

10 files changed

+57
-30
lines changed

cppython/plugins/conan/plugin.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ def publish(self) -> None:
247247
raise FileNotFoundError(f'conanfile.py not found at {conanfile_path}')
248248

249249
conan_api = ConanAPI()
250+
250251
all_remotes = conan_api.remotes.list()
251252

252253
# Configure remotes for upload
@@ -272,7 +273,7 @@ def publish(self) -> None:
272273
user=None,
273274
channel=None,
274275
lockfile=None,
275-
remotes=all_remotes,
276+
remotes=all_remotes, # Use all remotes for dependency resolution
276277
update=None,
277278
check_updates=False,
278279
is_build_require=False,
@@ -284,22 +285,31 @@ def publish(self) -> None:
284285
conan_api.graph.analyze_binaries(
285286
graph=deps_graph,
286287
build_mode=['*'],
287-
remotes=all_remotes,
288+
remotes=all_remotes, # Use all remotes for dependency resolution
288289
update=None,
289290
lockfile=None,
290291
)
291292

292293
conan_api.install.install_binaries(deps_graph=deps_graph, remotes=all_remotes)
293294

294-
# Upload if not local only
295-
if not self.data.local_only:
295+
if not self.data.skip_upload:
296296
self._upload_package(conan_api, ref, configured_remotes)
297297

298298
def _get_configured_remotes(self, all_remotes):
299-
"""Get and validate configured remotes for upload."""
300-
if self.data.local_only:
299+
"""Get and validate configured remotes for upload.
300+
301+
Note: This only affects upload behavior. For dependency resolution,
302+
we always use all available system remotes regardless of this config.
303+
"""
304+
# If skip_upload is True, don't upload anywhere
305+
if self.data.skip_upload:
301306
return []
302307

308+
# If no remotes specified, upload to all available remotes
309+
if not self.data.remotes:
310+
return all_remotes
311+
312+
# Otherwise, upload only to specified remotes
303313
configured_remotes = [remote for remote in all_remotes if remote.name in self.data.remotes]
304314

305315
if not configured_remotes:

cppython/plugins/conan/resolution.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ def resolve_conan_data(data: dict[str, Any], core_data: CorePluginData) -> Conan
318318

319319
return ConanData(
320320
remotes=parsed_data.remotes,
321+
skip_upload=parsed_data.skip_upload,
321322
host_profile=host_profile,
322323
build_profile=build_profile,
323324
)

cppython/plugins/conan/schema.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -293,22 +293,22 @@ class ConanData(CPPythonModel):
293293
"""Resolved conan data"""
294294

295295
remotes: list[str]
296+
skip_upload: bool
296297
host_profile: Profile
297298
build_profile: Profile
298299

299-
@property
300-
def local_only(self) -> bool:
301-
"""Check if publishing should be local-only."""
302-
return len(self.remotes) == 0
303-
304300

305301
class ConanConfiguration(CPPythonModel):
306302
"""Raw conan data"""
307303

308304
remotes: Annotated[
309305
list[str],
310-
Field(description='List of remotes to upload to. Empty list means the local conan cache will be used.'),
306+
Field(description='List of remotes to upload to. If empty, uploads to all available remotes.'),
311307
] = ['conancenter']
308+
skip_upload: Annotated[
309+
bool,
310+
Field(description='If true, skip uploading packages during publish (local-only mode).'),
311+
] = False
312312
host_profile: Annotated[
313313
str | None,
314314
Field(

tests/fixtures/conan.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Shared fixtures for Conan plugin tests"""
22

33
from pathlib import Path
4+
from typing import Any
45
from unittest.mock import Mock
56

67
import pytest
@@ -10,6 +11,24 @@
1011
from cppython.plugins.conan.plugin import ConanProvider
1112
from cppython.plugins.conan.schema import ConanDependency
1213

14+
# Shared parameterization for plugin data across all conan tests
15+
CONAN_PLUGIN_DATA_PARAMS = [
16+
{'remotes': ['conancenter'], 'skip_upload': False}, # Default behavior
17+
{'remotes': [], 'skip_upload': False}, # Empty remotes (upload to all)
18+
{'remotes': ['conancenter'], 'skip_upload': True}, # Skip upload with specific remotes
19+
{'remotes': [], 'skip_upload': True}, # Skip upload with empty remotes
20+
]
21+
22+
23+
@pytest.fixture(name='conan_plugin_data', scope='session', params=CONAN_PLUGIN_DATA_PARAMS)
24+
def fixture_conan_plugin_data(request) -> dict[str, Any]:
25+
"""Shared parameterized plugin data for conan tests
26+
27+
Returns:
28+
The constructed plugin data with different combinations of remotes and skip_upload
29+
"""
30+
return request.param
31+
1332

1433
@pytest.fixture(autouse=True)
1534
def clean_conan_cache(tmp_path: Path, monkeypatch: pytest.MonkeyPatch):

tests/integration/examples/test_conan_cmake.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def test_simple(example_runner: CliRunner) -> None:
5252

5353
# --- Setup for Publish with modified config ---
5454
# Modify the in-memory representation of the pyproject data
55-
pyproject_data['tool']['cppython']['providers']['conan']['remotes'] = []
55+
pyproject_data['tool']['cppython']['providers']['conan']['skip_upload'] = True
5656

5757
# Create a new project instance with the modified configuration for the 'publish' step
5858
publish_project = Project(project_configuration, interface, pyproject_data)

tests/unit/plugins/conan/test_install.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,13 @@ class TestConanInstall(ProviderPluginTestMixin[ConanProvider]):
2929

3030
@staticmethod
3131
@pytest.fixture(name='plugin_data', scope='session')
32-
def fixture_plugin_data() -> dict[str, Any]:
32+
def fixture_plugin_data(conan_plugin_data: dict[str, Any]) -> dict[str, Any]:
3333
"""A required testing hook that allows data generation
3434
3535
Returns:
3636
The constructed plugin data
3737
"""
38-
return {
39-
'remotes': [],
40-
}
38+
return conan_plugin_data
4139

4240
@staticmethod
4341
@pytest.fixture(name='plugin_type', scope='session')

tests/unit/plugins/conan/test_provider.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ class TestConanProvider(ProviderUnitTestContract[ConanProvider]):
1313

1414
@staticmethod
1515
@pytest.fixture(name='plugin_data', scope='session')
16-
def fixture_plugin_data() -> dict[str, Any]:
16+
def fixture_plugin_data(conan_plugin_data: dict[str, Any]) -> dict[str, Any]:
1717
"""A required testing hook that allows data generation
1818
1919
Returns:
2020
The constructed plugin data
2121
"""
22-
return {}
22+
return conan_plugin_data
2323

2424
@staticmethod
2525
@pytest.fixture(name='plugin_type', scope='session')

tests/unit/plugins/conan/test_publish.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,19 @@ def fixture_plugin_type() -> type[ConanProvider]:
4242
"""
4343
return ConanProvider
4444

45-
def test_local_only(
45+
def test_skip_upload(
4646
self, plugin: ConanProvider, conan_mock_api_publish: Mock, conan_temp_conanfile: None, mocker: MockerFixture
4747
) -> None:
48-
"""Test that publish with remotes=[] only exports and builds locally
48+
"""Test that publish with skip_upload=True only exports and builds locally
4949
5050
Args:
5151
plugin: The plugin instance
5252
conan_mock_api_publish: Mock ConanAPI for publish operations
5353
conan_temp_conanfile: Fixture to create conanfile.py
5454
mocker: Pytest mocker fixture
5555
"""
56-
# Set plugin to local mode
57-
plugin.data.remotes = []
56+
# Set plugin to skip upload mode
57+
plugin.data.skip_upload = True
5858

5959
# Mock the necessary imports and API creation
6060
mocker.patch('cppython.plugins.conan.plugin.ConanAPI', return_value=conan_mock_api_publish)
@@ -190,8 +190,8 @@ def test_with_default_profiles(
190190
conan_temp_conanfile: Fixture to create conanfile.py
191191
mocker: Pytest mocker fixture
192192
"""
193-
# Set plugin to local mode
194-
plugin.data.remotes = []
193+
# Set plugin to skip upload mode
194+
plugin.data.skip_upload = True
195195

196196
# Mock the necessary imports and API creation
197197
mocker.patch('cppython.plugins.conan.plugin.ConanAPI', return_value=conan_mock_api_publish)

tests/unit/plugins/conan/test_resolution.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ def test_null_profiles(
446446
mock_build_profile = Mock(spec=Profile)
447447
mock_resolve_profiles.return_value = (mock_host_profile, mock_build_profile)
448448

449-
data = {'host_profile': None, 'build_profile': None, 'remotes': []}
449+
data = {'host_profile': None, 'build_profile': None, 'remotes': [], 'skip_upload': False}
450450
core_data = Mock(spec=CorePluginData)
451451

452452
result = resolve_conan_data(data, core_data)
@@ -455,6 +455,7 @@ def test_null_profiles(
455455
assert result.host_profile == mock_host_profile
456456
assert result.build_profile == mock_build_profile
457457
assert result.remotes == []
458+
assert result.skip_upload is False
458459

459460
# Verify profile resolution was called with None values
460461
mock_resolve_profiles.assert_called_once_with(None, None, mock_conan_api, None)

tests/unit/plugins/conan/test_update.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,13 @@ class TestConanUpdate(ProviderPluginTestMixin[ConanProvider]):
2020

2121
@staticmethod
2222
@pytest.fixture(name='plugin_data', scope='session')
23-
def fixture_plugin_data() -> dict[str, Any]:
23+
def fixture_plugin_data(conan_plugin_data: dict[str, Any]) -> dict[str, Any]:
2424
"""A required testing hook that allows data generation
2525
2626
Returns:
2727
The constructed plugin data
2828
"""
29-
return {
30-
'remotes': [],
31-
}
29+
return conan_plugin_data
3230

3331
@staticmethod
3432
@pytest.fixture(name='plugin_type', scope='session')

0 commit comments

Comments
 (0)