1- use std:: path:: { Path , PathBuf } ;
2-
31use clap:: { Parser , Subcommand } ;
42use clap_verbosity_flag:: { InfoLevel , Verbosity } ;
5- use miette:: { Context , IntoDiagnostic } ;
3+ use miette:: IntoDiagnostic ;
64use pixi_build_types:: {
7- BackendCapabilities , ChannelConfiguration , FrontendCapabilities , PlatformAndVirtualPackages ,
8- procedures:: {
9- conda_build_v0:: CondaBuildParams ,
10- conda_metadata:: { CondaMetadataParams , CondaMetadataResult } ,
11- initialize:: InitializeParams ,
12- negotiate_capabilities:: NegotiateCapabilitiesParams ,
13- } ,
5+ BackendCapabilities , FrontendCapabilities ,
6+ procedures:: negotiate_capabilities:: NegotiateCapabilitiesParams ,
147} ;
158use rattler_build:: console_utils:: { LoggingOutputHandler , get_default_env_filter} ;
16- use rattler_conda_types:: { ChannelConfig , GenericVirtualPackage , Platform } ;
17- use rattler_virtual_packages:: { VirtualPackage , VirtualPackageOverrides } ;
18- use tempfile:: TempDir ;
199use tracing_subscriber:: { layer:: SubscriberExt , util:: SubscriberInitExt } ;
2010
21- use crate :: {
22- consts,
23- project:: to_project_model,
24- protocol:: { Protocol , ProtocolInstantiator } ,
25- server:: Server ,
26- } ;
11+ use crate :: { protocol:: ProtocolInstantiator , server:: Server } ;
2712
2813#[ allow( missing_docs) ]
2914#[ derive( Parser ) ]
@@ -44,19 +29,6 @@ pub struct App {
4429
4530#[ derive( Subcommand , Debug ) ]
4631pub enum Commands {
47- /// Get conda metadata for a recipe.
48- GetCondaMetadata {
49- #[ clap( env, long, env = "PIXI_PROJECT_MANIFEST" , default_value = consts:: WORKSPACE_MANIFEST ) ]
50- manifest_path : PathBuf ,
51-
52- #[ clap( long) ]
53- host_platform : Option < Platform > ,
54- } ,
55- /// Build a conda package.
56- CondaBuild {
57- #[ clap( env, long, env = "PIXI_PROJECT_MANIFEST" , default_value = consts:: WORKSPACE_MANIFEST ) ]
58- manifest_path : PathBuf ,
59- } ,
6032 /// Get the capabilities of the backend.
6133 Capabilities ,
6234}
@@ -91,52 +63,22 @@ pub(crate) async fn main_impl<T: ProtocolInstantiator, F: FnOnce(LoggingOutputHa
9163 None => run_server ( args. http_port , factory) . await ,
9264 Some ( Commands :: Capabilities ) => {
9365 let backend_capabilities = capabilities :: < T > ( ) . await ?;
94- eprintln ! (
95- "Supports {}: {}" ,
96- pixi_build_types:: procedures:: conda_metadata:: METHOD_NAME ,
97- backend_capabilities
98- . provides_conda_metadata
99- . unwrap_or_default( )
100- ) ;
10166 eprintln ! (
10267 "Supports {}: {}" ,
10368 pixi_build_types:: procedures:: conda_outputs:: METHOD_NAME ,
104- backend_capabilities
105- . provides_conda_outputs
106- . unwrap_or_default( )
107- ) ;
108- eprintln ! (
109- "Supports {}: {}" ,
110- pixi_build_types:: procedures:: conda_build_v0:: METHOD_NAME ,
111- backend_capabilities
112- . provides_conda_build
113- . unwrap_or_default( )
69+ backend_capabilities. provides_conda_outputs( )
11470 ) ;
11571 eprintln ! (
11672 "Supports {}: {}" ,
11773 pixi_build_types:: procedures:: conda_build_v1:: METHOD_NAME ,
118- backend_capabilities
119- . provides_conda_build_v1
120- . unwrap_or_default( )
74+ backend_capabilities. provides_conda_build_v1( )
12175 ) ;
12276 eprintln ! (
12377 "Highest project model: {}" ,
124- backend_capabilities
125- . highest_supported_project_model
126- . map( |v| v. to_string( ) )
127- . unwrap_or_else( || String :: from( "None" ) )
78+ backend_capabilities. highest_supported_project_model( )
12879 ) ;
12980 Ok ( ( ) )
13081 }
131- Some ( Commands :: CondaBuild { manifest_path } ) => build ( factory, & manifest_path) . await ,
132- Some ( Commands :: GetCondaMetadata {
133- manifest_path,
134- host_platform,
135- } ) => {
136- let metadata = conda_get_metadata ( factory, & manifest_path, host_platform) . await ?;
137- println ! ( "{}" , serde_yaml:: to_string( & metadata) . unwrap( ) ) ;
138- Ok ( ( ) )
139- }
14082 }
14183}
14284
@@ -157,92 +99,6 @@ pub async fn main_ext<T: ProtocolInstantiator, F: FnOnce(LoggingOutputHandler) -
15799 main_impl ( factory, args) . await
158100}
159101
160- /// Negotiate the capabilities of the backend and initialize the backend.
161- async fn initialize < T : ProtocolInstantiator > (
162- factory : T ,
163- manifest_path : & Path ,
164- ) -> miette:: Result < Box < dyn Protocol + Send + Sync + ' static > > {
165- // Negotiate the capabilities of the backend.
166- let capabilities = capabilities :: < T > ( ) . await ?;
167- let channel_config = ChannelConfig :: default_with_root_dir (
168- manifest_path
169- . parent ( )
170- . expect ( "manifest should always reside in a directory" )
171- . to_path_buf ( ) ,
172- ) ;
173- let project_model = to_project_model (
174- manifest_path,
175- & channel_config,
176- capabilities. highest_supported_project_model ,
177- ) ?;
178-
179- // Check if the project model is required
180- // and if it is not present, return an error.
181- if capabilities. highest_supported_project_model . is_some ( ) && project_model. is_none ( ) {
182- miette:: bail!(
183- "Could not extract 'project_model' from: {}, while it is required" ,
184- manifest_path. display( )
185- ) ;
186- }
187-
188- // Initialize the backend
189- let ( protocol, _initialize_result) = factory
190- . initialize ( InitializeParams {
191- workspace_root : None ,
192- source_dir : None ,
193- manifest_path : manifest_path. to_path_buf ( ) ,
194- project_model,
195- cache_directory : None ,
196- configuration : None ,
197- target_configuration : None ,
198- } )
199- . await ?;
200- Ok ( protocol)
201- }
202-
203- /// Frontend implementation for getting conda metadata.
204- async fn conda_get_metadata < T : ProtocolInstantiator > (
205- factory : T ,
206- manifest_path : & Path ,
207- host_platform : Option < Platform > ,
208- ) -> miette:: Result < CondaMetadataResult > {
209- let channel_config = ChannelConfig :: default_with_root_dir (
210- manifest_path
211- . parent ( )
212- . expect ( "manifest should always reside in a directory" )
213- . to_path_buf ( ) ,
214- ) ;
215-
216- let protocol = initialize ( factory, manifest_path) . await ?;
217-
218- let virtual_packages: Vec < _ > = VirtualPackage :: detect ( & VirtualPackageOverrides :: from_env ( ) )
219- . into_diagnostic ( ) ?
220- . into_iter ( )
221- . map ( GenericVirtualPackage :: from)
222- . collect ( ) ;
223-
224- let tempdir = TempDir :: new_in ( "." )
225- . into_diagnostic ( )
226- . context ( "failed to create a temporary directory in the current directory" ) ?;
227-
228- protocol
229- . conda_get_metadata ( CondaMetadataParams {
230- build_platform : None ,
231- host_platform : host_platform. map ( |platform| PlatformAndVirtualPackages {
232- platform,
233- virtual_packages : Some ( virtual_packages. clone ( ) ) ,
234- } ) ,
235- channel_base_urls : None ,
236- channel_configuration : ChannelConfiguration {
237- base_url : channel_config. channel_alias ,
238- } ,
239- work_directory : tempdir. path ( ) . to_path_buf ( ) ,
240- variant_configuration : None ,
241- variant_files : None ,
242- } )
243- . await
244- }
245-
246102/// Returns the capabilities of the backend.
247103async fn capabilities < Factory : ProtocolInstantiator > ( ) -> miette:: Result < BackendCapabilities > {
248104 let result = Factory :: negotiate_capabilities ( NegotiateCapabilitiesParams {
@@ -252,44 +108,3 @@ async fn capabilities<Factory: ProtocolInstantiator>() -> miette::Result<Backend
252108
253109 Ok ( result. capabilities )
254110}
255-
256- /// Frontend implementation for building a conda package.
257- async fn build < T : ProtocolInstantiator > ( factory : T , manifest_path : & Path ) -> miette:: Result < ( ) > {
258- let channel_config = ChannelConfig :: default_with_root_dir (
259- manifest_path
260- . parent ( )
261- . expect ( "manifest should always reside in a directory" )
262- . to_path_buf ( ) ,
263- ) ;
264-
265- let protocol = initialize ( factory, manifest_path) . await ?;
266- let work_dir = TempDir :: new_in ( "." )
267- . into_diagnostic ( )
268- . context ( "failed to create a temporary directory in the current directory" ) ?;
269-
270- let result = protocol
271- . conda_build_v0 ( CondaBuildParams {
272- host_platform : None ,
273- build_platform_virtual_packages : None ,
274- channel_base_urls : None ,
275- channel_configuration : ChannelConfiguration {
276- base_url : channel_config. channel_alias ,
277- } ,
278- outputs : None ,
279- variant_configuration : None ,
280- variant_files : None ,
281- work_directory : work_dir. path ( ) . to_path_buf ( ) ,
282- editable : false ,
283- } )
284- . await ?;
285-
286- for package in result. packages {
287- eprintln ! ( "Successfully build '{}'" , package. output_file. display( ) ) ;
288- eprintln ! ( "Use following globs to revalidate: " ) ;
289- for glob in package. input_globs {
290- eprintln ! ( " - {glob}" ) ;
291- }
292- }
293-
294- Ok ( ( ) )
295- }
0 commit comments