Skip to content

Commit

Permalink
bump: rip to add scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
baszalmstra committed Nov 28, 2023
1 parent c5911d8 commit 6cfef72
Show file tree
Hide file tree
Showing 15 changed files with 91 additions and 79 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ rattler_solve = { version = "0.13.0", default-features = false, features = ["res
rattler_virtual_packages = { version = "0.13.0", default-features = false }
regex = "1.10.2"
reqwest = { version = "0.11.22", default-features = false }
rip = { package = "rattler_installs_packages", git = "https://github.com/prefix-dev/rattler_installs_packages", branch = "main", default-features = false, features = ["resolvo"] }
rip = { package = "rattler_installs_packages", git = "https://github.com/prefix-dev/rattler_installs_packages", branch = "main", default-features = false }
serde = "1.0.193"
serde_json = "1.0.108"
serde_spanned = "0.6.4"
Expand Down
2 changes: 1 addition & 1 deletion pixi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ build-docs = { cmd = "mkdocs build --strict" }
pre-commit = "~=3.3.0"

# Needed for building rattler
rust = "~=1.70.0"
rust = "~=1.73.0"
openssl = "3.*"
pkg-config = "0.29.*"
git = "2.42.0.*"
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.70.0
1.73.0
2 changes: 1 addition & 1 deletion src/cli/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ fn replace_bash_completion(script: &str) -> Cow<str> {

/// Replace the parts of the bash completion script that need different functionality.
fn replace_zsh_completion(script: &str) -> Cow<str> {
let pattern = r#"(?ms)(\(run\))(?:.*?)(_arguments.*?)(\*::task)"#;
let pattern = r"(?ms)(\(run\))(?:.*?)(_arguments.*?)(\*::task)";
// Adds tab completion to the pixi run command.
// NOTE THIS IS FORMATTED BY HAND
let zsh_replacement = r#"$1
Expand Down
16 changes: 10 additions & 6 deletions src/cli/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,15 +252,19 @@ pub async fn execute(args: Args) -> miette::Result<()> {
_ = ctrl_c => { unreachable!("Ctrl+C should not be triggered") }
};
if status_code == 127 {
let formatted: String = project
let available_tasks = project
.tasks(Some(Platform::current()))
.into_keys()
.sorted()
.map(|name| format!("\t{}\n", console::style(name).bold()))
.collect();

if !formatted.is_empty() {
eprintln!("\nAvailable tasks:\n{}", formatted);
.collect_vec();

if !available_tasks.is_empty() {
eprintln!(
"\nAvailable tasks:\n{}",
available_tasks.into_iter().format_with("\n", |name, f| {
f(&format_args!("\t{}", console::style(name).bold()))
})
);
}
}
if status_code != 0 {
Expand Down
4 changes: 2 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ pub fn get_default_author() -> Option<(String, String)> {

for line in std::str::from_utf8(&rv.stdout).ok()?.lines() {
match line.split_once(' ') {
Some((key, value)) if key == "user.email" => {
Some(("user.email", value)) => {
email = Some(value.to_string());
}
Some((key, value)) if key == "user.name" => {
Some(("user.name", value)) => {
name = Some(value.to_string());
}
_ => {}
Expand Down
30 changes: 17 additions & 13 deletions src/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,17 @@ use crate::lock_file::lock_file_satisfies_project;
use rattler::install::Transaction;
use rattler_conda_types::{Platform, PrefixRecord, RepoDataRecord};
use rattler_lock::{CondaLock, LockedDependency};
use rip::types::Artifact;
use rip::{
tags::WheelTag, Artifact, ArtifactHashes, ArtifactInfo, ArtifactName, Distribution, Extra,
InstallPaths, NormalizedPackageName, PackageDb, UnpackWheelOptions, Wheel, WheelFilename,
artifacts::{
wheel::{InstallPaths, UnpackWheelOptions},
Wheel,
},
index::PackageDb,
python_env::{find_distributions_in_venv, uninstall_distribution, Distribution, WheelTag},
types::{
ArtifactHashes, ArtifactInfo, ArtifactName, Extra, NormalizedPackageName, WheelFilename,
},
};
use std::collections::HashSet;
use std::{io::ErrorKind, path::Path, str::FromStr, time::Duration};
Expand Down Expand Up @@ -217,7 +225,7 @@ async fn update_python_distributions(
);

// Determine the current python distributions in those locations
let current_python_packages = rip::find_distributions_in_venv(prefix.root(), &install_paths)
let current_python_packages = find_distributions_in_venv(prefix.root(), &install_paths)
.into_diagnostic()
.context(
"failed to locate python packages that have not been installed as conda packages",
Expand Down Expand Up @@ -248,11 +256,7 @@ async fn update_python_distributions(
let site_package_path = install_paths.site_packages();

for python_distribution in python_distributions_to_remove {
uninstall_pixi_installed_distribution(
&prefix,
&site_package_path,
&python_distribution,
)?;
uninstall_pixi_installed_distribution(prefix, site_package_path, &python_distribution)?;
}
}

Expand Down Expand Up @@ -489,7 +493,7 @@ fn remove_old_python_distributions(
let install_paths = InstallPaths::for_venv(python_version, platform.is_windows());

// Locate the packages that are installed in the previous environment
let current_python_packages = rip::find_distributions_in_venv(prefix.root(), &install_paths)
let current_python_packages = find_distributions_in_venv(prefix.root(), &install_paths)
.into_diagnostic()
.with_context(|| format!("failed to determine the python packages installed for a previous version of python ({}.{})", python_version.0, python_version.1))?
.into_iter().filter(|d| d.installer.as_deref() != Some("conda") && d.installer.is_some()).collect_vec();
Expand All @@ -508,7 +512,7 @@ fn remove_old_python_distributions(
&python_package.name, &python_package.version
));

uninstall_pixi_installed_distribution(&prefix, &site_package_path, &python_package)?;
uninstall_pixi_installed_distribution(prefix, site_package_path, &python_package)?;

pb.inc(1);
}
Expand All @@ -518,8 +522,8 @@ fn remove_old_python_distributions(

/// Uninstalls a python distribution that was previously installed by pixi.
fn uninstall_pixi_installed_distribution(
prefix: &&Prefix,
site_package_path: &&Path,
prefix: &Prefix,
site_package_path: &Path,
python_package: &Distribution,
) -> miette::Result<()> {
tracing::info!(
Expand All @@ -536,7 +540,7 @@ fn uninstall_pixi_installed_distribution(
// should probably actually add this file to the RECORD.
let _ = std::fs::remove_file(prefix.root().join(&python_package.dist_info).join("HASH"));

rip::uninstall::uninstall_distribution(&prefix.root().join(site_package_path), relative_dist_info)
uninstall_distribution(&prefix.root().join(site_package_path), relative_dist_info)
.into_diagnostic()
.with_context(|| format!("could not uninstall python package {}-{}. Manually remove the `.pixi/env` folder and try again.", &python_package.name, &python_package.version))?;

Expand Down
33 changes: 17 additions & 16 deletions src/lock_file/package_identifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@ use super::python_name_mapping;
use pep508_rs::{Requirement, VersionOrUrl};
use rattler_conda_types::{PackageUrl, RepoDataRecord};
use rattler_lock::{LockedDependency, LockedDependencyKind};
use rip::PinnedPackage;
use rip::resolve::PinnedPackage;
use rip::types::{Extra, NormalizedPackageName, ParsePackageNameError};
use std::{collections::HashSet, str::FromStr};
use thiserror::Error;

/// Defines information about a Pypi package extracted from either a python package or from a
/// conda package.
#[derive(Debug)]
pub struct PypiPackageIdentifier {
pub name: rip::NormalizedPackageName,
pub version: rip::Version,
pub extras: HashSet<rip::Extra>,
pub name: NormalizedPackageName,
pub version: pep440_rs::Version,
pub extras: HashSet<Extra>,
}

impl PypiPackageIdentifier {
Expand Down Expand Up @@ -45,14 +46,14 @@ impl PypiPackageIdentifier {
panic!("expected conda dependency");
};

let name = rip::NormalizedPackageName::from_str(&locked_dependency.name)
let name = NormalizedPackageName::from_str(&locked_dependency.name)
.map_err(|e| ConversionError::PackageName(locked_dependency.name.clone(), e))?;
let version = rip::Version::from_str(&locked_dependency.version)
let version = pep440_rs::Version::from_str(&locked_dependency.version)
.map_err(|_| ConversionError::Version(locked_dependency.version.clone()))?;
let extras = pypi
.extras
.iter()
.map(|e| rip::Extra::from_str(e).map_err(|_| ConversionError::Extra(e.clone())))
.map(|e| Extra::from_str(e).map_err(|_| ConversionError::Extra(e.clone())))
.collect::<Result<_, _>>()?;

Ok(Self {
Expand Down Expand Up @@ -87,8 +88,8 @@ impl PypiPackageIdentifier {
if !has_pypi_purl && python_name_mapping::is_conda_forge_url(&conda.url) {
// Convert the conda package names to pypi package names. If the conversion fails we
// just assume that its not a valid python package.
let name = rip::NormalizedPackageName::from_str(&locked_dependency.name).ok();
let version = rip::Version::from_str(&locked_dependency.version).ok();
let name = NormalizedPackageName::from_str(&locked_dependency.name).ok();
let version = pep440_rs::Version::from_str(&locked_dependency.version).ok();
if let (Some(name), Some(version)) = (name, version) {
result.push(PypiPackageIdentifier {
name,
Expand Down Expand Up @@ -123,9 +124,9 @@ impl PypiPackageIdentifier {
if !has_pypi_purl && python_name_mapping::is_conda_forge_record(record) {
// Convert the conda package names to pypi package names. If the conversion fails we
// just assume that its not a valid python package.
let name =
rip::NormalizedPackageName::from_str(record.package_record.name.as_source()).ok();
let version = rip::Version::from_str(&record.package_record.version.as_str()).ok();
let name = NormalizedPackageName::from_str(record.package_record.name.as_source()).ok();
let version =
pep440_rs::Version::from_str(&record.package_record.version.as_str()).ok();
if let (Some(name), Some(version)) = (name, version) {
result.push(PypiPackageIdentifier {
name,
Expand Down Expand Up @@ -172,10 +173,10 @@ impl PypiPackageIdentifier {
) -> Result<Self, ConversionError> {
assert_eq!(package_url.package_type(), "pypi");
let name = package_url.name();
let name = rip::NormalizedPackageName::from_str(name)
let name = NormalizedPackageName::from_str(name)
.map_err(|e| ConversionError::PackageName(name.to_string(), e))?;
let version_str = package_url.version().unwrap_or(fallback_version);
let version = rip::Version::from_str(version_str)
let version = pep440_rs::Version::from_str(version_str)
.map_err(|_| ConversionError::Version(version_str.to_string()))?;

// TODO: We can't really tell which python extras are enabled from a PURL.
Expand All @@ -191,7 +192,7 @@ impl PypiPackageIdentifier {
pub fn satisfies(&self, requirement: &Requirement) -> bool {
// Parse the name of the requirement. If the name cannot be parsed to a normalized package
// the names will also not match.
let Ok(req_name) = rip::NormalizedPackageName::from_str(&requirement.name) else {
let Ok(req_name) = NormalizedPackageName::from_str(&requirement.name) else {
return false;
};

Expand Down Expand Up @@ -227,7 +228,7 @@ impl PypiPackageIdentifier {
#[derive(Error, Debug)]
pub enum ConversionError {
#[error("'{0}' is not a valid python package name")]
PackageName(String, #[source] rip::ParsePackageNameError),
PackageName(String, #[source] ParsePackageNameError),

#[error("'{0}' is not a valid python version")]
Version(String),
Expand Down
14 changes: 6 additions & 8 deletions src/lock_file/python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ use itertools::Itertools;
use miette::{Context, IntoDiagnostic};
use pep508_rs::{MarkerEnvironment, StringVersion};
use rattler_conda_types::{PackageRecord, Platform, RepoDataRecord, Version, VersionWithSource};
use rip::{
tags::{WheelTag, WheelTags},
PinnedPackage, SDistResolution,
};
use rip::python_env::{WheelTag, WheelTags};
use rip::resolve::{resolve, PinnedPackage, ResolveOptions, SDistResolution};
use std::{collections::HashMap, str::FromStr, vec};

/// Resolve python packages for the specified project.
Expand Down Expand Up @@ -79,7 +77,7 @@ pub async fn resolve_pypi_dependencies<'p>(
.collect::<Vec<pep508_rs::Requirement>>();

// Resolve the PyPi dependencies
let mut result = rip::resolve(
let mut result = resolve(
project.pypi_package_db()?,
&requirements,
&marker_environment,
Expand All @@ -89,7 +87,7 @@ pub async fn resolve_pypi_dependencies<'p>(
.map(|p| (p.name.clone(), p))
.collect(),
HashMap::default(),
&rip::ResolveOptions {
&ResolveOptions {
// TODO: Change this once we fully support sdists.
sdist_resolution: SDistResolution::OnlyWheels,
},
Expand Down Expand Up @@ -209,7 +207,7 @@ fn project_platform_tags(

tags.append(&mut compatible_tags(&python_record.version, &platforms).collect());

WheelTags::from_iter(tags.into_iter())
WheelTags::from_iter(tags)
}

fn project_platforms(platform: Platform, system_requirements: &SystemRequirements) -> Vec<String> {
Expand Down Expand Up @@ -447,7 +445,7 @@ where
PIter::IntoIter: Clone + 'a,
{
py_interpreter_range(python_version)
.cartesian_product(platforms.into_iter())
.cartesian_product(platforms)
.map(|(interpreter, platform)| WheelTag {
interpreter,
abi: String::from("none"),
Expand Down
4 changes: 2 additions & 2 deletions src/lock_file/python_name_mapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ struct CondaPyPiNameMapping {
/// Downloads and caches the conda-forge conda-to-pypi name mapping.
pub async fn conda_pypi_name_mapping() -> miette::Result<&'static HashMap<String, String>> {
static MAPPING: OnceCell<HashMap<String, String>> = OnceCell::new();
MAPPING.get_or_try_init((|| async {
MAPPING.get_or_try_init(async {
let response = reqwest::get("https://raw.githubusercontent.com/regro/cf-graph-countyfair/master/mappings/pypi/name_mapping.json").await
.into_diagnostic()
.context("failed to download pypi name mapping")?;
Expand All @@ -28,7 +28,7 @@ pub async fn conda_pypi_name_mapping() -> miette::Result<&'static HashMap<String
.map(|m| (m.conda_name, m.pypi_name))
.collect();
Ok(mapping_by_name)
})()).await
}).await
}

/// Updates the specified repodata record to include an optional PyPI package name if it is missing.
Expand Down
Loading

0 comments on commit 6cfef72

Please sign in to comment.