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: add -f/--feature to the pixi project platform command #785

Merged
4 changes: 4 additions & 0 deletions docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -709,9 +709,11 @@ Adds a platform(s) to the project file and updates the lockfile.
##### Options

- `--no-install`: do not update the environment, only add changed packages to the lock-file.
- `--feature <FEATURE> (-f)`: The feature for which the platform will be added.

```sh
pixi project platform add win-64
pixi project platform add --feature test win-64
```

### `project platform list`
Expand All @@ -737,9 +739,11 @@ Remove platform(s) from the project file and updates the lockfile.
##### Options

- `--no-install`: do not update the environment, only add changed packages to the lock-file.
- `--feature <FEATURE> (-f)`: The feature for which the platform will be removed.

```sh
pixi project platform remove win-64
pixi project platform remove --feature test win-64
```

### `project version get`
Expand Down
5 changes: 4 additions & 1 deletion src/cli/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::{
consts,
environment::{get_up_to_date_prefix, verify_prefix_location_unchanged, LockFileUsage},
project::{manifest::PyPiRequirement, DependencyType, Project, SpecType},
FeatureName,
};
use clap::Parser;
use itertools::{Either, Itertools};
Expand Down Expand Up @@ -121,7 +122,9 @@ pub async fn execute(args: Args) -> miette::Result<()> {
.filter(|p| !project.platforms().contains(p))
.cloned()
.collect::<Vec<Platform>>();
project.manifest.add_platforms(platforms_to_add.iter())?;
project
.manifest
.add_platforms(platforms_to_add.iter(), &FeatureName::Default)?;

match dependency_type {
DependencyType::CondaDependency(spec_type) => {
Expand Down
35 changes: 17 additions & 18 deletions src/cli/project/platform/add.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use std::str::FromStr;

use crate::environment::{get_up_to_date_prefix, LockFileUsage};
use crate::Project;
use crate::{FeatureName, Project};
use clap::Parser;
use indexmap::IndexMap;
use itertools::Itertools;
use miette::IntoDiagnostic;
use rattler_conda_types::Platform;

Expand All @@ -17,9 +16,17 @@ pub struct Args {
/// Don't update the environment, only add changed packages to the lock-file.
#[clap(long)]
pub no_install: bool,

/// The name of the feature to add the platform to.
#[clap(long, short)]
pub feature: Option<String>,
}

pub async fn execute(mut project: Project, args: Args) -> miette::Result<()> {
let feature_name = args
.feature
.map_or(FeatureName::Default, FeatureName::Named);

// Determine which platforms are missing
let platforms = args
.platform
Expand All @@ -28,21 +35,10 @@ pub async fn execute(mut project: Project, args: Args) -> miette::Result<()> {
.collect::<Result<Vec<_>, _>>()
.into_diagnostic()?;

let missing_platforms = platforms
.into_iter()
.filter(|x| !project.platforms().contains(x))
.collect_vec();

if missing_platforms.is_empty() {
eprintln!(
"{}All platform(s) have already been added.",
console::style(console::Emoji("✔ ", "")).green(),
);
return Ok(());
}

// Add the platforms to the lock-file
project.manifest.add_platforms(missing_platforms.iter())?;
project
.manifest
.add_platforms(platforms.iter(), &feature_name)?;

// Try to update the lock-file with the new channels
get_up_to_date_prefix(
Expand All @@ -55,11 +51,14 @@ pub async fn execute(mut project: Project, args: Args) -> miette::Result<()> {
project.save()?;

// Report back to the user
for platform in missing_platforms {
for platform in platforms {
eprintln!(
"{}Added {}",
console::style(console::Emoji("✔ ", "")).green(),
platform
match &feature_name {
FeatureName::Default => platform.to_string(),
FeatureName::Named(name) => format!("{} to the feature {}", platform, name),
}
);
}

Expand Down
20 changes: 16 additions & 4 deletions src/cli/project/platform/list.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
use crate::Project;

pub async fn execute(project: Project) -> miette::Result<()> {
project.platforms().iter().for_each(|platform| {
println!("{}", platform.as_str());
});

project
.environments()
.iter()
.map(|e| {
println!(
"{} {}",
console::style("Environment:").bold().bright(),
e.name().fancy_display()
);
e.platforms()
})
.for_each(|c| {
c.into_iter().for_each(|platform| {
println!("- {}", platform.as_str());
})
});
Ok(())
}
33 changes: 15 additions & 18 deletions src/cli/project/platform/remove.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use crate::environment::{get_up_to_date_prefix, LockFileUsage};

use crate::Project;
use crate::{FeatureName, Project};
use clap::Parser;
use indexmap::IndexMap;
use itertools::Itertools;
use miette::IntoDiagnostic;
use rattler_conda_types::Platform;
use std::str::FromStr;
Expand All @@ -17,9 +16,17 @@ pub struct Args {
/// Don't update the environment, only remove the platform(s) from the lock-file.
#[clap(long)]
pub no_install: bool,

/// The name of the feature to remove the platform from.
#[clap(long, short)]
pub feature: Option<String>,
}

pub async fn execute(mut project: Project, args: Args) -> miette::Result<()> {
let feature_name = args
.feature
.map_or(FeatureName::Default, FeatureName::Named);

// Determine which platforms to remove
let platforms = args
.platform
Expand All @@ -28,23 +35,10 @@ pub async fn execute(mut project: Project, args: Args) -> miette::Result<()> {
.collect::<Result<Vec<_>, _>>()
.into_diagnostic()?;

let platforms_to_remove = platforms
.into_iter()
.filter(|x| project.platforms().contains(x))
.collect_vec();

if platforms_to_remove.is_empty() {
eprintln!(
"{}The platforms(s) are not present.",
console::style(console::Emoji("✔ ", "")).green(),
);
return Ok(());
}

// Remove the platform(s) from the manifest
project
.manifest
.remove_platforms(platforms_to_remove.iter().map(|p| p.to_string()))?;
.remove_platforms(&platforms, &feature_name)?;

get_up_to_date_prefix(
&project.default_environment(),
Expand All @@ -56,11 +50,14 @@ pub async fn execute(mut project: Project, args: Args) -> miette::Result<()> {
project.save()?;

// Report back to the user
for platform in platforms_to_remove {
for platform in platforms {
eprintln!(
"{}Removed {}",
console::style(console::Emoji("✔ ", "")).green(),
platform,
match &feature_name {
FeatureName::Default => platform.to_string(),
FeatureName::Named(name) => format!("{} from the feature {}", platform, name),
},
);
}

Expand Down
Loading
Loading