Skip to content
Open
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
1 change: 1 addition & 0 deletions crates/pixi/tests/integration_rust/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@ impl PixiControl {
},
config: Default::default(),
editable: false,
channel: None,
},
}
}
Expand Down
6 changes: 5 additions & 1 deletion crates/pixi_api/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ use pixi_manifest::{
};
use pixi_pypi_spec::{PixiPypiSpec, PypiPackageName};
use pixi_spec::PixiSpec;
use rattler_conda_types::{Channel, MatchSpec, PackageName, Platform, RepoDataRecord};
use rattler_conda_types::{
Channel, MatchSpec, NamedChannelOrUrl, PackageName, Platform, RepoDataRecord,
};

use crate::interface::Interface;
use crate::workspace::add::GitOptions;
Expand Down Expand Up @@ -175,13 +177,15 @@ impl<I: Interface> WorkspaceContext<I> {
spec_type: SpecType,
dep_options: DependencyOptions,
git_options: GitOptions,
channel: Option<Vec<NamedChannelOrUrl>>,
) -> miette::Result<Option<UpdateDeps>> {
Box::pin(crate::workspace::add::add_conda_dep(
self.workspace_mut()?,
specs,
spec_type,
dep_options,
git_options,
channel,
))
.await
}
Expand Down
30 changes: 28 additions & 2 deletions crates/pixi_api/src/workspace/add/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ use pixi_core::{
environment::sanity_check_workspace,
workspace::{PypiDeps, UpdateDeps, WorkspaceMut},
};
use pixi_manifest::PrioritizedChannel;
use pixi_manifest::{FeatureName, KnownPreviewFeature, SpecType};
use pixi_spec::{GitSpec, SourceLocationSpec, SourceSpec};
use rattler_conda_types::{MatchSpec, PackageName};

use rattler_conda_types::{MatchSpec, NamedChannelOrUrl, PackageName};
use std::str::FromStr;
mod options;

pub use options::{DependencyOptions, GitOptions};
Expand All @@ -18,6 +19,7 @@ pub async fn add_conda_dep(
spec_type: SpecType,
dep_options: DependencyOptions,
git_options: GitOptions,
channel: Option<Vec<NamedChannelOrUrl>>,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

channel is now Option<Vec> as oppose to Option earlier. This helps us take url and local channel paths as part of matchspec as well.

) -> miette::Result<Option<UpdateDeps>> {
sanity_check_workspace(workspace.workspace()).await?;

Expand All @@ -29,6 +31,30 @@ pub async fn add_conda_dep(
let mut match_specs = IndexMap::default();
let mut source_specs = IndexMap::default();

// Add a channel if specified

if channel.is_some() {
for ch in channel.unwrap() {
workspace.manifest().add_channels(
[PrioritizedChannel::from(ch.clone())],
&dep_options.feature,
false,
)?;
}
}

for (_, spec) in &specs {
if let Some(channel) = spec.channel.as_ref() {
let channel = NamedChannelOrUrl::from_str(channel.as_ref().base_url.as_str()).unwrap();
workspace.manifest().add_channels(
[PrioritizedChannel::from(channel)],
&dep_options.feature,
false,
)?;
} else {
continue;
}
}
// if user passed some git configuration
// we will use it to create pixi source specs
let passed_specs: IndexMap<PackageName, (MatchSpec, SpecType)> = specs
Expand Down
6 changes: 6 additions & 0 deletions crates/pixi_cli/src/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use pixi_api::{
};
use pixi_config::ConfigCli;
use pixi_core::{DependencyType, WorkspaceLocator};
use rattler_conda_types::NamedChannelOrUrl;

use crate::{
cli_config::{DependencyConfig, LockFileUpdateConfig, NoInstallConfig, WorkspaceConfig},
Expand Down Expand Up @@ -92,6 +93,10 @@ pub struct Args {
/// Whether the pypi requirement should be editable
#[arg(long, requires = "pypi")]
pub editable: bool,

// Specify channel
#[arg(long)]
pub channel: Option<Vec<NamedChannelOrUrl>>,
}

impl TryFrom<&Args> for DependencyOptions {
Expand Down Expand Up @@ -154,6 +159,7 @@ pub async fn execute(args: Args) -> miette::Result<()> {
spec_type,
(&args).try_into()?,
git_options,
args.channel,
)
.await?
}
Expand Down
2 changes: 2 additions & 0 deletions docs/reference/cli/pixi/add.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ pixi add [OPTIONS] <SPEC>...
- <a id="arg---feature" href="#arg---feature">`--feature (-f) <FEATURE>`</a>
: The feature for which the dependency should be modified
<br>**default**: `default`
- <a id="arg---channel" href="#arg---channel">`--channel` <CHANNEL></a>
: Specify channel for the dependency
- <a id="arg---editable" href="#arg---editable">`--editable`</a>
: Whether the pypi requirement should be editable

Expand Down
93 changes: 11 additions & 82 deletions tests/integration_python/test_main_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -1380,7 +1380,7 @@ def test_add_url_no_channel(pixi: Path, tmp_pixi_workspace: Path) -> None:

verify_cli_command([pixi, "init", tmp_pixi_workspace])

# helpful error for missing channel
# verify channel can be added using matchspec syntax
verify_cli_command(
[
pixi,
Expand All @@ -1389,102 +1389,31 @@ def test_add_url_no_channel(pixi: Path, tmp_pixi_workspace: Path) -> None:
"--manifest-path",
tmp_pixi_workspace,
],
expected_exit_code=ExitCode.FAILURE,
stderr_contains="pixi workspace channel add https://repo.prefix.dev/bioconda",
)

# test channel parameter with url
verify_cli_command(
[
pixi,
"workspace",
"channel",
"add",
"https://repo.prefix.dev/bioconda",
"--manifest-path",
tmp_pixi_workspace,
],
)
# successful after adding the channel
verify_cli_command(
[
pixi,
"add",
"https://repo.prefix.dev/bioconda::snakemake-minimal",
"--manifest-path",
tmp_pixi_workspace,
],
stderr_contains="Added https://repo.prefix.dev/bioconda::snakemake-minimal",
)

# no message for initially unused feature...
verify_cli_command(
[
pixi,
"add",
"https://conda.anaconda.org/conda-forge::xz",
"--feature=prefix",
"--manifest-path",
tmp_pixi_workspace,
],
)
verify_cli_command(
[
pixi,
"workspace",
"environment",
"add",
"prefix",
"--feature=prefix",
"--manifest-path",
tmp_pixi_workspace,
],
)
# ...but decent message on install:
verify_cli_command(
[
pixi,
"install",
"--environment=prefix",
"--manifest-path",
tmp_pixi_workspace,
],
expected_exit_code=ExitCode.FAILURE,
stderr_contains="unavailable channel 'https://conda.anaconda.org/conda-forge/'",
)
# and helpful message now feature is used:
verify_cli_command(
[
pixi,
"add",
"https://conda.anaconda.org/conda-forge::libzlib",
"--feature=prefix",
"--manifest-path",
tmp_pixi_workspace,
],
expected_exit_code=ExitCode.FAILURE,
stderr_contains="pixi workspace channel add https://conda.anaconda.org/conda-forge",
)

verify_cli_command(
Comment on lines -1399 to -1468
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you remove these tests?

[
pixi,
"workspace",
"channel",
"add",
"--feature=prefix",
Comment on lines -1407 to -1474
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed these as using matchspec syntax adds the channel if not found, hence these tests are irrelevant.

"--channel",
"https://conda.anaconda.org/conda-forge",
"libzlib",
"--manifest-path",
tmp_pixi_workspace,
],
stderr_contains="Added libzlib",
)
# successful after adding the channel
# test channel parameter with name
verify_cli_command(
[
pixi,
"install",
"--environment=prefix",
"add",
"--channel",
"conda-forge",
"libzlib",
"--manifest-path",
tmp_pixi_workspace,
],
stderr_contains="The prefix environment has been installed",
stderr_contains="Added libzlib",
)
Loading