1010
1111import requests
1212from conan .api .conan_api import ConanAPI
13+ from conan .api .model import ListPattern
1314
1415from cppython .core .plugin_schema .generator import SyncConsumer
1516from cppython .core .plugin_schema .provider import Provider , ProviderPluginGroupData , SupportedProviderFeatures
@@ -123,15 +124,7 @@ async def download_tooling(cls, directory: Path) -> None:
123124 cls ._download_file (cls ._provider_url , directory / 'conan_provider.cmake' )
124125
125126 def publish (self ) -> None :
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.
131-
132- Raises:
133- ConanException: If conan operations fail
134- """
127+ """Publishes the package using conan create workflow."""
135128 # Get the project root directory where conanfile.py should be located
136129 project_root = self .core_data .project_data .project_root
137130 conanfile_path = project_root / 'conanfile.py'
@@ -142,20 +135,72 @@ def publish(self) -> None:
142135 # Initialize Conan API
143136 conan_api = ConanAPI ()
144137
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
138+ # Step 1: Export the recipe to the cache
139+ # This is equivalent to the export part of `conan create`
140+ ref , conanfile = conan_api .export .export (
141+ path = str (conanfile_path ),
142+ name = None ,
143+ version = None ,
144+ user = None ,
145+ channel = None ,
146+ lockfile = None ,
147+ remotes = conan_api .remotes .list (),
148+ )
149+
150+ # Step 2: Get default profiles
151+ profile_host , profile_build = conan_api .profiles .get_profiles_from_args ([])
152+
153+ # Step 3: Build dependency graph for the package
154+ deps_graph = conan_api .graph .load_graph_consumer (
155+ path = str (conanfile_path ),
156+ name = None ,
157+ version = None ,
158+ user = None ,
159+ channel = None ,
160+ profile_host = profile_host ,
161+ profile_build = profile_build ,
162+ lockfile = None ,
163+ remotes = conan_api .remotes .list (),
164+ update = None ,
165+ check_updates = False ,
166+ is_build_require = False ,
167+ )
168+
169+ # Step 4: Analyze binaries and install/build them if needed
170+ conan_api .graph .analyze_binaries (
171+ graph = deps_graph ,
172+ build_mode = ['*' ], # Build from source (equivalent to the create behavior)
173+ remotes = conan_api .remotes .list (),
174+ update = None ,
175+ lockfile = None ,
176+ )
177+
178+ # Step 5: Install all dependencies and build the package
179+ conan_api .install .install_binaries (deps_graph = deps_graph , remotes = conan_api .remotes .list ())
152180
153181 # If not local, upload the package
154182 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
183+ # Get all packages matching the created reference
184+ ref_pattern = ListPattern (f'{ ref .name } /*' , package_id = '*' , only_recipe = False )
185+ package_list = conan_api .list .select (ref_pattern )
186+
187+ if package_list .recipes :
188+ # Get the first configured remote or raise an error
189+ remotes = conan_api .remotes .list ()
190+ if not remotes :
191+ raise RuntimeError ('No remotes configured for upload' )
192+
193+ remote = remotes [0 ] # Use first remote
194+
195+ # Upload the package
196+ conan_api .upload .upload_full (
197+ package_list = package_list ,
198+ remote = remote ,
199+ enabled_remotes = remotes ,
200+ check_integrity = False ,
201+ force = False ,
202+ metadata = None ,
203+ dry_run = False ,
204+ )
205+ else :
206+ raise RuntimeError ('No packages found to upload' )
0 commit comments