Skip to content
Closed
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
4 changes: 2 additions & 2 deletions crates/pixi/tests/integration_rust/add_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use pep508_rs::MarkerTree;
use pixi_cli::cli_config::GitRev;
use pixi_consts::consts;
use pixi_core::DependencyType;
use pixi_manifest::{FeaturesExt, SpecType};
use pixi_manifest::{FeatureName, FeaturesExt, SpecType};
use pixi_pypi_spec::{PixiPypiSource, PixiPypiSpec, PypiPackageName, VersionOrStar};
use rattler_conda_types::{PackageName, Platform};
use tempfile::TempDir;
Expand Down Expand Up @@ -633,7 +633,7 @@ async fn add_unconstrained_dependency() {
let bar_spec = project
.workspace
.value
.feature("unreferenced")
.feature(&FeatureName::from("unreferenced"))
.expect("feature 'unreferenced' is missing")
.combined_dependencies(None)
.unwrap_or_default()
Expand Down
4 changes: 2 additions & 2 deletions crates/pixi/tests/integration_rust/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,7 @@ impl TasksControl<'_> {
commands: vec![],
depends_on: None,
platform: platform.map(Into::into),
feature: feature_name.non_default().map(str::to_owned),
feature: feature_name.non_default().map(FeatureName::from),
cwd: None,
default_environment: None,
env: Default::default(),
Expand All @@ -856,7 +856,7 @@ impl TasksControl<'_> {
&self,
name: TaskName,
platform: Option<Platform>,
feature_name: Option<String>,
feature_name: Option<FeatureName>,
) -> miette::Result<()> {
task::execute(task::Args {
config_source: isolated_config_source(),
Expand Down
4 changes: 2 additions & 2 deletions crates/pixi_api/src/workspace/add/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub async fn add_conda_dep(
let pixi_platforms = resolve_platforms(&workspace_platforms, &dep_options.platforms)?;
workspace
.manifest()
.add_platforms(pixi_platforms.iter(), &FeatureName::DEFAULT)?;
.add_platforms(pixi_platforms.iter(), &FeatureName::Default)?;

let mut match_specs = IndexMap::default();
let mut source_specs = IndexMap::default();
Expand Down Expand Up @@ -137,7 +137,7 @@ pub async fn add_pypi_dep(
let pixi_platforms = resolve_platforms(&workspace_platforms, &options.platforms)?;
workspace
.manifest()
.add_platforms(pixi_platforms.iter(), &FeatureName::DEFAULT)?;
.add_platforms(pixi_platforms.iter(), &FeatureName::Default)?;

// TODO: add dry_run logic to add
let dry_run = false;
Expand Down
2 changes: 1 addition & 1 deletion crates/pixi_api/src/workspace/remove/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ mod tests {

fn options() -> DependencyOptions {
DependencyOptions {
feature: FeatureName::DEFAULT,
feature: FeatureName::Default,
platforms: vec![],
no_install: true,
lock_file_usage: LockFileUsage::Frozen,
Expand Down
4 changes: 2 additions & 2 deletions crates/pixi_api/src/workspace/task/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ fn declare_platform_and_add_task(
if let Some(p) = &pixi_platform {
workspace
.manifest()
.add_platforms(std::slice::from_ref(p).iter(), &FeatureName::DEFAULT)?;
.add_platforms(std::slice::from_ref(p).iter(), &FeatureName::Default)?;
}
workspace
.manifest()
Expand Down Expand Up @@ -151,7 +151,7 @@ pub async fn alias_task<I: Interface>(
&mut workspace,
&name,
&task,
&FeatureName::DEFAULT,
&FeatureName::Default,
platform.as_ref(),
)?;
workspace.save().await.into_diagnostic()?;
Expand Down
4 changes: 3 additions & 1 deletion crates/pixi_cli/src/cli_config.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::str::FromStr;

use crate::has_specs::HasSpecs;
use clap::Parser;
use indexmap::IndexMap;
Expand Down Expand Up @@ -301,7 +303,7 @@ pub struct DependencyConfig {
pub platforms: Vec<PixiPlatformName>,

/// The feature for which the dependency should be modified.
#[clap(long, short, default_value_t)]
#[clap(long, short, default_value_t, value_parser = FeatureName::from_str)]
pub feature: FeatureName,

/// The git url to use when adding a git dependency
Expand Down
10 changes: 5 additions & 5 deletions crates/pixi_cli/src/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ pub struct Args {
pub environment: Option<String>,

/// A name for the created feature
#[clap(long, short)]
pub feature: Option<String>,
#[clap(long, short, value_parser = FeatureName::from_str)]
pub feature: Option<FeatureName>,

#[clap(flatten)]
pub config: ConfigCli,
Expand Down Expand Up @@ -87,19 +87,19 @@ pub async fn execute(args: Args) -> miette::Result<()> {
struct MissingEnvironmentName;

fn get_feature_and_environment(
feature_arg: &Option<String>,
feature_arg: &Option<FeatureName>,
environment_arg: &Option<String>,
fallback: impl Fn() -> Result<String, MissingEnvironmentName>,
) -> Result<(FeatureName, EnvironmentName), miette::Report> {
let feature_string = match (feature_arg, environment_arg) {
(Some(f), _) => f.clone(),
(Some(f), _) => f.as_str().to_string(),
(_, Some(e)) => e.clone(),
_ => fallback()?,
};

let environment_string = match (environment_arg, feature_arg) {
(Some(e), _) => e.clone(),
(_, Some(f)) => f.clone(),
(_, Some(f)) => f.as_str().to_string(),
_ => fallback()?,
};

Expand Down
2 changes: 1 addition & 1 deletion crates/pixi_cli/src/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ impl Display for EnvironmentInfo {
bold.apply_to("Features"),
self.features
.iter()
.map(|feature| feature.fancy_display())
.map(|feature| consts::FEATURE_STYLE.apply_to(feature.to_string()))
.format(", ")
)?;
if let Some(solve_group) = &self.solve_group {
Expand Down
14 changes: 7 additions & 7 deletions crates/pixi_cli/src/remove/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ pandas = "*"
&manifest,
"polars",
DependencyType::CondaDependency(SpecType::Run),
&FeatureName::DEFAULT,
&FeatureName::Default,
&[],
),
@r"
Expand All @@ -341,7 +341,7 @@ pandas = "*"
&manifest,
"ruff",
DependencyType::PypiDependency,
&FeatureName::DEFAULT,
&FeatureName::Default,
&[],
),
@r"
Expand All @@ -360,7 +360,7 @@ pandas = "*"
&manifest,
"openssl",
DependencyType::CondaDependency(SpecType::Run),
&FeatureName::DEFAULT,
&FeatureName::Default,
&[],
),
@r"
Expand All @@ -379,7 +379,7 @@ pandas = "*"
&manifest,
"cmake",
DependencyType::CondaDependency(SpecType::Run),
&FeatureName::DEFAULT,
&FeatureName::Default,
&[],
),
@r"
Expand All @@ -399,7 +399,7 @@ pandas = "*"
&manifest,
"numpy",
DependencyType::CondaDependency(SpecType::Run),
&FeatureName::DEFAULT,
&FeatureName::Default,
&[],
),
@r"
Expand All @@ -419,7 +419,7 @@ pandas = "*"
&manifest,
"polrs",
DependencyType::PypiDependency,
&FeatureName::DEFAULT,
&FeatureName::Default,
&[],
),
@r"
Expand All @@ -438,7 +438,7 @@ pandas = "*"
&manifest,
"fizzbuzz",
DependencyType::CondaDependency(SpecType::Run),
&FeatureName::DEFAULT,
&FeatureName::Default,
&[],
),
@" × dependency `fizzbuzz` was not found in dependencies"
Expand Down
20 changes: 6 additions & 14 deletions crates/pixi_cli/src/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ pub struct RemoveArgs {
pub platform: Option<PixiPlatformName>,

/// The feature for which the task should be removed.
#[arg(long, short)]
pub feature: Option<String>,
#[arg(long, short, value_parser = FeatureName::from_str)]
pub feature: Option<FeatureName>,
}

#[derive(Parser, Debug, Clone)]
Expand All @@ -81,8 +81,8 @@ pub struct AddArgs {
pub platform: Option<PixiPlatformName>,

/// The feature for which the task should be added.
#[arg(long, short)]
pub feature: Option<String>,
#[arg(long, short, value_parser = FeatureName::from_str)]
pub feature: Option<FeatureName>,

/// The working directory relative to the root of the workspace.
#[arg(long)]
Expand Down Expand Up @@ -417,10 +417,7 @@ async fn add_task(
workspace_ctx: WorkspaceContext<CliInterface>,
args: AddArgs,
) -> miette::Result<()> {
let feature = args
.clone()
.feature
.map_or_else(FeatureName::default, FeatureName::from);
let feature = args.feature.clone().unwrap_or_default();

workspace_ctx
.add_task(
Expand Down Expand Up @@ -450,12 +447,7 @@ async fn remove_tasks(
args: RemoveArgs,
) -> miette::Result<()> {
workspace_ctx
.remove_task(
args.names,
args.platform,
args.feature
.map_or_else(FeatureName::default, FeatureName::from),
)
.remove_task(args.names, args.platform, args.feature.unwrap_or_default())
.await
}

Expand Down
4 changes: 3 additions & 1 deletion crates/pixi_cli/src/upgrade.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::str::FromStr;

use std::cmp::Ordering;

use clap::Parser;
Expand Down Expand Up @@ -62,7 +64,7 @@ pub struct UpgradeSpecsArgs {
pub packages: Option<Vec<String>>,

/// The feature to update
#[clap(long = "feature", short = 'f')]
#[clap(long = "feature", short = 'f', value_parser = FeatureName::from_str)]
pub feature: Option<FeatureName>,

/// The packages which should be excluded
Expand Down
9 changes: 6 additions & 3 deletions crates/pixi_cli/src/workspace/channel.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::str::FromStr;

use std::io::Write;

use clap::Parser;
Expand All @@ -6,6 +8,7 @@ use miette::IntoDiagnostic;
use pixi_api::{WorkspaceContext, workspace::ChannelOptions};
use pixi_config::ConfigCli;
use pixi_core::WorkspaceLocator;
use pixi_manifest::FeatureName;
use rattler_conda_types::NamedChannelOrUrl;

use crate::{
Expand Down Expand Up @@ -50,8 +53,8 @@ pub struct AddRemoveArgs {
pub config: ConfigCli,

/// The name of the feature to modify.
#[clap(long, short)]
pub feature: Option<String>,
#[clap(long, short, value_parser = FeatureName::from_str)]
pub feature: Option<FeatureName>,
}

#[derive(Parser, Debug, Default, Clone)]
Expand All @@ -67,7 +70,7 @@ impl TryFrom<&AddRemoveArgs> for ChannelOptions {
fn try_from(args: &AddRemoveArgs) -> Result<Self, Self::Error> {
Ok(Self {
channels: args.channel.clone(),
feature: args.feature.clone(),
feature: args.feature.clone().map(|f| f.to_string()),
no_install: args.no_install_config.no_install,
lock_file_usage: args.lock_file_update_config.lock_file_usage()?,
})
Expand Down
3 changes: 3 additions & 0 deletions crates/pixi_cli/src/workspace/feature.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::str::FromStr;

use std::io::Write;

use clap::Parser;
Expand Down Expand Up @@ -27,6 +29,7 @@ pub struct Args {
#[derive(Parser, Debug)]
pub struct RemoveArgs {
/// The name of the feature to remove
#[clap(value_parser = FeatureName::from_str)]
pub feature: FeatureName,
}

Expand Down
24 changes: 16 additions & 8 deletions crates/pixi_cli/src/workspace/platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use pixi_api::WorkspaceContext;
use pixi_core::WorkspaceLocator;
use pixi_core::workspace::{PlatformOverrides, PlatformSource};
use pixi_manifest::{
FeaturesExt, HasWorkspaceManifest, PixiPlatform, PixiPlatformName, PlatformEdit, PlatformMove,
platform::subdir_default_virtual_packages,
FeatureName, FeaturesExt, HasWorkspaceManifest, PixiPlatform, PixiPlatformName, PlatformEdit,
PlatformMove, platform::subdir_default_virtual_packages,
};
use rattler_conda_types::{GenericVirtualPackage, PackageName, Platform, Version};
use rattler_virtual_packages::{VirtualPackageOverrides, VirtualPackages};
Expand Down Expand Up @@ -316,8 +316,8 @@ pub struct AddArgs {
pub no_install: bool,

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

#[derive(Parser, Debug)]
Expand Down Expand Up @@ -395,8 +395,8 @@ pub struct RemoveArgs {
pub no_install: bool,

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

#[derive(Parser, Debug, Default)]
Expand Down Expand Up @@ -498,7 +498,11 @@ async fn execute_add(
}

workspace_ctx
.add_platforms(platforms, args.no_install, args.feature)
.add_platforms(
platforms,
args.no_install,
args.feature.map(|f| f.to_string()),
)
.await
}

Expand Down Expand Up @@ -654,7 +658,11 @@ async fn execute_remove(
})
.collect::<miette::Result<Vec<_>>>()?;
workspace_ctx
.remove_platforms(platforms, args.no_install, args.feature)
.remove_platforms(
platforms,
args.no_install,
args.feature.map(|f| f.to_string()),
)
.await
}

Expand Down
5 changes: 5 additions & 0 deletions crates/pixi_consts/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ use url::Url;

pub const DEFAULT_ENVIRONMENT_NAME: &str = "default";
pub const DEFAULT_FEATURE_NAME: &str = DEFAULT_ENVIRONMENT_NAME;

/// Prefix of the implicit feature that is synthesized for an environment which
/// defines dependencies inline. This prefix is reserved: user-defined features
/// may not start with it.
pub const ENVIRONMENT_FEATURE_PREFIX: &str = "env:";
pub const PYPROJECT_PIXI_PREFIX: &str = "tool.pixi";

pub const WORKSPACE_MANIFEST: &str = "pixi.toml";
Expand Down
2 changes: 1 addition & 1 deletion crates/pixi_core/src/workspace/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ impl<'p> HasFeaturesIter<'p> for Environment<'p> {
let environment_features = self.environment.features.iter().map(|feature_name| {
manifest
.features
.get(&FeatureName::from(feature_name.clone()))
.get(feature_name)
.expect("feature usage should have been validated upfront")
});

Expand Down
Loading
Loading