Skip to content

Commit 7e2ec46

Browse files
committed
Initial Publish Implementation
1 parent 9241ba2 commit 7e2ec46

File tree

1 file changed

+34
-3
lines changed

1 file changed

+34
-3
lines changed

cppython/plugins/conan/plugin.py

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from typing import Any
1010

1111
import requests
12+
from conan.api.conan_api import ConanAPI
1213

1314
from cppython.core.plugin_schema.generator import SyncConsumer
1415
from cppython.core.plugin_schema.provider import Provider, ProviderPluginGroupData, SupportedProviderFeatures
@@ -122,9 +123,39 @@ async def download_tooling(cls, directory: Path) -> None:
122123
cls._download_file(cls._provider_url, directory / 'conan_provider.cmake')
123124

124125
def publish(self) -> None:
125-
"""Updates the provider
126+
"""Publishes the package using conan create workflow.
127+
128+
Creates a Conan package and conditionally uploads it based on the 'local' configuration.
129+
If 'local' is True, only performs conan create without uploading.
130+
If 'local' is False, performs conan create and uploads to the configured remote.
126131
127132
Raises:
128-
NotImplementedError: Conan does not support publishing
133+
ConanException: If conan operations fail
129134
"""
130-
raise NotImplementedError('Conan does not support publishing')
135+
# Get the project root directory where conanfile.py should be located
136+
project_root = self.core_data.project_data.project_root
137+
conanfile_path = project_root / 'conanfile.py'
138+
139+
if not conanfile_path.exists():
140+
raise FileNotFoundError(f'conanfile.py not found at {conanfile_path}')
141+
142+
# Initialize Conan API
143+
conan_api = ConanAPI()
144+
145+
try:
146+
# Use the command API to run conan create, which is the equivalent of the subprocess call
147+
# This is the most direct replacement for subprocess.run(['conan', 'create', str(project_root)])
148+
create_cmd = f'create {project_root}'
149+
conan_api.command.run(create_cmd)
150+
except Exception as e:
151+
raise RuntimeError(f'Failed to create Conan package: {e}') from e
152+
153+
# If not local, upload the package
154+
if not self.data.local:
155+
try:
156+
# Use the command API to upload all packages
157+
# This is the equivalent of subprocess.run(['conan', 'upload', '*', '--confirm', '--all'])
158+
upload_cmd = 'upload * --confirm --all'
159+
conan_api.command.run(upload_cmd)
160+
except Exception as e:
161+
raise RuntimeError(f'Failed to upload Conan package: {e}') from e

0 commit comments

Comments
 (0)