From b7073867220271ac6ba5d2a62a316497f3b1aa7e Mon Sep 17 00:00:00 2001 From: Ruben Arts Date: Tue, 3 Oct 2023 13:51:21 +0200 Subject: fix: update the --frozen logic to error when there is no lockfile (#373) closes #371 Error when there is no lockfile and the `--frozen` option is used. --- docs/cli.mdx | 13 ++++++++++--- src/environment.rs | 15 +++++++++------ 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/docs/cli.mdx b/docs/cli.mdx index 2cfbbcf..9aa1370 100644 --- a/docs/cli.mdx +++ b/docs/cli.mdx @@ -60,7 +60,7 @@ Which gets generated on `pixi add` or when you manually change the `pixi.toml` f - `--manifest-path`: the path to `pixi.toml`, by default it searches for one in the parent directories. - `--frozen`: install the environment as defined in the lockfile. Without checking the status of the lockfile. -- `--locked`: only install if lockfile is up-to-date. Conflicts with `--frozen`. +- `--locked`: only install if the `pixi.lock` is up-to-date with the `pixi.toml`[^1]. Conflicts with `--frozen`. ```shell pixi install @@ -81,7 +81,7 @@ You cannot run `pixi run source setup.bash` as `source` is not available in the - `--manifest-path`: the path to `pixi.toml`, by default it searches for one in the parent directories. - `--frozen`: install the environment as defined in the lockfile. Without checking the status of the lockfile. -- `--locked`: only install if lockfile is up-to-date. Conflicts with `--frozen`. +- `--locked`: only install if the `pixi.lock` is up-to-date with the `pixi.toml`[^1]. Conflicts with `--frozen`. ```shell pixi run python @@ -167,7 +167,7 @@ To exit the pixi shell, simply run `exit`. - `--manifest-path`: the path to `pixi.toml`, by default it searches for one in the parent directories. - `--frozen`: install the environment as defined in the lockfile. Without checking the status of the lockfile. -- `--locked`: only install if lockfile is up-to-date. Conflicts with `--frozen`. +- `--locked`: only install if the `pixi.lock` is up-to-date with the `pixi.toml`[^1]. Conflicts with `--frozen`. ```shell pixi shell @@ -328,3 +328,10 @@ pixi project channel add file:///home/user/local_channel pixi project channel add https://repo.prefix.dev/conda-forge pixi project channel add --no-install robostack ``` + +[^1]: An __up-to-date__ lockfile means that the dependencies in the lockfile are allowed by the dependencies in the manifest file. + For example + - a `pixi.toml` with `python = ">= 3.11"` is up-to-date with a `name: python, version: 3.11.0` in the `pixi.lock`. + - a `pixi.toml` with `python = ">= 3.12"` is **not** up-to-date with a `name: python, version: 3.11.0` in the `pixi.lock`. + + Being up-to-date does **not** mean that the lockfile holds the latest version available on the channel for the given dependency. diff --git a/src/environment.rs b/src/environment.rs index 5d81585..6504434 100644 --- a/src/environment.rs +++ b/src/environment.rs @@ -74,15 +74,18 @@ pub async fn get_up_to_date_prefix( if frozen && locked { miette::bail!("Frozen and Locked can't be true at the same time, as using frozen will ignore the locked variable."); } - let lock_file = load_lock_file(project).await?; - let lock_file = if frozen || lock_file_up_to_date(project, &lock_file)? { - lock_file - } else { + if frozen && !project.lock_file_path().is_file() { + miette::bail!("No lockfile available, can't do a frozen installation."); + } + + let mut lock_file = load_lock_file(project).await?; + + if !frozen && !lock_file_up_to_date(project, &lock_file)? { if locked { miette::bail!("Lockfile not up-to-date with the project"); } - update_lock_file(project, lock_file, None).await? - }; + lock_file = update_lock_file(project, lock_file, None).await? + } // Update the environment update_prefix( -- cgit v1.2.3