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

Feature/remove channel from feature #706

Merged
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
143 changes: 74 additions & 69 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ rattler_solve = { version = "0.16.2", default-features = false, features = ["res
rattler_virtual_packages = { version = "0.16.2", default-features = false }
regex = "1.10.3"
reqwest = { version = "0.11.23", default-features = false }
reqwest-middleware = "0.2.4"
rip = { package = "rattler_installs_packages", version = "0.4.0", default-features = false }
self-replace = "1.3.7"
serde = "1.0.195"
Expand Down
10 changes: 7 additions & 3 deletions src/cli/global/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@ use itertools::Itertools;
use miette::IntoDiagnostic;
use rattler::install::Transaction;
use rattler_conda_types::{Channel, ChannelConfig, MatchSpec, PackageName, Platform, PrefixRecord};
use rattler_networking::AuthenticatedClient;
use rattler_networking::AuthenticationMiddleware;
use rattler_repodata_gateway::sparse::SparseRepoData;
use rattler_shell::{
activation::{ActivationVariables, Activator, PathModificationBehavior},
shell::Shell,
shell::ShellEnum,
};
use rattler_solve::{resolvo, SolverImpl};
use reqwest_middleware::ClientWithMiddleware;
use std::ffi::OsStr;
use std::sync::Arc;
use std::{
path::{Path, PathBuf},
str::FromStr,
Expand Down Expand Up @@ -328,7 +330,9 @@ pub async fn execute(args: Args) -> miette::Result<()> {
.map(|c| Channel::from_str(c, &channel_config))
.collect::<Result<Vec<Channel>, _>>()
.into_diagnostic()?;
let authenticated_client = AuthenticatedClient::default();
let authenticated_client = reqwest_middleware::ClientBuilder::new(reqwest::Client::new())
.with_arc(Arc::new(AuthenticationMiddleware::default()))
.build();

// Find the MatchSpec we want to install
let package_matchspec = MatchSpec::from_str(&args.package).into_diagnostic()?;
Expand Down Expand Up @@ -395,7 +399,7 @@ pub(super) async fn globally_install_package(
package_matchspec: MatchSpec,
platform_sparse_repodata: &[SparseRepoData],
channel_config: &ChannelConfig,
authenticated_client: AuthenticatedClient,
authenticated_client: ClientWithMiddleware,
) -> miette::Result<(PrefixRecord, Vec<PathBuf>, bool)> {
let package_name = package_name(&package_matchspec)?;

Expand Down
7 changes: 5 additions & 2 deletions src/cli/global/upgrade.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use std::str::FromStr;
use std::sync::Arc;

use clap::Parser;
use miette::IntoDiagnostic;
use rattler_conda_types::{Channel, ChannelConfig, MatchSpec, Platform};
use rattler_networking::AuthenticatedClient;
use rattler_networking::AuthenticationMiddleware;

use crate::repodata::fetch_sparse_repodata;

Expand Down Expand Up @@ -54,7 +55,9 @@ pub async fn execute(args: Args) -> miette::Result<()> {
);
}

let authenticated_client = AuthenticatedClient::default();
let authenticated_client = reqwest_middleware::ClientBuilder::new(reqwest::Client::new())
.with_arc(Arc::new(AuthenticationMiddleware::default()))
.build();
// Fetch sparse repodata
let platform_sparse_repodata =
fetch_sparse_repodata(&channels, [Platform::current()], &authenticated_client).await?;
Expand Down
7 changes: 5 additions & 2 deletions src/cli/global/upgrade_all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use clap::Parser;
use futures::{stream, StreamExt, TryStreamExt};
use miette::IntoDiagnostic;
use rattler_conda_types::{Channel, ChannelConfig, Platform};
use rattler_networking::AuthenticatedClient;
use rattler_networking::AuthenticationMiddleware;
use std::sync::Arc;

use crate::repodata::fetch_sparse_repodata;

Expand Down Expand Up @@ -37,7 +38,9 @@ pub async fn execute(args: Args) -> miette::Result<()> {

let packages = list_global_packages().await?;

let authenticated_client = AuthenticatedClient::default();
let authenticated_client = reqwest_middleware::ClientBuilder::new(reqwest::Client::new())
.with_arc(Arc::new(AuthenticationMiddleware::default()))
.build();
// Fetch sparse repodata
let platform_sparse_repodata =
fetch_sparse_repodata(&channels, [Platform::current()], &authenticated_client).await?;
Expand Down
39 changes: 24 additions & 15 deletions src/cli/project/channel/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,29 @@ pub struct Args {
pub urls: bool,
}

pub async fn execute(project: Project, args: Args) -> miette::Result<()> {
project.channels().into_iter().for_each(|channel| {
if args.urls {
// Print the channel's url
println!("{}", channel.base_url());
} else {
// Print the channel's name and fallback to the url if it doesn't have one
let name = channel
.name
.as_deref()
.unwrap_or(channel.base_url().as_str());
println!("{}", name);
}
});

pub fn execute(project: Project, args: Args) -> miette::Result<()> {
project
.environments()
.iter()
.map(|e| {
println!(
"{} {}",
console::style("Environment:").bold().blue(),
console::style(e.name()).bold()
);
e.channels()
})
.for_each(|c| {
c.into_iter().for_each(|channel| {
println!(
"- {}",
if args.urls {
channel.base_url().as_str()
} else {
channel.name()
}
);
})
});
Ok(())
}
2 changes: 1 addition & 1 deletion src/cli/project/channel/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub async fn execute(args: Args) -> miette::Result<()> {

match args.command {
Command::Add(args) => add::execute(project, args).await,
Command::List(args) => list::execute(project, args).await,
Command::List(args) => list::execute(project, args),
Command::Remove(args) => remove::execute(project, args).await,
}
}
37 changes: 19 additions & 18 deletions src/cli/project/channel/remove.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use crate::environment::{get_up_to_date_prefix, LockFileUsage};

use crate::project::manifest::channel::PrioritizedChannel;
use crate::project::manifest::FeatureName;
use crate::Project;
use clap::Parser;
use itertools::Itertools;
use miette::IntoDiagnostic;
use rattler_conda_types::{Channel, ChannelConfig};

Expand All @@ -15,9 +16,17 @@ pub struct Args {
/// Don't update the environment, only remove the channel(s) from the lock-file.
#[clap(long)]
pub no_install: bool,

/// The name of the feature to remove the channel 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 channels to remove
let channel_config = ChannelConfig::default();
let channels = args
Expand All @@ -29,23 +38,15 @@ pub async fn execute(mut project: Project, args: Args) -> miette::Result<()> {
.collect::<Result<Vec<_>, _>>()
.into_diagnostic()?;

let channels_to_remove = channels
.into_iter()
.filter(|(_name, channel)| project.channels().contains(channel))
.collect_vec();

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

// Remove the channels from the manifest
project
.manifest
.remove_channels(channels_to_remove.iter().map(|(name, _channel)| name))?;
project.manifest.remove_channels(
channels
.clone()
.into_iter()
.map(|(_name, channel)| channel)
.map(PrioritizedChannel::from_channel),
&feature_name,
)?;

// Try to update the lock-file without the removed channels
get_up_to_date_prefix(
Expand All @@ -59,7 +60,7 @@ pub async fn execute(mut project: Project, args: Args) -> miette::Result<()> {
project.save()?;

// Report back to the user
for (name, channel) in channels_to_remove {
for (name, channel) in channels {
eprintln!(
"{}Removed {} ({})",
console::style(console::Emoji("✔ ", "")).green(),
Expand Down
7 changes: 5 additions & 2 deletions src/cli/search.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use std::borrow::Cow;
use std::io::{self, Write};
use std::sync::Arc;
use std::{cmp::Ordering, path::PathBuf};

use clap::Parser;
use itertools::Itertools;
use miette::IntoDiagnostic;
use rattler_conda_types::{Channel, ChannelConfig, PackageName, Platform, RepoDataRecord};
use rattler_networking::AuthenticatedClient;
use rattler_networking::AuthenticationMiddleware;
use rattler_repodata_gateway::sparse::SparseRepoData;
use regex::Regex;

Expand Down Expand Up @@ -103,7 +104,9 @@ pub async fn execute(args: Args) -> miette::Result<()> {
};

let package_name_filter = args.package;
let authenticated_client = AuthenticatedClient::default();
let authenticated_client = reqwest_middleware::ClientBuilder::new(reqwest::Client::new())
.with_arc(Arc::new(AuthenticationMiddleware::default()))
.build();
let repo_data = fetch_sparse_repodata(
channels.iter().map(AsRef::as_ref),
[Platform::current()],
Expand Down
7 changes: 5 additions & 2 deletions src/cli/upload.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use std::path::PathBuf;
use std::sync::Arc;

use clap::Parser;
use futures::TryStreamExt;
use indicatif::HumanBytes;
use miette::IntoDiagnostic;

use rattler_digest::{compute_file_digest, Sha256};
use rattler_networking::AuthenticatedClient;
use rattler_networking::AuthenticationMiddleware;

use tokio::fs::File;
use tokio_util::io::ReaderStream;
Expand Down Expand Up @@ -41,7 +42,9 @@ pub async fn execute(args: Args) -> miette::Result<()> {
HumanBytes(filesize)
);

let client = AuthenticatedClient::default();
let client = reqwest_middleware::ClientBuilder::new(reqwest::Client::new())
.with_arc(Arc::new(AuthenticationMiddleware::default()))
.build();

let sha256sum = format!(
"{:x}",
Expand Down
4 changes: 2 additions & 2 deletions src/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use itertools::Itertools;
use rattler::install::{PythonInfo, Transaction};
use rattler_conda_types::{Platform, PrefixRecord, RepoDataRecord};
use rattler_lock::{LockFile, PypiPackageData, PypiPackageEnvironmentData};
use rattler_networking::AuthenticatedClient;
use rattler_repodata_gateway::sparse::SparseRepoData;
use reqwest_middleware::ClientWithMiddleware;
use rip::index::PackageDb;
use rip::resolve::SDistResolution;
use std::error::Error;
Expand Down Expand Up @@ -422,7 +422,7 @@ impl PythonStatus {
/// Updates the environment to contain the packages from the specified lock-file
pub async fn update_prefix_conda(
prefix: &Prefix,
authenticated_client: AuthenticatedClient,
authenticated_client: ClientWithMiddleware,
installed_packages: Vec<PrefixRecord>,
repodata_records: &[RepoDataRecord],
platform: Platform,
Expand Down
6 changes: 3 additions & 3 deletions src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use rattler::install::{
};
use rattler::package_cache::PackageCache;
use rattler_conda_types::{PrefixRecord, RepoDataRecord};
use rattler_networking::AuthenticatedClient;
use reqwest_middleware::ClientWithMiddleware;
use std::cmp::Ordering;
use std::path::{Path, PathBuf};
use std::time::Duration;
Expand All @@ -23,7 +23,7 @@ pub async fn execute_transaction(
prefix_records: &[PrefixRecord],
target_prefix: PathBuf,
cache_dir: PathBuf,
download_client: AuthenticatedClient,
download_client: ClientWithMiddleware,
) -> miette::Result<()> {
// Open the package cache
let package_cache = PackageCache::new(cache_dir.join("pkgs"));
Expand Down Expand Up @@ -154,7 +154,7 @@ pub async fn execute_transaction(
#[allow(clippy::too_many_arguments)]
async fn execute_operation(
target_prefix: &Path,
download_client: AuthenticatedClient,
download_client: ClientWithMiddleware,
package_cache: &PackageCache,
install_driver: &InstallDriver,
download_pb: Option<&ProgressBarMessageFormatter>,
Expand Down
Loading
Loading