@@ -8,11 +8,9 @@ mod update;
88mod utils;
99
1010pub use crate :: environment:: CondaPrefixUpdater ;
11- use crate :: Workspace ;
12- use miette:: { IntoDiagnostic , WrapErr } ;
1311pub ( crate ) use package_identifier:: PypiPackageIdentifier ;
1412use pixi_record:: PixiRecord ;
15- use rattler_lock:: { LockFile , ParseCondaLockError , PypiPackageData , PypiPackageEnvironmentData } ;
13+ use rattler_lock:: { PypiPackageData , PypiPackageEnvironmentData } ;
1614pub ( crate ) use records_by_name:: { PixiRecordsByName , PypiRecordsByName } ;
1715pub ( crate ) use resolve:: {
1816 conda:: resolve_conda, pypi:: resolve_pypi, uv_resolution_context:: UvResolutionContext ,
@@ -37,57 +35,26 @@ pub type LockedPypiPackages = Vec<PypiRecord>;
3735/// data. In Pixi we basically always need both.
3836pub type PypiRecord = ( PypiPackageData , PypiPackageEnvironmentData ) ;
3937
40- /// Loads the lockfile for the specified project or returns a dummy one if none
41- /// could be found.
42- pub async fn load_lock_file ( project : & Workspace ) -> miette:: Result < LockFile > {
43- let lock_file_path = project. lock_file_path ( ) ;
44- if lock_file_path. is_file ( ) {
45- // Spawn a background task because loading the file might be IO bound.
46- tokio:: task:: spawn_blocking ( move || {
47- LockFile :: from_path ( & lock_file_path)
48- . map_err ( |err| match err {
49- ParseCondaLockError :: IncompatibleVersion { lock_file_version, max_supported_version} => {
50- miette:: miette!(
51- help="Please update pixi to the latest version and try again." ,
52- "The lock file version is {}, but only up to including version {} is supported by the current version." ,
53- lock_file_version, max_supported_version
54- )
55- }
56- _ => miette:: miette!( err) ,
57- } )
58- . wrap_err_with ( || {
59- format ! (
60- "Failed to load lock file from `{}`" ,
61- lock_file_path. display( )
62- )
63- } )
64- } )
65- . await
66- . unwrap_or_else ( |e| Err ( e) . into_diagnostic ( ) )
67- } else {
68- Ok ( LockFile :: default ( ) )
69- }
70- }
71-
7238#[ cfg( test) ]
7339mod tests {
74- use crate :: { load_lock_file , Workspace } ;
40+ use crate :: Workspace ;
7541
7642 #[ tokio:: test]
7743 async fn test_load_newer_lock_file ( ) {
7844 // Test that loading a lock file with a newer version than the current
7945 // version of pixi will return an error.
8046 let temp_dir = tempfile:: tempdir ( ) . unwrap ( ) ;
81- let project = r#"
47+ let manifest_toml = r#"
8248 [project]
8349 name = "pixi"
8450 channels = []
8551 platforms = []
8652 "# ;
87- let project =
88- Workspace :: from_str ( temp_dir. path ( ) . join ( "pixi.toml" ) . as_path ( ) , project) . unwrap ( ) ;
53+ let workspace =
54+ Workspace :: from_str ( temp_dir. path ( ) . join ( "pixi.toml" ) . as_path ( ) , manifest_toml)
55+ . unwrap ( ) ;
8956
90- let lock_file_path = project . lock_file_path ( ) ;
57+ let lock_file_path = workspace . lock_file_path ( ) ;
9158 let raw_lock_file = r#"
9259 version: 9999
9360 environments:
@@ -101,7 +68,7 @@ mod tests {
10168 . await
10269 . unwrap ( ) ;
10370
104- let err = load_lock_file ( & project ) . await . unwrap_err ( ) ;
71+ let err = & workspace . load_lock_file ( ) . await . unwrap_err ( ) ;
10572 let dbg_err = format ! ( "{:?}" , err) ;
10673 // Test that the error message contains the correct information.
10774 assert ! ( dbg_err. contains( "The lock file version is 9999, but only up to including version" ) ) ;
0 commit comments