Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update lock on pixi list #775

Merged
merged 3 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -296,15 +296,23 @@ List project's packages. Highlighted packages are explicit dependencies.
- `--json`: Whether to output in json format.
- `--json-pretty`: Whether to output in pretty json format
- `--sort-by <SORT_BY>`: Sorting strategy [default: name] [possible values: size, name, type]
- `--manifest-path <MANIFEST_PATH>`: the path to `pixi.toml`, by default it searches for one in the parent directories.
- `--environment`(`-e`): the environment's packages to list, if non is provided the default environment's packages will be listed.
- `--manifest-path <MANIFEST_PATH>`: The path to `pixi.toml`, by default it searches for one in the parent directories.
- `--environment`(`-e`): The environment's packages to list, if non is provided the default environment's packages will be listed.
- `--frozen`: Install the environment as defined in the lockfile. Without checking the status of the lockfile. It can also be controlled by the `PIXI_FROZEN` environment variable (example: `PIXI_FROZEN=true`).
- `--locked`: Only install if the `pixi.lock` is up-to-date with the `pixi.toml`[^1]. It can also be controlled by the `PIXI_LOCKED` environment variable (example: `PIXI_LOCKED=true`). Conflicts with `--frozen`.
- `--no-install`: Don't install the environment for pypi solving, only update the lock-file if it can solve without installing. (Implied by `--frozen` and `--locked`)

```shell

```shell
pixi list
pixi list --json-pretty
pixi list --sort-by size
pixi list --platform win-64
pixi list --environment cuda
pixi list --frozen
pixi list --locked
pixi list --no-install
```
Output will look like this, where `python` will be green as it is the package that was explicitly added to the `pixi.toml`:

Expand Down
24 changes: 17 additions & 7 deletions src/cli/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ use rattler_conda_types::Platform;
use rattler_lock::Package;
use serde::Serialize;

use crate::lock_file::load_lock_file;
use crate::project::manifest::EnvironmentName;
use crate::Project;
use crate::{Project, UpdateLockFileOptions};

// an enum to sort by size or name
#[derive(clap::ValueEnum, Clone, Debug, Serialize)]
Expand Down Expand Up @@ -53,6 +52,13 @@ pub struct Args {
/// The environment to list packages for. Defaults to the default environment.
#[arg(short, long)]
pub environment: Option<String>,

#[clap(flatten)]
pub lock_file_usage: super::LockFileUsageArgs,

/// Don't install the environment for pypi solving, only update the lock-file if it can solve without installing.
#[arg(long)]
pub no_install: bool,
}

#[derive(Serialize)]
Expand All @@ -75,16 +81,20 @@ pub async fn execute(args: Args) -> miette::Result<()> {
.environment(&environment_name)
.ok_or_else(|| miette::miette!("unknown environment '{environment_name}'"))?;

let lock_file = project
.up_to_date_lock_file(UpdateLockFileOptions {
lock_file_usage: args.lock_file_usage.into(),
no_install: args.no_install,
..UpdateLockFileOptions::default()
})
.await?;

// Load the platform
let platform = args.platform.unwrap_or_else(Platform::current);

// Load the lockfile
let lock_file = load_lock_file(&project)
.await
.map_err(|_| miette::miette!("Cannot load lockfile. Did you run `pixi install` first?"))?;

// Get all the packages in the environment.
let locked_deps = lock_file
.lock_file
.environment(environment.name().as_str())
.and_then(|env| env.packages(platform).map(Vec::from_iter))
.unwrap_or_default();
Expand Down
Loading