Skip to content

Commit

Permalink
Update all dependencies as well as rattler (#321)
Browse files Browse the repository at this point in the history
* update all dependencies of pixi

* update to the latest rattler version

* fmt and clippy

* Update src/environment.rs

* bump: to latest version

* fix: rattler issue

---------

Co-authored-by: Bas Zalmstra <zalmstra.bas@gmail.com>
  • Loading branch information
wolfv and baszalmstra authored Sep 11, 2023
1 parent 1a50d8f commit eb1b64b
Show file tree
Hide file tree
Showing 17 changed files with 325 additions and 299 deletions.
333 changes: 156 additions & 177 deletions Cargo.lock

Large diffs are not rendered by default.

28 changes: 14 additions & 14 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,23 @@ slow_integration_tests = []

[dependencies]
atty = "0.2"
chrono = "0.4.26"
clap = { version = "4.3.16", default-features = false, features = ["derive", "usage", "wrap_help", "std", "color", "error-context"] }
chrono = "0.4.28"
clap = { version = "4.4.2", default-features = false, features = ["derive", "usage", "wrap_help", "std", "color", "error-context"] }
clap-verbosity-flag = "2.0.1"
clap_complete = "4.3.2"
clap_complete = "4.4.0"
console = { version = "0.15.7", features = ["windows-console-colors"] }
deno_task_shell = "0.13.2"
# deno_task_shell = { path = "../deno_task_shell" }
dirs = "5.0.1"
dunce = "1.0.4"
futures = "0.3.28"
indexmap = { version = "1.9.3", features = ["serde"] }
indicatif = "0.17.5"
indicatif = "0.17.6"
insta = { version = "1.31.0", features = ["yaml"] }
is_executable = "1.0.1"
itertools = "0.11.0"
miette = { version = "5.10.0", features = ["fancy", "supports-color", "supports-hyperlinks", "supports-unicode", "terminal_size", "textwrap"] }
minijinja = { version = "1.0.5", features = ["builtins"] }
minijinja = { version = "1.0.7", features = ["builtins"] }
once_cell = "1.18.0"
rattler = { version = "0.8.0", default-features = false }
rattler_conda_types = { version = "0.8.0", default-features = false }
Expand All @@ -43,25 +43,25 @@ rattler_repodata_gateway = { version = "0.8.0", default-features = false, featur
rattler_shell = { version = "0.8.0", default-features = false, features = ["sysinfo"] }
rattler_solve = { version = "0.8.0", default-features = false, features = ["libsolv_rs"] }
rattler_virtual_packages = { version = "0.8.0", default-features = false }
reqwest = { version = "0.11.18", default-features = false }
serde = "1.0.171"
serde_json = "1.0.103"
reqwest = { version = "0.11.20", default-features = false }
serde = "1.0.188"
serde_json = "1.0.105"
serde_spanned = "0.6.3"
serde_with = { version = "3.1.0", features = ["indexmap"] }
serde_with = { version = "3.3.0", features = ["indexmap"] }
spdx = "0.10.2"
strsim = "0.10.0"
tempfile = "3.6.0"
tokio = { version = "1.29.1", features = ["macros", "rt-multi-thread", "signal"] }
tempfile = "3.8.0"
tokio = { version = "1.32.0", features = ["macros", "rt-multi-thread", "signal"] }
tokio-util = "0.7.8"
toml_edit = { version = "0.19.14", features = ["serde"] }
tracing = "0.1.37"
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
url = "2.4.0"
url = "2.4.1"

[dev-dependencies]
rattler_digest = "0.8.0"
serde_json = "1.0.103"
tokio = { version = "1.29.1", features = ["rt"] }
serde_json = "1.0.105"
tokio = { version = "1.32.0", features = ["rt"] }
toml = "0.7.6"

[patch.crates-io]
Expand Down
20 changes: 11 additions & 9 deletions src/cli/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ use console::style;
use indexmap::IndexMap;
use itertools::Itertools;
use miette::{IntoDiagnostic, WrapErr};
use rattler_conda_types::version_spec::StrictRangeOperator;
use rattler_conda_types::PackageName;
use rattler_conda_types::{
version_spec::VersionOperator, MatchSpec, NamelessMatchSpec, Platform, Version, VersionSpec,
MatchSpec, NamelessMatchSpec, Platform, StrictVersion, Version, VersionSpec,
};
use rattler_repodata_gateway::sparse::SparseRepoData;
use rattler_solve::{libsolv_rs, SolverImpl};
Expand Down Expand Up @@ -121,7 +123,7 @@ pub async fn add_specs_to_project(
Some(name) => Ok((name.clone(), spec.into())),
None => Err(miette::miette!("missing package name for spec '{spec}'")),
})
.collect::<miette::Result<HashMap<String, NamelessMatchSpec>>>()?;
.collect::<miette::Result<HashMap<PackageName, NamelessMatchSpec>>>()?;

// Get the current specs

Expand Down Expand Up @@ -154,7 +156,7 @@ pub async fn add_specs_to_project(
Err(err) => {
return Err(err).wrap_err_with(||miette::miette!(
"could not determine any available versions for {} on {platform}. Either the package could not be found or version constraints on other dependencies result in a conflict.",
new_specs.keys().join(", ")
new_specs.keys().map(|s| s.as_source()).join(", ")
));
}
};
Expand Down Expand Up @@ -183,9 +185,9 @@ pub async fn add_specs_to_project(
.expect("a version must have been previously selected");
let updated_spec = if spec.version.is_none() {
let mut updated_spec = spec.clone();
updated_spec.version = Some(VersionSpec::Operator(
VersionOperator::StartsWith,
best_version,
updated_spec.version = Some(VersionSpec::StrictRange(
StrictRangeOperator::StartsWith,
StrictVersion(best_version),
));
updated_spec
} else {
Expand Down Expand Up @@ -256,11 +258,11 @@ pub async fn add_specs_to_project(

/// Given several specs determines the highest installable version for them.
pub fn determine_best_version(
new_specs: &HashMap<String, NamelessMatchSpec>,
current_specs: &IndexMap<String, NamelessMatchSpec>,
new_specs: &HashMap<PackageName, NamelessMatchSpec>,
current_specs: &IndexMap<PackageName, NamelessMatchSpec>,
sparse_repo_data: &[SparseRepoData],
platform: Platform,
) -> miette::Result<HashMap<String, Version>> {
) -> miette::Result<HashMap<PackageName, Version>> {
let combined_specs = current_specs
.iter()
.chain(new_specs.iter())
Expand Down
30 changes: 19 additions & 11 deletions src/cli/global/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use dirs::home_dir;
use itertools::Itertools;
use miette::IntoDiagnostic;
use rattler::install::Transaction;
use rattler_conda_types::{Channel, ChannelConfig, MatchSpec, Platform, PrefixRecord};
use rattler_conda_types::{Channel, ChannelConfig, MatchSpec, PackageName, Platform, PrefixRecord};
use rattler_networking::AuthenticatedClient;
use rattler_repodata_gateway::sparse::SparseRepoData;
use rattler_shell::{
Expand Down Expand Up @@ -80,12 +80,12 @@ pub(crate) struct BinEnvDir(pub PathBuf);

impl BinEnvDir {
/// Construct the path to the env directory for the binary package `package_name`.
fn package_bin_env_dir(package_name: &str) -> miette::Result<PathBuf> {
Ok(bin_env_dir()?.join(package_name))
fn package_bin_env_dir(package_name: &PackageName) -> miette::Result<PathBuf> {
Ok(bin_env_dir()?.join(package_name.as_normalized()))
}

/// Get the Binary Environment directory, erroring if it doesn't already exist.
pub async fn from_existing(package_name: &str) -> miette::Result<Self> {
pub async fn from_existing(package_name: &PackageName) -> miette::Result<Self> {
let bin_env_dir = Self::package_bin_env_dir(package_name)?;
if tokio::fs::try_exists(&bin_env_dir)
.await
Expand All @@ -94,13 +94,14 @@ impl BinEnvDir {
Ok(Self(bin_env_dir))
} else {
Err(miette::miette!(
"could not find environment for package {package_name}"
"could not find environment for package {}",
package_name.as_source()
))
}
}

/// Create the Binary Environment directory
pub async fn create(package_name: &str) -> miette::Result<Self> {
pub async fn create(package_name: &PackageName) -> miette::Result<Self> {
let bin_env_dir = Self::package_bin_env_dir(package_name)?;
tokio::fs::create_dir_all(&bin_env_dir)
.await
Expand All @@ -119,13 +120,13 @@ pub(crate) fn bin_env_dir() -> miette::Result<PathBuf> {
/// Find the designated package in the prefix
pub(crate) async fn find_designated_package(
prefix: &Prefix,
package_name: &str,
package_name: &PackageName,
) -> miette::Result<PrefixRecord> {
let prefix_records = prefix.find_installed_packages(None).await?;
prefix_records
.into_iter()
.find(|r| r.repodata_record.package_record.name == package_name)
.ok_or_else(|| miette::miette!("could not find {} in prefix", package_name))
.find(|r| r.repodata_record.package_record.name == *package_name)
.ok_or_else(|| miette::miette!("could not find {} in prefix", package_name.as_source()))
}

/// Create the environment activation script
Expand Down Expand Up @@ -391,7 +392,7 @@ pub async fn execute(args: Args) -> miette::Result<()> {
if scripts.is_empty() {
miette::bail!(
"could not find an executable entrypoint in package {} {} {} from {}, are you sure it exists?",
console::style(prefix_package.repodata_record.package_record.name).bold(),
console::style(prefix_package.repodata_record.package_record.name.as_source()).bold(),
console::style(prefix_package.repodata_record.package_record.version).bold(),
console::style(prefix_package.repodata_record.package_record.build).bold(),
channel,
Expand All @@ -401,7 +402,14 @@ pub async fn execute(args: Args) -> miette::Result<()> {
eprintln!(
"{}Installed package {} {} {} from {}",
console::style(console::Emoji("✔ ", "")).green(),
console::style(prefix_package.repodata_record.package_record.name).bold(),
console::style(
prefix_package
.repodata_record
.package_record
.name
.as_source()
)
.bold(),
console::style(prefix_package.repodata_record.package_record.version).bold(),
console::style(prefix_package.repodata_record.package_record.build).bold(),
channel,
Expand Down
9 changes: 6 additions & 3 deletions src/cli/global/list.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use std::collections::HashSet;
use std::fmt::Display;
use std::str::FromStr;

use clap::Parser;
use itertools::Itertools;
use miette::IntoDiagnostic;
use rattler_conda_types::PackageName;

use crate::cli::global::install::{
bin_env_dir, find_and_map_executable_scripts, find_designated_package, BinDir, BinEnvDir,
Expand All @@ -17,7 +19,7 @@ pub struct Args {}

#[derive(Debug)]
struct InstalledPackageInfo {
name: String,
name: PackageName,
binaries: Vec<String>,
}

Expand All @@ -31,7 +33,7 @@ impl Display for InstalledPackageInfo {
write!(
f,
" - [package] {}\n - {binaries}",
console::style(&self.name).bold()
console::style(&self.name.as_source()).bold()
)
}
}
Expand All @@ -50,7 +52,8 @@ pub async fn execute(_args: Args) -> miette::Result<()> {
.into_diagnostic()?;
while let Some(entry) = dir_contents.next_entry().await.into_diagnostic()? {
if entry.file_type().await.into_diagnostic()?.is_dir() {
packages.push(entry.file_name().to_string_lossy().to_string());
let Ok(name) = PackageName::from_str(entry.file_name().to_string_lossy().as_ref()) else { continue };
packages.push(name);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/cli/global/remove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ pub async fn execute(args: Args) -> miette::Result<()> {
eprintln!(
"{}Successfully removed global package {}",
console::style(console::Emoji("✔ ", "")).green(),
console::style(package_name).bold(),
console::style(package_name.as_source()).bold(),
);
} else {
let whitespace = console::Emoji(" ", "").to_string();
Expand All @@ -98,7 +98,7 @@ pub async fn execute(args: Args) -> miette::Result<()> {
.join(&format!("\n{whitespace} - "));
miette::bail!(
"got multiple errors trying to remove global package {}:\n{} - {}",
package_name,
package_name.as_source(),
whitespace,
error_string,
);
Expand Down
23 changes: 13 additions & 10 deletions src/cli/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{cmp::Ordering, path::PathBuf};
use clap::Parser;
use itertools::Itertools;
use miette::IntoDiagnostic;
use rattler_conda_types::{Channel, ChannelConfig, Platform, RepoDataRecord};
use rattler_conda_types::{Channel, ChannelConfig, PackageName, Platform, RepoDataRecord};
use rattler_repodata_gateway::sparse::SparseRepoData;
use strsim::jaro;
use tokio::task::spawn_blocking;
Expand Down Expand Up @@ -34,12 +34,12 @@ pub struct Args {

/// fetch packages from `repo_data` based on `filter_func`
fn search_package_by_filter<F>(
package: &str,
package: &PackageName,
repo_data: &[SparseRepoData],
filter_func: F,
) -> miette::Result<Vec<RepoDataRecord>>
where
F: Fn(&str, &str) -> bool,
F: Fn(&str, &PackageName) -> bool,
{
let similar_packages = repo_data
.iter()
Expand All @@ -55,7 +55,9 @@ where
// add the latest version of the fetched package to latest_packages vector
for repo in repo_data {
for package in &similar_packages {
let mut records = repo.load_records(package).into_diagnostic()?;
let mut records = repo
.load_records(&PackageName::new_unchecked(*package))
.into_diagnostic()?;
// sort records by version, get the latest one
records.sort_by(|a, b| a.package_record.version.cmp(&b.package_record.version));
let latest_package = records.last().cloned();
Expand Down Expand Up @@ -96,17 +98,18 @@ pub async fn execute(args: Args) -> miette::Result<()> {
let platforms = [Platform::current()];
let repo_data = fetch_sparse_repodata(&channels, &platforms).await?;

let p = package_name.clone();
let p = PackageName::try_from(package_name.clone()).into_diagnostic()?;
let mut packages = await_in_progress(
"searching packages",
spawn_blocking(move || {
let packages = search_package_by_filter(&p, &repo_data, |pn, n| pn.contains(n));
let packages =
search_package_by_filter(&p, &repo_data, |pn, n| pn.contains(n.as_normalized()));
match packages {
Ok(packages) => {
if packages.is_empty() {
let similarity = 0.6;
return search_package_by_filter(&p, &repo_data, |pn, n| {
jaro(pn, n) > similarity
jaro(pn, n.as_normalized()) > similarity
});
}
Ok(packages)
Expand All @@ -119,8 +122,8 @@ pub async fn execute(args: Args) -> miette::Result<()> {
.into_diagnostic()??;

packages.sort_by(|a, b| {
let ord = jaro(&b.package_record.name, &package_name)
.partial_cmp(&jaro(&a.package_record.name, &package_name));
let ord = jaro(b.package_record.name.as_normalized(), &package_name)
.partial_cmp(&jaro(a.package_record.name.as_normalized(), &package_name));
if let Some(ord) = ord {
ord
} else {
Expand Down Expand Up @@ -155,7 +158,7 @@ pub async fn execute(args: Args) -> miette::Result<()> {

println!(
"{:40} {:19} {:19}",
console::style(package_name).cyan().bright(),
console::style(package_name.as_source()).cyan().bright(),
console::style(version),
console::style(channel_name),
);
Expand Down
Loading

0 comments on commit eb1b64b

Please sign in to comment.