|
9 | 9 | from typing import Any |
10 | 10 |
|
11 | 11 | import requests |
| 12 | +from conan.api.conan_api import ConanAPI |
12 | 13 |
|
13 | 14 | from cppython.core.plugin_schema.generator import SyncConsumer |
14 | 15 | from cppython.core.plugin_schema.provider import Provider, ProviderPluginGroupData, SupportedProviderFeatures |
@@ -122,9 +123,39 @@ async def download_tooling(cls, directory: Path) -> None: |
122 | 123 | cls._download_file(cls._provider_url, directory / 'conan_provider.cmake') |
123 | 124 |
|
124 | 125 | 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. |
126 | 131 |
|
127 | 132 | Raises: |
128 | | - NotImplementedError: Conan does not support publishing |
| 133 | + ConanException: If conan operations fail |
129 | 134 | """ |
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