From 56ff0f5a6be1aab2781c88b596645691e30d0aeb Mon Sep 17 00:00:00 2001 From: nichmor Date: Wed, 7 Feb 2024 12:37:52 +0200 Subject: [PATCH 01/19] feat: add support for stree installing --- .../src/artifacts/sdist.rs | 53 +++- ...__tests__get_whl_for_local_stree_rich.snap | 236 ++++++++++++++++++ .../src/artifacts/stree.rs | 1 + .../src/artifacts/wheel.rs | 6 +- .../src/index/direct_url/file.rs | 56 +++-- .../src/index/direct_url/git.rs | 15 +- .../src/index/direct_url/http.rs | 29 ++- .../src/index/git_interop.rs | 36 ++- .../src/index/mod.rs | 2 + .../src/index/package_database.rs | 33 ++- .../src/types/artifact_name.rs | 49 ++++ .../src/types/mod.rs | 4 +- crates/rip_bin/src/main.rs | 3 +- .../dev_folder_with_rich/rich/__init__.py | 173 +------------ 14 files changed, 471 insertions(+), 225 deletions(-) create mode 100644 crates/rattler_installs_packages/src/artifacts/snapshots/rattler_installs_packages__artifacts__sdist__tests__get_whl_for_local_stree_rich.snap diff --git a/crates/rattler_installs_packages/src/artifacts/sdist.rs b/crates/rattler_installs_packages/src/artifacts/sdist.rs index 2d643397..356517c5 100644 --- a/crates/rattler_installs_packages/src/artifacts/sdist.rs +++ b/crates/rattler_installs_packages/src/artifacts/sdist.rs @@ -19,7 +19,7 @@ use zip::ZipArchive; /// Represents a source distribution artifact. pub struct SDist { /// Name of the source distribution - name: SDistFilename, + pub name: SDistFilename, /// Source dist archive file: parking_lot::Mutex>, @@ -134,6 +134,12 @@ impl SDist { pub fn lock_data(&self) -> parking_lot::MutexGuard> { self.file.lock() } + + /// Get a lock on the inner data + pub fn set_name(&mut self, name: SDistFilename) -> miette::Result<()> { + self.name = name; + Ok(()) + } } impl HasArtifactName for SDist { @@ -883,4 +889,49 @@ mod tests { assert_debug_snapshot!(wheel_metadata.1); } + + #[tokio::test(flavor = "multi_thread")] + pub async fn get_whl_for_local_stree_rich() { + let path = Path::new(env!("CARGO_MANIFEST_DIR")) + .join("../../test-data/stree/dev_folder_with_rich"); + + let url = Url::from_file_path(path.canonicalize().unwrap()).unwrap(); + + let package_db = get_package_db(); + let env_markers = Arc::new(Pep508EnvMakers::from_env().await.unwrap().0); + let wheel_builder = WheelBuilder::new( + package_db.0.clone(), + env_markers, + None, + ResolveOptions::default(), + HashMap::default(), + ) + .unwrap(); + + let norm_name = PackageName::from_str("rich").unwrap(); + let stree_file_name = STreeFilename { + distribution: norm_name, + version: Version::from_str("0.0.0").unwrap(), + url: url.clone(), + }; + + let artifact_info = ArtifactInfo { + filename: ArtifactName::STree(stree_file_name), + url: url, + hashes: None, + requires_python: None, + dist_info_metadata: DistInfoMetadata::default(), + yanked: Yanked::default(), + }; + + let whl = package_db + .0 + .get_wheel(&artifact_info, Some(&wheel_builder)) + .await + .unwrap(); + + let whl_metadata = whl.metadata().unwrap(); + + assert_debug_snapshot!(whl_metadata.1); + } } diff --git a/crates/rattler_installs_packages/src/artifacts/snapshots/rattler_installs_packages__artifacts__sdist__tests__get_whl_for_local_stree_rich.snap b/crates/rattler_installs_packages/src/artifacts/snapshots/rattler_installs_packages__artifacts__sdist__tests__get_whl_for_local_stree_rich.snap new file mode 100644 index 00000000..4e6fdbce --- /dev/null +++ b/crates/rattler_installs_packages/src/artifacts/snapshots/rattler_installs_packages__artifacts__sdist__tests__get_whl_for_local_stree_rich.snap @@ -0,0 +1,236 @@ +--- +source: crates/rattler_installs_packages/src/artifacts/sdist.rs +expression: whl_metadata.1 +--- +WheelCoreMetadata { + name: PackageName { + source: "rich", + normalized: "rich", + }, + version: Version { + epoch: 0, + release: [ + 13, + 6, + 0, + ], + pre: None, + post: None, + dev: None, + local: None, + }, + metadata_version: MetadataVersion( + Version { + epoch: 0, + release: [ + 2, + 1, + ], + pre: None, + post: None, + dev: None, + local: None, + }, + ), + requires_dist: [ + Requirement { + name: "ipywidgets", + extras: None, + version_or_url: Some( + VersionSpecifier( + VersionSpecifiers( + [ + VersionSpecifier { + operator: GreaterThanEqual, + version: Version { + epoch: 0, + release: [ + 7, + 5, + 1, + ], + pre: None, + post: None, + dev: None, + local: None, + }, + }, + VersionSpecifier { + operator: LessThan, + version: Version { + epoch: 0, + release: [ + 9, + ], + pre: None, + post: None, + dev: None, + local: None, + }, + }, + ], + ), + ), + ), + marker: Some( + Expression( + MarkerExpression { + l_value: Extra, + operator: Equal, + r_value: QuotedString( + "jupyter", + ), + }, + ), + ), + }, + Requirement { + name: "markdown-it-py", + extras: None, + version_or_url: Some( + Url( + Url { + scheme: "git+https", + cannot_be_a_base: false, + username: "", + password: None, + host: Some( + Domain( + "github.com", + ), + ), + port: None, + path: "/executablebooks/markdown-it-py.git", + query: None, + fragment: None, + }, + ), + ), + marker: None, + }, + Requirement { + name: "pygments", + extras: None, + version_or_url: Some( + VersionSpecifier( + VersionSpecifiers( + [ + VersionSpecifier { + operator: GreaterThanEqual, + version: Version { + epoch: 0, + release: [ + 2, + 13, + 0, + ], + pre: None, + post: None, + dev: None, + local: None, + }, + }, + VersionSpecifier { + operator: LessThan, + version: Version { + epoch: 0, + release: [ + 3, + 0, + 0, + ], + pre: None, + post: None, + dev: None, + local: None, + }, + }, + ], + ), + ), + ), + marker: None, + }, + Requirement { + name: "typing-extensions", + extras: None, + version_or_url: Some( + VersionSpecifier( + VersionSpecifiers( + [ + VersionSpecifier { + operator: GreaterThanEqual, + version: Version { + epoch: 0, + release: [ + 4, + 0, + 0, + ], + pre: None, + post: None, + dev: None, + local: None, + }, + }, + VersionSpecifier { + operator: LessThan, + version: Version { + epoch: 0, + release: [ + 5, + 0, + ], + pre: None, + post: None, + dev: None, + local: None, + }, + }, + ], + ), + ), + ), + marker: Some( + Expression( + MarkerExpression { + l_value: MarkerEnvVersion( + PythonVersion, + ), + operator: LessThan, + r_value: QuotedString( + "3.9", + ), + }, + ), + ), + }, + ], + requires_python: Some( + VersionSpecifiers( + [ + VersionSpecifier { + operator: GreaterThanEqual, + version: Version { + epoch: 0, + release: [ + 3, + 7, + 0, + ], + pre: None, + post: None, + dev: None, + local: None, + }, + }, + ], + ), + ), + extras: { + Extra { + source: "jupyter", + normalized: "jupyter", + }, + }, +} diff --git a/crates/rattler_installs_packages/src/artifacts/stree.rs b/crates/rattler_installs_packages/src/artifacts/stree.rs index 3952ae67..79cf0918 100644 --- a/crates/rattler_installs_packages/src/artifacts/stree.rs +++ b/crates/rattler_installs_packages/src/artifacts/stree.rs @@ -1,3 +1,4 @@ +// use crate::index::Location; use crate::resolve::PypiVersion; use crate::types::ArtifactFromSource; use crate::types::ReadPyProjectError; diff --git a/crates/rattler_installs_packages/src/artifacts/wheel.rs b/crates/rattler_installs_packages/src/artifacts/wheel.rs index 254c3f01..a2df6867 100644 --- a/crates/rattler_installs_packages/src/artifacts/wheel.rs +++ b/crates/rattler_installs_packages/src/artifacts/wheel.rs @@ -44,7 +44,8 @@ use crate::win::launcher::{build_windows_launcher, LauncherType, WindowsLauncher /// See the [Reference Page](https://packaging.python.org/en/latest/specifications/binary-distribution-format/#binary-distribution-format) /// for more information. pub struct Wheel { - name: WheelFilename, + /// Name of wheel + pub name: WheelFilename, archive: Mutex>>, } @@ -652,10 +653,13 @@ impl Wheel { python_executable: &Path, options: &UnpackWheelOptions, ) -> Result { + println!("BEFORE GET VITALS"); let vitals = self .get_vitals() .map_err(UnpackError::FailedToParseWheelVitals)?; + println!("AFTER GET VITALS"); + let transformer = WheelPathTransformer { data: vitals.data, root_is_purelib: vitals.root_is_purelib, diff --git a/crates/rattler_installs_packages/src/index/direct_url/file.rs b/crates/rattler_installs_packages/src/index/direct_url/file.rs index fad828a0..55ecb764 100644 --- a/crates/rattler_installs_packages/src/index/direct_url/file.rs +++ b/crates/rattler_installs_packages/src/index/direct_url/file.rs @@ -1,9 +1,10 @@ use crate::artifacts::{SDist, STree, Wheel}; +// use crate::index::git_interop::Location; use crate::index::package_database::DirectUrlArtifactResponse; use crate::resolve::PypiVersion; use crate::types::{ - ArtifactFromBytes, ArtifactHashes, ArtifactInfo, ArtifactName, DistInfoMetadata, - HasArtifactName, NormalizedPackageName, PackageName, SDistFilename, SDistFormat, STreeFilename, + ArtifactFromBytes, ArtifactHashes, ArtifactInfo, ArtifactType, DistInfoMetadata, + NormalizedPackageName, PackageName, SDistFilename, SDistFormat, STreeFilename, WheelCoreMetadata, Yanked, }; use crate::wheel_builder::{WheelBuildError, WheelBuilder}; @@ -23,7 +24,7 @@ pub(crate) async fn get_sdist_from_file_path( normalized_package_name: &NormalizedPackageName, path: &PathBuf, wheel_builder: &WheelBuilder, -) -> miette::Result<((Vec, WheelCoreMetadata), ArtifactName)> { +) -> miette::Result<((Vec, WheelCoreMetadata), SDist)> { let distribution = PackageName::from(normalized_package_name.clone()); let path_str = if let Some(path_str) = path.as_os_str().to_str() { @@ -47,7 +48,7 @@ pub(crate) async fn get_sdist_from_file_path( let file = File::open(path).into_diagnostic()?; - let dummy_sdist = SDist::from_bytes(dummy_sdist_file_name, Box::new(file))?; + let mut dummy_sdist = SDist::from_bytes(dummy_sdist_file_name, Box::new(file))?; let wheel_metadata = wheel_builder .get_sdist_metadata(&dummy_sdist) @@ -61,9 +62,9 @@ pub(crate) async fn get_sdist_from_file_path( format, }; - let filename = ArtifactName::SDist(sdist_filename.clone()); + dummy_sdist.name = sdist_filename; - Ok((wheel_metadata, filename)) + Ok((wheel_metadata, dummy_sdist)) } /// Return an stree from file path @@ -72,7 +73,7 @@ pub(crate) async fn get_stree_from_file_path( url: Url, path: Option, wheel_builder: &WheelBuilder, -) -> miette::Result<((Vec, WheelCoreMetadata), ArtifactName)> { +) -> miette::Result<((Vec, WheelCoreMetadata), STree)> { let distribution = PackageName::from(normalized_package_name.clone()); let path = match path { None => PathBuf::from_str(url.path()).into_diagnostic()?, @@ -88,23 +89,29 @@ pub(crate) async fn get_stree_from_file_path( url: url.clone(), }; - let stree = STree { + let mut stree = STree { name: stree_file_name, location: Mutex::new(path), }; + println!("BEFORE GET SDIST METADATA"); + let wheel_metadata = wheel_builder .get_sdist_metadata(&stree) .await .into_diagnostic()?; + println!("AFTER SDIST METADATA"); + let stree_file_name = STreeFilename { distribution: wheel_metadata.1.name.clone(), version: wheel_metadata.1.version.clone(), url: url.clone(), }; - Ok((wheel_metadata, ArtifactName::STree(stree_file_name))) + stree.name = stree_file_name; + + Ok((wheel_metadata, stree)) } /// Get artifact by file URL @@ -126,31 +133,37 @@ pub(crate) async fn get_artifacts_and_metadata>( let normalized_package_name = p.into(); - let (metadata_bytes, metadata, artifact_name) = if path.is_file() && str_name.ends_with(".whl") - { + let (metadata_bytes, metadata, artifact) = if path.is_file() && str_name.ends_with(".whl") { + eprintln!("BEFORE FROM PATH"); let wheel = Wheel::from_path(&path, &normalized_package_name) .map_err(|e| WheelBuildError::Error(format!("Could not build wheel: {}", e))) .into_diagnostic()?; + eprintln!("AFTER FROM PATH"); + let (data_bytes, metadata) = wheel.metadata()?; - ( - data_bytes, - metadata, - ArtifactName::Wheel(wheel.name().clone()), - ) + (data_bytes, metadata, ArtifactType::Wheel(wheel)) } else if path.is_file() { - let (wheel_metadata, name) = + let (wheel_metadata, sdist) = get_sdist_from_file_path(&normalized_package_name, &path, wheel_builder).await?; - (wheel_metadata.0, wheel_metadata.1, name) + ( + wheel_metadata.0, + wheel_metadata.1, + ArtifactType::SDist(sdist), + ) } else { - let (wheel_metadata, name) = get_stree_from_file_path( + let (wheel_metadata, stree) = get_stree_from_file_path( &normalized_package_name, url.clone(), Some(path), wheel_builder, ) .await?; - (wheel_metadata.0, wheel_metadata.1, name) + ( + wheel_metadata.0, + wheel_metadata.1, + ArtifactType::STree(stree), + ) }; let artifact_hash = { @@ -162,7 +175,7 @@ pub(crate) async fn get_artifacts_and_metadata>( }; let artifact_info = Arc::new(ArtifactInfo { - filename: artifact_name, + filename: artifact.name(), url: url.clone(), hashes: Some(artifact_hash), requires_python: metadata.requires_python.clone(), @@ -177,5 +190,6 @@ pub(crate) async fn get_artifacts_and_metadata>( artifact_info, metadata: (metadata_bytes, metadata), artifact_versions: result, + artifact, }) } diff --git a/crates/rattler_installs_packages/src/index/direct_url/git.rs b/crates/rattler_installs_packages/src/index/direct_url/git.rs index a72cf479..352ac692 100644 --- a/crates/rattler_installs_packages/src/index/direct_url/git.rs +++ b/crates/rattler_installs_packages/src/index/direct_url/git.rs @@ -1,13 +1,15 @@ use crate::index::git_interop::{git_clone, GitSource, ParsedUrl}; use crate::index::package_database::DirectUrlArtifactResponse; use crate::resolve::PypiVersion; -use crate::types::{ArtifactHashes, ArtifactInfo, DistInfoMetadata, NormalizedPackageName, Yanked}; +use crate::types::{ + ArtifactHashes, ArtifactInfo, ArtifactName, ArtifactType, DistInfoMetadata, HasArtifactName, + NormalizedPackageName, Yanked, +}; use crate::wheel_builder::WheelBuilder; use indexmap::IndexMap; use miette::IntoDiagnostic; use rattler_digest::{compute_bytes_digest, Sha256}; use std::sync::Arc; -use tempfile::tempdir; use url::Url; /// Get artifact by git reference @@ -25,9 +27,7 @@ pub(crate) async fn get_artifacts_and_metadata>( rev: parsed_url.revision, }; - let temp_dir = tempdir().unwrap(); - - let mut location = git_clone(&git_source, &temp_dir).into_diagnostic()?; + let mut location = git_clone(&git_source).into_diagnostic()?; if let Some(subdirectory) = parsed_url.subdirectory { location.push(&subdirectory); @@ -40,7 +40,7 @@ pub(crate) async fn get_artifacts_and_metadata>( } }; - let (wheel_metadata, filename) = super::file::get_stree_from_file_path( + let (wheel_metadata, artifact) = super::file::get_stree_from_file_path( &normalized_package_name, url.clone(), Some(location), @@ -65,7 +65,7 @@ pub(crate) async fn get_artifacts_and_metadata>( }; let artifact_info = Arc::new(ArtifactInfo { - filename, + filename: ArtifactName::STree(artifact.name().clone()), url: url.clone(), hashes: Some(project_hash), requires_python, @@ -80,5 +80,6 @@ pub(crate) async fn get_artifacts_and_metadata>( artifact_info, metadata: (wheel_metadata.0, wheel_metadata.1), artifact_versions: result, + artifact: ArtifactType::STree(artifact), }) } diff --git a/crates/rattler_installs_packages/src/index/direct_url/http.rs b/crates/rattler_installs_packages/src/index/direct_url/http.rs index 34f1a0e8..9ba238f0 100644 --- a/crates/rattler_installs_packages/src/index/direct_url/http.rs +++ b/crates/rattler_installs_packages/src/index/direct_url/http.rs @@ -3,9 +3,8 @@ use crate::index::http::Http; use crate::index::{parse_hash, CacheMode}; use crate::resolve::PypiVersion; use crate::types::{ - ArtifactFromBytes, ArtifactHashes, ArtifactInfo, ArtifactName, DistInfoMetadata, - HasArtifactName, NormalizedPackageName, PackageName, SDistFilename, SDistFormat, - WheelCoreMetadata, Yanked, + ArtifactFromBytes, ArtifactHashes, ArtifactInfo, ArtifactType, DistInfoMetadata, + NormalizedPackageName, PackageName, SDistFilename, SDistFormat, WheelCoreMetadata, Yanked, }; use crate::utils::ReadAndSeek; use crate::wheel_builder::WheelBuilder; @@ -62,23 +61,26 @@ pub(crate) async fn get_artifacts_and_metadata>( assert_eq!(hash, artifact_hash); }; - let (filename, metadata_bytes, metadata) = if str_name.ends_with(".whl") { + let (metadata_bytes, metadata, artifact) = if str_name.ends_with(".whl") { let wheel = Wheel::from_url_and_bytes(url.path(), &normalized_package_name, bytes)?; - let filename = ArtifactName::Wheel(wheel.name().clone()); let (data_bytes, metadata) = wheel.metadata()?; - (filename, data_bytes, metadata) + (data_bytes, metadata, ArtifactType::Wheel(wheel)) } else { - let (wheel_metadata, filename) = + let (wheel_metadata, sdist) = get_sdist_from_bytes(&normalized_package_name, url.clone(), bytes, wheel_builder) .await?; - (filename, wheel_metadata.0, wheel_metadata.1) + ( + wheel_metadata.0, + wheel_metadata.1, + ArtifactType::SDist(sdist), + ) }; let artifact_info = Arc::new(ArtifactInfo { - filename, + filename: artifact.name(), url: url.clone(), hashes: Some(artifact_hash), requires_python: metadata.requires_python.clone(), @@ -93,6 +95,7 @@ pub(crate) async fn get_artifacts_and_metadata>( artifact_info, metadata: (metadata_bytes, metadata), artifact_versions: result, + artifact, }) } @@ -102,7 +105,7 @@ async fn get_sdist_from_bytes( url: Url, bytes: Box, wheel_builder: &WheelBuilder, -) -> miette::Result<((Vec, WheelCoreMetadata), ArtifactName)> { +) -> miette::Result<((Vec, WheelCoreMetadata), SDist)> { // it's probably an sdist let distribution = PackageName::from(normalized_package_name.clone()); let version = Version::from_str("0.0.0").expect("0.0.0 version should always be parseable"); @@ -118,7 +121,7 @@ async fn get_sdist_from_bytes( // we don't know the version for artifact until we extract the actual metadata // so we create a plain sdist object aka dummy // and populate it with correct metadata after calling `get_sdist_metadata` - let dummy_sdist = SDist::from_bytes(dummy_sdist_file_name, Box::new(bytes))?; + let mut dummy_sdist = SDist::from_bytes(dummy_sdist_file_name, Box::new(bytes))?; let wheel_metadata = wheel_builder .get_sdist_metadata(&dummy_sdist) @@ -131,7 +134,7 @@ async fn get_sdist_from_bytes( version: wheel_metadata.1.version.clone(), format, }; - let filename = ArtifactName::SDist(sdist_filename.clone()); + dummy_sdist.name = sdist_filename; - Ok((wheel_metadata, filename)) + Ok((wheel_metadata, dummy_sdist)) } diff --git a/crates/rattler_installs_packages/src/index/git_interop.rs b/crates/rattler_installs_packages/src/index/git_interop.rs index 1184d9aa..d889f493 100644 --- a/crates/rattler_installs_packages/src/index/git_interop.rs +++ b/crates/rattler_installs_packages/src/index/git_interop.rs @@ -1,4 +1,5 @@ use std::collections::HashMap; +use std::env::temp_dir; use std::fmt; use std::{ fmt::{Display, Formatter}, @@ -12,7 +13,6 @@ use fs_extra::dir::remove; use miette::IntoDiagnostic; use regex::Regex; use serde::{Deserialize, Serialize}; -use tempfile::TempDir; use url::Url; /// A Git repository URL or a local path to a Git repository @@ -300,8 +300,28 @@ fn get_revision_sha(dest: &PathBuf, rev: Option) -> Result Self { +// let tmp = tempdir().unwrap(); +// Self{ +// cache_dir: tmp, +// location: path +// } +// } +// } + /// Fetch the git repository specified by the given source and place it in the cache directory. -pub fn git_clone(source: &GitSource, tmp_dir: &TempDir) -> Result { +pub fn git_clone(source: &GitSource) -> Result { // test if git is available locally as we fetch the git from PATH, if !Command::new("git") .arg("--version") @@ -314,8 +334,11 @@ pub fn git_clone(source: &GitSource, tmp_dir: &TempDir) -> Result (|| Some(url.path_segments()?.last()?.to_string()))() @@ -435,5 +458,10 @@ pub fn git_clone(source: &GitSource, tmp_dir: &TempDir) -> Result, pub(crate) artifact_versions: VersionArtifacts, pub(crate) metadata: (Vec, WheelCoreMetadata), + pub(crate) artifact: ArtifactType, } impl PackageDb { @@ -232,7 +233,35 @@ impl PackageDb { ) -> miette::Result { // TODO: add support for this currently there are not saved if artifact_info.is::() { - miette::bail!("STree artifacts are not supported"); + if let Some(builder) = builder { + let stree_name = artifact_info + .filename + .as_inner::() + .unwrap_or_else(|| { + panic!( + "the specified artifact '{}' does not refer to type requested to read", + artifact_info.filename + ) + }); + + let response = super::direct_url::fetch_artifact_and_metadata_by_direct_url( + &self.http, + stree_name.distribution.clone(), + artifact_info.url.clone(), + builder, + ) + .await?; + + let stree = response + .artifact + .as_stree() + .expect("the request artifact does not refer to stree"); + + let built = builder.build_wheel(stree).await.into_diagnostic(); + return built; + } else { + miette::bail!("cannot build wheel without a wheel builder"); + } } // Try to build the wheel for this SDist if possible diff --git a/crates/rattler_installs_packages/src/types/artifact_name.rs b/crates/rattler_installs_packages/src/types/artifact_name.rs index 9c679f18..b3dc2912 100644 --- a/crates/rattler_installs_packages/src/types/artifact_name.rs +++ b/crates/rattler_installs_packages/src/types/artifact_name.rs @@ -1,4 +1,5 @@ use super::{NormalizedPackageName, PackageName, ParsePackageNameError}; +use crate::artifacts::{SDist, STree, Wheel}; use crate::python_env::WheelTag; use crate::types::Version; use itertools::Itertools; @@ -530,6 +531,54 @@ impl InnerAsArtifactName for STreeFilename { } } +/// Enum that contains all artifacts types +pub enum ArtifactType { + /// Wheel artifact + Wheel(Wheel), + /// Sdist artifact + SDist(SDist), + /// STree artifact + STree(STree), +} + +impl ArtifactType { + /// Return the name of artifact + pub fn name(&self) -> ArtifactName { + match self { + ArtifactType::Wheel(artifact) => ArtifactName::Wheel(artifact.name.clone()), + ArtifactType::SDist(artifact) => ArtifactName::SDist(artifact.name.clone()), + ArtifactType::STree(artifact) => ArtifactName::STree(artifact.name.clone()), + } + } + + /// Returns this artifact as wheel + pub fn as_wheel(&self) -> Option<&Wheel> { + match self { + ArtifactType::Wheel(wheel) => Some(wheel), + ArtifactType::SDist(_) => None, + ArtifactType::STree(_) => None, + } + } + + /// Returns this name as a wheel name + pub fn as_sdist(&self) -> Option<&SDist> { + match self { + ArtifactType::Wheel(_) => None, + ArtifactType::STree(_) => None, + ArtifactType::SDist(sdist) => Some(sdist), + } + } + + /// Returns this name as a source tree name + pub fn as_stree(&self) -> Option<&STree> { + match self { + ArtifactType::Wheel(_) => None, + ArtifactType::STree(name) => Some(name), + ArtifactType::SDist(_) => None, + } + } +} + #[cfg(test)] mod test { use super::*; diff --git a/crates/rattler_installs_packages/src/types/mod.rs b/crates/rattler_installs_packages/src/types/mod.rs index 93ef4f6d..8e084bd6 100644 --- a/crates/rattler_installs_packages/src/types/mod.rs +++ b/crates/rattler_installs_packages/src/types/mod.rs @@ -22,8 +22,8 @@ mod rfc822ish; pub use artifact::{ArtifactFromBytes, ArtifactFromSource, HasArtifactName, ReadPyProjectError}; pub use artifact_name::{ - ArtifactName, BuildTag, InnerAsArtifactName, ParseArtifactNameError, SDistFilename, - SDistFormat, STreeFilename, SourceArtifactName, WheelFilename, + ArtifactName, ArtifactType, BuildTag, InnerAsArtifactName, ParseArtifactNameError, + SDistFilename, SDistFormat, STreeFilename, SourceArtifactName, WheelFilename, }; pub use direct_url_json::{DirectUrlHashes, DirectUrlJson, DirectUrlSource, DirectUrlVcs}; diff --git a/crates/rip_bin/src/main.rs b/crates/rip_bin/src/main.rs index c8e30f5b..9871fe31 100644 --- a/crates/rip_bin/src/main.rs +++ b/crates/rip_bin/src/main.rs @@ -303,8 +303,7 @@ async fn actual_main() -> miette::Result<()> { let artifact_info = pinned_package.artifacts.first().unwrap(); let artifact = package_db .get_wheel(artifact_info, Some(&wheel_builder)) - .await - .expect("could not get artifact"); + .await?; venv.install_wheel(&artifact, &UnpackWheelOptions::default()) .into_diagnostic()?; } diff --git a/test-data/stree/dev_folder_with_rich/rich/__init__.py b/test-data/stree/dev_folder_with_rich/rich/__init__.py index b631d544..fd64f6dd 100644 --- a/test-data/stree/dev_folder_with_rich/rich/__init__.py +++ b/test-data/stree/dev_folder_with_rich/rich/__init__.py @@ -1,177 +1,6 @@ """Rich text and beautiful formatting in the terminal.""" -import os -from typing import IO, TYPE_CHECKING, Any, Callable, Optional, Union - -from ._extension import load_ipython_extension # noqa: F401 - -__all__ = ["get_console", "reconfigure", "print", "inspect", "print_json"] - -if TYPE_CHECKING: - from .console import Console - -# Global console used by alternative print -_console: Optional["Console"] = None - -try: - _IMPORT_CWD = os.path.abspath(os.getcwd()) -except FileNotFoundError: - # Can happen if the cwd has been deleted - _IMPORT_CWD = "" - - -def get_console() -> "Console": - """Get a global :class:`~rich.console.Console` instance. This function is used when Rich requires a Console, - and hasn't been explicitly given one. - - Returns: - Console: A console instance. - """ - global _console - if _console is None: - from .console import Console - - _console = Console() - - return _console - - -def reconfigure(*args: Any, **kwargs: Any) -> None: - """Reconfigures the global console by replacing it with another. - - Args: - *args (Any): Positional arguments for the replacement :class:`~rich.console.Console`. - **kwargs (Any): Keyword arguments for the replacement :class:`~rich.console.Console`. - """ - from rich.console import Console - - new_console = Console(*args, **kwargs) - _console = get_console() - _console.__dict__ = new_console.__dict__ - - -def print( - *objects: Any, - sep: str = " ", - end: str = "\n", - file: Optional[IO[str]] = None, - flush: bool = False, -) -> None: - r"""Print object(s) supplied via positional arguments. - This function has an identical signature to the built-in print. - For more advanced features, see the :class:`~rich.console.Console` class. - - Args: - sep (str, optional): Separator between printed objects. Defaults to " ". - end (str, optional): Character to write at end of output. Defaults to "\\n". - file (IO[str], optional): File to write to, or None for stdout. Defaults to None. - flush (bool, optional): Has no effect as Rich always flushes output. Defaults to False. - - """ - from .console import Console - - write_console = get_console() if file is None else Console(file=file) - return write_console.print(*objects, sep=sep, end=end) - - -def print_json( - json: Optional[str] = None, - *, - data: Any = None, - indent: Union[None, int, str] = 2, - highlight: bool = True, - skip_keys: bool = False, - ensure_ascii: bool = False, - check_circular: bool = True, - allow_nan: bool = True, - default: Optional[Callable[[Any], Any]] = None, - sort_keys: bool = False, -) -> None: - """Pretty prints JSON. Output will be valid JSON. - - Args: - json (str): A string containing JSON. - data (Any): If json is not supplied, then encode this data. - indent (int, optional): Number of spaces to indent. Defaults to 2. - highlight (bool, optional): Enable highlighting of output: Defaults to True. - skip_keys (bool, optional): Skip keys not of a basic type. Defaults to False. - ensure_ascii (bool, optional): Escape all non-ascii characters. Defaults to False. - check_circular (bool, optional): Check for circular references. Defaults to True. - allow_nan (bool, optional): Allow NaN and Infinity values. Defaults to True. - default (Callable, optional): A callable that converts values that can not be encoded - in to something that can be JSON encoded. Defaults to None. - sort_keys (bool, optional): Sort dictionary keys. Defaults to False. - """ - - get_console().print_json( - json, - data=data, - indent=indent, - highlight=highlight, - skip_keys=skip_keys, - ensure_ascii=ensure_ascii, - check_circular=check_circular, - allow_nan=allow_nan, - default=default, - sort_keys=sort_keys, - ) - - -def inspect( - obj: Any, - *, - console: Optional["Console"] = None, - title: Optional[str] = None, - help: bool = False, - methods: bool = False, - docs: bool = True, - private: bool = False, - dunder: bool = False, - sort: bool = True, - all: bool = False, - value: bool = True, -) -> None: - """Inspect any Python object. - - * inspect() to see summarized info. - * inspect(, methods=True) to see methods. - * inspect(, help=True) to see full (non-abbreviated) help. - * inspect(, private=True) to see private attributes (single underscore). - * inspect(, dunder=True) to see attributes beginning with double underscore. - * inspect(, all=True) to see all attributes. - - Args: - obj (Any): An object to inspect. - title (str, optional): Title to display over inspect result, or None use type. Defaults to None. - help (bool, optional): Show full help text rather than just first paragraph. Defaults to False. - methods (bool, optional): Enable inspection of callables. Defaults to False. - docs (bool, optional): Also render doc strings. Defaults to True. - private (bool, optional): Show private attributes (beginning with underscore). Defaults to False. - dunder (bool, optional): Show attributes starting with double underscore. Defaults to False. - sort (bool, optional): Sort attributes alphabetically. Defaults to True. - all (bool, optional): Show all attributes. Defaults to False. - value (bool, optional): Pretty print value. Defaults to True. - """ - _console = console or get_console() - from rich._inspect import Inspect - - # Special case for inspect(inspect) - is_inspect = obj is inspect - - _inspect = Inspect( - obj, - title=title, - help=is_inspect or help, - methods=is_inspect or methods, - docs=is_inspect or docs, - private=private, - dunder=dunder, - sort=sort, - all=all, - value=value, - ) - _console.print(_inspect) - +print("HEY IMPORTING IT IT's working") if __name__ == "__main__": # pragma: no cover print("Hello, **World**") From 2967c933289321aad78ce82870e13ea923aff241 Mon Sep 17 00:00:00 2001 From: nichmor Date: Wed, 7 Feb 2024 12:50:50 +0200 Subject: [PATCH 02/19] misc: remove comments --- .../src/artifacts/sdist.rs | 6 ----- .../src/artifacts/stree.rs | 1 - .../src/artifacts/wheel.rs | 3 --- .../src/index/direct_url/file.rs | 8 ------ .../src/index/git_interop.rs | 25 ------------------- .../src/index/mod.rs | 2 -- 6 files changed, 45 deletions(-) diff --git a/crates/rattler_installs_packages/src/artifacts/sdist.rs b/crates/rattler_installs_packages/src/artifacts/sdist.rs index 356517c5..2dbe43da 100644 --- a/crates/rattler_installs_packages/src/artifacts/sdist.rs +++ b/crates/rattler_installs_packages/src/artifacts/sdist.rs @@ -134,12 +134,6 @@ impl SDist { pub fn lock_data(&self) -> parking_lot::MutexGuard> { self.file.lock() } - - /// Get a lock on the inner data - pub fn set_name(&mut self, name: SDistFilename) -> miette::Result<()> { - self.name = name; - Ok(()) - } } impl HasArtifactName for SDist { diff --git a/crates/rattler_installs_packages/src/artifacts/stree.rs b/crates/rattler_installs_packages/src/artifacts/stree.rs index 79cf0918..3952ae67 100644 --- a/crates/rattler_installs_packages/src/artifacts/stree.rs +++ b/crates/rattler_installs_packages/src/artifacts/stree.rs @@ -1,4 +1,3 @@ -// use crate::index::Location; use crate::resolve::PypiVersion; use crate::types::ArtifactFromSource; use crate::types::ReadPyProjectError; diff --git a/crates/rattler_installs_packages/src/artifacts/wheel.rs b/crates/rattler_installs_packages/src/artifacts/wheel.rs index a2df6867..fb9ab4ba 100644 --- a/crates/rattler_installs_packages/src/artifacts/wheel.rs +++ b/crates/rattler_installs_packages/src/artifacts/wheel.rs @@ -653,13 +653,10 @@ impl Wheel { python_executable: &Path, options: &UnpackWheelOptions, ) -> Result { - println!("BEFORE GET VITALS"); let vitals = self .get_vitals() .map_err(UnpackError::FailedToParseWheelVitals)?; - println!("AFTER GET VITALS"); - let transformer = WheelPathTransformer { data: vitals.data, root_is_purelib: vitals.root_is_purelib, diff --git a/crates/rattler_installs_packages/src/index/direct_url/file.rs b/crates/rattler_installs_packages/src/index/direct_url/file.rs index 55ecb764..a292ce49 100644 --- a/crates/rattler_installs_packages/src/index/direct_url/file.rs +++ b/crates/rattler_installs_packages/src/index/direct_url/file.rs @@ -1,5 +1,4 @@ use crate::artifacts::{SDist, STree, Wheel}; -// use crate::index::git_interop::Location; use crate::index::package_database::DirectUrlArtifactResponse; use crate::resolve::PypiVersion; use crate::types::{ @@ -94,15 +93,11 @@ pub(crate) async fn get_stree_from_file_path( location: Mutex::new(path), }; - println!("BEFORE GET SDIST METADATA"); - let wheel_metadata = wheel_builder .get_sdist_metadata(&stree) .await .into_diagnostic()?; - println!("AFTER SDIST METADATA"); - let stree_file_name = STreeFilename { distribution: wheel_metadata.1.name.clone(), version: wheel_metadata.1.version.clone(), @@ -134,13 +129,10 @@ pub(crate) async fn get_artifacts_and_metadata>( let normalized_package_name = p.into(); let (metadata_bytes, metadata, artifact) = if path.is_file() && str_name.ends_with(".whl") { - eprintln!("BEFORE FROM PATH"); let wheel = Wheel::from_path(&path, &normalized_package_name) .map_err(|e| WheelBuildError::Error(format!("Could not build wheel: {}", e))) .into_diagnostic()?; - eprintln!("AFTER FROM PATH"); - let (data_bytes, metadata) = wheel.metadata()?; (data_bytes, metadata, ArtifactType::Wheel(wheel)) } else if path.is_file() { diff --git a/crates/rattler_installs_packages/src/index/git_interop.rs b/crates/rattler_installs_packages/src/index/git_interop.rs index d889f493..6d1c8b3a 100644 --- a/crates/rattler_installs_packages/src/index/git_interop.rs +++ b/crates/rattler_installs_packages/src/index/git_interop.rs @@ -300,26 +300,6 @@ fn get_revision_sha(dest: &PathBuf, rev: Option) -> Result Self { -// let tmp = tempdir().unwrap(); -// Self{ -// cache_dir: tmp, -// location: path -// } -// } -// } - /// Fetch the git repository specified by the given source and place it in the cache directory. pub fn git_clone(source: &GitSource) -> Result { // test if git is available locally as we fetch the git from PATH, @@ -458,10 +438,5 @@ pub fn git_clone(source: &GitSource) -> Result { } } - // let loc = Location{ - // cache_dir: tmp_dir, - // location: cache_path - // }; - Ok(cache_path) } diff --git a/crates/rattler_installs_packages/src/index/mod.rs b/crates/rattler_installs_packages/src/index/mod.rs index 5c853a72..88a73c2b 100644 --- a/crates/rattler_installs_packages/src/index/mod.rs +++ b/crates/rattler_installs_packages/src/index/mod.rs @@ -12,7 +12,5 @@ mod package_sources; pub use package_database::{ArtifactRequest, PackageDb}; pub use package_sources::{PackageSources, PackageSourcesBuilder}; -// pub use git_interop::Location; - pub use self::http::CacheMode; pub use html::parse_hash; From 63a5254ce034fa05adc6a65482bd5300e0c31bdd Mon Sep 17 00:00:00 2001 From: nichmor Date: Wed, 7 Feb 2024 12:51:53 +0200 Subject: [PATCH 03/19] misc: remove tmpdir --- crates/rattler_installs_packages/src/index/git_interop.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/rattler_installs_packages/src/index/git_interop.rs b/crates/rattler_installs_packages/src/index/git_interop.rs index 6d1c8b3a..93ba5f1f 100644 --- a/crates/rattler_installs_packages/src/index/git_interop.rs +++ b/crates/rattler_installs_packages/src/index/git_interop.rs @@ -314,7 +314,6 @@ pub fn git_clone(source: &GitSource) -> Result { )); } - // let tmp_dir = tempdir().unwrap(); let tmp_dir = temp_dir(); let cache_dir = tmp_dir.join("rip-git-cache"); From e30cebc6675c922cc2016cc6b18628331fb4104d Mon Sep 17 00:00:00 2001 From: nichmor Date: Wed, 7 Feb 2024 13:30:58 +0200 Subject: [PATCH 04/19] misc: use tmpdir --- crates/rattler_installs_packages/src/index/git_interop.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/crates/rattler_installs_packages/src/index/git_interop.rs b/crates/rattler_installs_packages/src/index/git_interop.rs index 93ba5f1f..72fcec8b 100644 --- a/crates/rattler_installs_packages/src/index/git_interop.rs +++ b/crates/rattler_installs_packages/src/index/git_interop.rs @@ -1,5 +1,4 @@ use std::collections::HashMap; -use std::env::temp_dir; use std::fmt; use std::{ fmt::{Display, Formatter}, @@ -314,7 +313,7 @@ pub fn git_clone(source: &GitSource) -> Result { )); } - let tmp_dir = temp_dir(); + let tmp_dir = tempfile::tempdir().unwrap().into_path(); let cache_dir = tmp_dir.join("rip-git-cache"); let recipe_dir = tmp_dir.join("rip-clone-dir"); From f21839d088e1ad80e6ccdee31a6379f3c7ef5cb5 Mon Sep 17 00:00:00 2001 From: nichmor Date: Thu, 8 Feb 2024 13:19:35 +0200 Subject: [PATCH 05/19] feat: add support for direct whl and sdist --- .../src/artifacts/sdist.rs | 209 +++++++++++++++++- .../src/artifacts/wheel.rs | 5 + .../src/index/direct_url/file.rs | 9 +- .../src/index/direct_url/git.rs | 1 + .../src/index/direct_url/http.rs | 9 +- .../src/index/html.rs | 1 + .../src/index/package_database.rs | 93 +++++--- .../src/types/artifact_name.rs | 30 ++- .../src/types/project_info.rs | 8 + 9 files changed, 309 insertions(+), 56 deletions(-) diff --git a/crates/rattler_installs_packages/src/artifacts/sdist.rs b/crates/rattler_installs_packages/src/artifacts/sdist.rs index 2dbe43da..14e20c99 100644 --- a/crates/rattler_installs_packages/src/artifacts/sdist.rs +++ b/crates/rattler_installs_packages/src/artifacts/sdist.rs @@ -262,14 +262,14 @@ fn generic_archive_reader( mod tests { use crate::artifacts::SDist; use crate::index::{ArtifactRequest, PackageSourcesBuilder}; - use crate::python_env::Pep508EnvMakers; + use crate::python_env::{Pep508EnvMakers, PythonLocation, VEnv}; use crate::resolve::PypiVersion; use crate::resolve::SDistResolution; - use crate::types::PackageName; use crate::types::{ - ArtifactFromSource, ArtifactInfo, ArtifactName, DistInfoMetadata, Extra, STreeFilename, - Yanked, + ArtifactFromSource, ArtifactInfo, ArtifactName, DistInfoMetadata, Extra, + NormalizedPackageName, STreeFilename, WheelFilename, Yanked, }; + use crate::types::{PackageName, SDistFilename, SDistFormat}; use crate::wheel_builder::WheelBuilder; use crate::{index::PackageDb, resolve::ResolveOptions}; use insta::{assert_debug_snapshot, assert_ron_snapshot}; @@ -277,11 +277,10 @@ mod tests { use reqwest::Client; use reqwest_middleware::ClientWithMiddleware; use std::collections::{HashMap, HashSet}; - use std::env; use std::path::Path; use std::str::FromStr; use std::sync::Arc; - use tempfile::TempDir; + use tempfile::{tempdir, TempDir}; use url::Url; fn get_package_db() -> (Arc, TempDir) { @@ -868,6 +867,7 @@ mod tests { let artifact_info = vec![ArtifactInfo { filename: ArtifactName::STree(stree_file_name), url: url, + is_direct_url: true, hashes: None, requires_python: None, dist_info_metadata: DistInfoMetadata::default(), @@ -911,7 +911,71 @@ mod tests { let artifact_info = ArtifactInfo { filename: ArtifactName::STree(stree_file_name), - url: url, + url: url.clone(), + is_direct_url: true, + hashes: None, + requires_python: None, + dist_info_metadata: DistInfoMetadata::default(), + yanked: Yanked::default(), + }; + + let whl = package_db + .0 + .get_wheel(&artifact_info, Some(&wheel_builder)) + .await + .unwrap(); + + // Install wheel to test if all vitals are correctly built + let tmpdir = tempdir().unwrap(); + + let venv = VEnv::create(tmpdir.path(), PythonLocation::System).unwrap(); + + venv.install_wheel(&whl, &Default::default()).unwrap(); + + // Check to make sure that the headers directory was created + assert!(venv + .root() + .join( + venv.install_paths() + .site_packages() + .join("rich/__init__.py") + ) + .exists()); + + let whl_metadata = whl.metadata().unwrap(); + + assert_debug_snapshot!(whl_metadata.1); + } + + #[tokio::test(flavor = "multi_thread")] + pub async fn get_whl_for_local_sdist_rich() { + let path = + Path::new(env!("CARGO_MANIFEST_DIR")).join("../../test-data/sdists/rich-13.6.0.tar.gz"); + + let url = Url::from_file_path(path.canonicalize().unwrap()).unwrap(); + + let package_db = get_package_db(); + let env_markers = Arc::new(Pep508EnvMakers::from_env().await.unwrap().0); + let wheel_builder = WheelBuilder::new( + package_db.0.clone(), + env_markers, + None, + ResolveOptions::default(), + HashMap::default(), + ) + .unwrap(); + + let norm_name = PackageName::from_str("rich").unwrap(); + let sdist_file_name = SDistFilename { + distribution: norm_name, + version: Version::from_str("0.0.0").unwrap(), + format: SDistFormat::TarGz, + }; + + let artifact_info = ArtifactInfo { + filename: ArtifactName::SDist(sdist_file_name), + url: url.clone(), + is_direct_url: true, hashes: None, requires_python: None, dist_info_metadata: DistInfoMetadata::default(), @@ -928,4 +992,135 @@ mod tests { assert_debug_snapshot!(whl_metadata.1); } + + #[tokio::test(flavor = "multi_thread")] + pub async fn get_whl_for_local_whl() { + let path = Path::new(env!("CARGO_MANIFEST_DIR")) + .join("../../test-data/wheels/miniblack-23.1.0-py3-none-any.whl"); + + let url = Url::from_file_path(path.canonicalize().unwrap()).unwrap(); + + let package_db = get_package_db(); + let env_markers = Arc::new(Pep508EnvMakers::from_env().await.unwrap().0); + let wheel_builder = WheelBuilder::new( + package_db.0.clone(), + env_markers, + None, + ResolveOptions::default(), + HashMap::default(), + ) + .unwrap(); + + let norm_name = NormalizedPackageName::from(PackageName::from_str("miniblack").unwrap()); + let whl_file_name = + WheelFilename::from_filename("miniblack-23.1.0-py3-none-any.whl", &norm_name).unwrap(); + + let artifact_info = ArtifactInfo { + filename: ArtifactName::Wheel(whl_file_name), + url: url.clone(), + is_direct_url: true, + hashes: None, + requires_python: None, + dist_info_metadata: DistInfoMetadata::default(), + yanked: Yanked::default(), + }; + + let whl = package_db + .0 + .get_wheel(&artifact_info, Some(&wheel_builder)) + .await + .unwrap(); + + let whl_metadata = whl.metadata().unwrap(); + + assert_debug_snapshot!(whl_metadata.1.requires_dist); + } + + #[tokio::test(flavor = "multi_thread")] + pub async fn get_only_metadata_for_local_sdist_rich_without_calling_available_artifacts() { + let path = + Path::new(env!("CARGO_MANIFEST_DIR")).join("../../test-data/sdists/rich-13.6.0.tar.gz"); + + let url = Url::from_file_path(path.canonicalize().unwrap()).unwrap(); + + let package_db = get_package_db(); + let env_markers = Arc::new(Pep508EnvMakers::from_env().await.unwrap().0); + let wheel_builder = WheelBuilder::new( + package_db.0.clone(), + env_markers, + None, + ResolveOptions::default(), + HashMap::default(), + ) + .unwrap(); + + let norm_name = PackageName::from_str("rich").unwrap(); + let sdist_file_name = SDistFilename { + distribution: norm_name, + version: Version::from_str("0.0.0").unwrap(), + format: SDistFormat::TarGz, + }; + + let artifact_info = vec![ArtifactInfo { + filename: ArtifactName::SDist(sdist_file_name), + url: url.clone(), + is_direct_url: true, + hashes: None, + requires_python: None, + dist_info_metadata: DistInfoMetadata::default(), + yanked: Yanked::default(), + }]; + + let wheel_metadata = package_db + .0 + .get_metadata(artifact_info.as_slice(), Some(&wheel_builder)) + .await + .unwrap() + .unwrap(); + + assert_debug_snapshot!(wheel_metadata.1); + } + + #[tokio::test(flavor = "multi_thread")] + pub async fn get_only_metadata_for_local_whl_rich_without_calling_available_artifacts() { + let path = Path::new(env!("CARGO_MANIFEST_DIR")) + .join("../../test-data/wheels/miniblack-23.1.0-py3-none-any.whl"); + + let url = Url::from_file_path(path.canonicalize().unwrap()).unwrap(); + + let package_db = get_package_db(); + let env_markers = Arc::new(Pep508EnvMakers::from_env().await.unwrap().0); + let wheel_builder = WheelBuilder::new( + package_db.0.clone(), + env_markers, + None, + ResolveOptions::default(), + HashMap::default(), + ) + .unwrap(); + + let package_name = PackageName::from_str("miniblack").unwrap(); + let norm_name = NormalizedPackageName::from(package_name); + let whl_file_name = + WheelFilename::from_filename("miniblack-23.1.0-py3-none-any.whl", &norm_name).unwrap(); + + let artifact_info = vec![ArtifactInfo { + filename: ArtifactName::Wheel(whl_file_name), + url: url.clone(), + is_direct_url: true, + hashes: None, + requires_python: None, + dist_info_metadata: DistInfoMetadata::default(), + yanked: Yanked::default(), + }]; + + let wheel_metadata = package_db + .0 + .get_metadata(artifact_info.as_slice(), Some(&wheel_builder)) + .await + .unwrap() + .unwrap(); + + assert_debug_snapshot!(wheel_metadata.1.requires_dist); + } } diff --git a/crates/rattler_installs_packages/src/artifacts/wheel.rs b/crates/rattler_installs_packages/src/artifacts/wheel.rs index fb9ab4ba..d8324605 100644 --- a/crates/rattler_installs_packages/src/artifacts/wheel.rs +++ b/crates/rattler_installs_packages/src/artifacts/wheel.rs @@ -36,6 +36,7 @@ use std::{ }; use thiserror::Error; use tokio_util::compat::TokioAsyncReadCompatExt; +use url::Url; use zip::{result::ZipError, ZipArchive}; use crate::win::launcher::{build_windows_launcher, LauncherType, WindowsLauncherArch}; @@ -46,6 +47,9 @@ use crate::win::launcher::{build_windows_launcher, LauncherType, WindowsLauncher pub struct Wheel { /// Name of wheel pub name: WheelFilename, + /// Possible direct url + pub direct_url: Option, + archive: Mutex>>, } @@ -62,6 +66,7 @@ impl ArtifactFromBytes for Wheel { Ok(Self { name, archive: Mutex::new(ZipArchive::new(bytes).into_diagnostic()?), + direct_url: None, }) } } diff --git a/crates/rattler_installs_packages/src/index/direct_url/file.rs b/crates/rattler_installs_packages/src/index/direct_url/file.rs index a292ce49..e15717ad 100644 --- a/crates/rattler_installs_packages/src/index/direct_url/file.rs +++ b/crates/rattler_installs_packages/src/index/direct_url/file.rs @@ -47,10 +47,10 @@ pub(crate) async fn get_sdist_from_file_path( let file = File::open(path).into_diagnostic()?; - let mut dummy_sdist = SDist::from_bytes(dummy_sdist_file_name, Box::new(file))?; + let mut sdist = SDist::from_bytes(dummy_sdist_file_name, Box::new(file))?; let wheel_metadata = wheel_builder - .get_sdist_metadata(&dummy_sdist) + .get_sdist_metadata(&sdist) .await .into_diagnostic()?; @@ -61,9 +61,9 @@ pub(crate) async fn get_sdist_from_file_path( format, }; - dummy_sdist.name = sdist_filename; + sdist.name = sdist_filename; - Ok((wheel_metadata, dummy_sdist)) + Ok((wheel_metadata, sdist)) } /// Return an stree from file path @@ -169,6 +169,7 @@ pub(crate) async fn get_artifacts_and_metadata>( let artifact_info = Arc::new(ArtifactInfo { filename: artifact.name(), url: url.clone(), + is_direct_url: true, hashes: Some(artifact_hash), requires_python: metadata.requires_python.clone(), dist_info_metadata: DistInfoMetadata::default(), diff --git a/crates/rattler_installs_packages/src/index/direct_url/git.rs b/crates/rattler_installs_packages/src/index/direct_url/git.rs index 352ac692..625da61c 100644 --- a/crates/rattler_installs_packages/src/index/direct_url/git.rs +++ b/crates/rattler_installs_packages/src/index/direct_url/git.rs @@ -67,6 +67,7 @@ pub(crate) async fn get_artifacts_and_metadata>( let artifact_info = Arc::new(ArtifactInfo { filename: ArtifactName::STree(artifact.name().clone()), url: url.clone(), + is_direct_url: true, hashes: Some(project_hash), requires_python, dist_info_metadata, diff --git a/crates/rattler_installs_packages/src/index/direct_url/http.rs b/crates/rattler_installs_packages/src/index/direct_url/http.rs index 9ba238f0..7a74c076 100644 --- a/crates/rattler_installs_packages/src/index/direct_url/http.rs +++ b/crates/rattler_installs_packages/src/index/direct_url/http.rs @@ -82,6 +82,7 @@ pub(crate) async fn get_artifacts_and_metadata>( let artifact_info = Arc::new(ArtifactInfo { filename: artifact.name(), url: url.clone(), + is_direct_url: true, hashes: Some(artifact_hash), requires_python: metadata.requires_python.clone(), dist_info_metadata: DistInfoMetadata::default(), @@ -121,10 +122,10 @@ async fn get_sdist_from_bytes( // we don't know the version for artifact until we extract the actual metadata // so we create a plain sdist object aka dummy // and populate it with correct metadata after calling `get_sdist_metadata` - let mut dummy_sdist = SDist::from_bytes(dummy_sdist_file_name, Box::new(bytes))?; + let mut sdist = SDist::from_bytes(dummy_sdist_file_name, Box::new(bytes))?; let wheel_metadata = wheel_builder - .get_sdist_metadata(&dummy_sdist) + .get_sdist_metadata(&sdist) .await .into_diagnostic()?; @@ -134,7 +135,7 @@ async fn get_sdist_from_bytes( version: wheel_metadata.1.version.clone(), format, }; - dummy_sdist.name = sdist_filename; + sdist.name = sdist_filename; - Ok((wheel_metadata, dummy_sdist)) + Ok((wheel_metadata, sdist)) } diff --git a/crates/rattler_installs_packages/src/index/html.rs b/crates/rattler_installs_packages/src/index/html.rs index 7525bd28..72c46ec4 100644 --- a/crates/rattler_installs_packages/src/index/html.rs +++ b/crates/rattler_installs_packages/src/index/html.rs @@ -93,6 +93,7 @@ fn into_artifact_info( Some(ArtifactInfo { filename, url, + is_direct_url: false, hashes: hash, requires_python, dist_info_metadata, diff --git a/crates/rattler_installs_packages/src/index/package_database.rs b/crates/rattler_installs_packages/src/index/package_database.rs index 62d53031..378f3b1b 100644 --- a/crates/rattler_installs_packages/src/index/package_database.rs +++ b/crates/rattler_installs_packages/src/index/package_database.rs @@ -7,7 +7,7 @@ use crate::index::package_sources::PackageSources; use crate::resolve::PypiVersion; use crate::types::{ArtifactInfo, ArtifactType, ProjectInfo, STreeFilename, WheelCoreMetadata}; -use crate::wheel_builder::{WheelBuilder, WheelCache}; +use crate::wheel_builder::{WheelBuildError, WheelBuilder, WheelCache}; use crate::{ types::ArtifactFromBytes, types::InnerAsArtifactName, types::NormalizedPackageName, types::WheelFilename, @@ -200,7 +200,7 @@ impl PackageDb { // network to get to the information. // Let's try to get information for any wheels that we have // first - let result = self.get_metadata_wheels(artifacts).await?; + let result = self.get_metadata_wheels(artifacts, wheel_builder).await?; if result.is_some() { return Ok(result); } @@ -232,33 +232,25 @@ impl PackageDb { builder: Option<&'async_recursion WheelBuilder>, ) -> miette::Result { // TODO: add support for this currently there are not saved - if artifact_info.is::() { + if artifact_info.is_direct_url { if let Some(builder) = builder { - let stree_name = artifact_info - .filename - .as_inner::() - .unwrap_or_else(|| { - panic!( - "the specified artifact '{}' does not refer to type requested to read", - artifact_info.filename - ) - }); - let response = super::direct_url::fetch_artifact_and_metadata_by_direct_url( &self.http, - stree_name.distribution.clone(), + artifact_info.filename.distribution_name(), artifact_info.url.clone(), builder, ) .await?; - let stree = response - .artifact - .as_stree() - .expect("the request artifact does not refer to stree"); - - let built = builder.build_wheel(stree).await.into_diagnostic(); - return built; + match response.artifact { + ArtifactType::Wheel(wheel) => return Ok(wheel), + ArtifactType::SDist(sdist) => { + return builder.build_wheel(&sdist).await.into_diagnostic() + } + ArtifactType::STree(stree) => { + return builder.build_wheel(&stree).await.into_diagnostic() + } + } } else { miette::bail!("cannot build wheel without a wheel builder"); } @@ -341,7 +333,7 @@ impl PackageDb { ) -> miette::Result> { for artifact_info in artifacts.iter() { let artifact_info_ref = artifact_info.borrow(); - if artifact_info_ref.is::() { + if artifact_info_ref.is::() && !artifact_info_ref.is_direct_url { let result = self .get_cached_artifact::(artifact_info_ref, CacheMode::OnlyIfCached) .await; @@ -372,7 +364,7 @@ impl PackageDb { } } // We know that it is an sdist - else if artifact_info_ref.is::() { + else if artifact_info_ref.is::() && !artifact_info_ref.is_direct_url { let result = self .get_cached_artifact::(artifact_info_ref, CacheMode::OnlyIfCached) .await; @@ -399,6 +391,7 @@ impl PackageDb { async fn get_metadata_wheels<'a, A: Borrow>( &self, artifacts: &'a [A], + wheel_builder: Option<&WheelBuilder>, ) -> miette::Result> { let wheels = artifacts .iter() @@ -420,11 +413,30 @@ impl PackageDb { return Ok(Some((artifact_info, metadata))); } - // Otherwise download the entire artifact - let artifact = self - .get_cached_artifact::(ai, CacheMode::Default) - .await?; - let metadata = artifact.metadata(); + let metadata = if ai.is_direct_url { + if let Some(wheel_builder) = wheel_builder { + let response = super::direct_url::fetch_artifact_and_metadata_by_direct_url( + &self.http, + ai.filename.distribution_name(), + ai.url.clone(), + wheel_builder, + ) + .await; + match response { + Err(err) => Err(miette::miette!(err.to_string())), + Ok(response) => Ok(response.metadata), + } + } else { + miette::bail!("cannot build wheel without a wheel builder"); + } + } else { + // Otherwise download the entire artifact + let artifact = self + .get_cached_artifact::(ai, CacheMode::Default) + .await?; + artifact.metadata() + }; + match metadata { Ok((blob, metadata)) => { self.put_metadata_in_cache(ai, &blob).await?; @@ -456,11 +468,26 @@ impl PackageDb { // only print these if we have not been able to find any metadata let mut errors = Vec::new(); for ai in sdists { - let artifact_info = ai.borrow(); - let artifact = self - .get_cached_artifact::(artifact_info, CacheMode::Default) - .await?; - let metadata = wheel_builder.get_sdist_metadata(&artifact).await; + let artifact_info: &ArtifactInfo = ai.borrow(); + let metadata = if artifact_info.is_direct_url { + let response = super::direct_url::fetch_artifact_and_metadata_by_direct_url( + &self.http, + artifact_info.filename.distribution_name(), + artifact_info.url.clone(), + wheel_builder, + ) + .await; + match response { + Err(err) => Err(WheelBuildError::Error(err.to_string())), + Ok(response) => Ok(response.metadata), + } + } else { + let artifact = self + .get_cached_artifact::(artifact_info, CacheMode::Default) + .await?; + wheel_builder.get_sdist_metadata(&artifact).await + }; + match metadata { Ok((blob, metadata)) => { self.put_metadata_in_cache(artifact_info, &blob).await?; diff --git a/crates/rattler_installs_packages/src/types/artifact_name.rs b/crates/rattler_installs_packages/src/types/artifact_name.rs index b3dc2912..dfce267f 100644 --- a/crates/rattler_installs_packages/src/types/artifact_name.rs +++ b/crates/rattler_installs_packages/src/types/artifact_name.rs @@ -80,6 +80,15 @@ impl ArtifactName { pub fn as_inner(&self) -> Option<&T> { T::try_as(self) } + + /// Tries to convert the specialized instance + pub fn distribution_name(&self) -> PackageName { + match self { + ArtifactName::Wheel(name) => name.distribution.clone(), + ArtifactName::STree(name) => name.distribution.clone(), + ArtifactName::SDist(name) => name.distribution.clone(), + } + } } impl Display for ArtifactName { @@ -426,6 +435,10 @@ impl WheelFilename { let Some((distribution, rest)) = split_into_filename_rest(file_stem, normalized_package_name) else { + println!( + "FILE STEM IS {:?} NORM NAME {:?}", + file_stem, normalized_package_name + ); return Err(ParseArtifactNameError::PackageNameNotFound( normalized_package_name.clone(), s.to_string(), @@ -531,13 +544,14 @@ impl InnerAsArtifactName for STreeFilename { } } -/// Enum that contains all artifacts types +/// Enum that contains the different artifacts types: +/// * SDist is a python source distribution +/// * Wheel is a python binary distribution +/// * STree (is not an official PyPa name) but represents a source code tree +#[allow(missing_docs)] pub enum ArtifactType { - /// Wheel artifact Wheel(Wheel), - /// Sdist artifact SDist(SDist), - /// STree artifact STree(STree), } @@ -552,7 +566,7 @@ impl ArtifactType { } /// Returns this artifact as wheel - pub fn as_wheel(&self) -> Option<&Wheel> { + pub fn as_wheel(self) -> Option { match self { ArtifactType::Wheel(wheel) => Some(wheel), ArtifactType::SDist(_) => None, @@ -561,7 +575,7 @@ impl ArtifactType { } /// Returns this name as a wheel name - pub fn as_sdist(&self) -> Option<&SDist> { + pub fn as_sdist(self) -> Option { match self { ArtifactType::Wheel(_) => None, ArtifactType::STree(_) => None, @@ -570,10 +584,10 @@ impl ArtifactType { } /// Returns this name as a source tree name - pub fn as_stree(&self) -> Option<&STree> { + pub fn as_stree(self) -> Option { match self { ArtifactType::Wheel(_) => None, - ArtifactType::STree(name) => Some(name), + ArtifactType::STree(stree) => Some(stree), ArtifactType::SDist(_) => None, } } diff --git a/crates/rattler_installs_packages/src/types/project_info.rs b/crates/rattler_installs_packages/src/types/project_info.rs index eecfec4c..a4877667 100644 --- a/crates/rattler_installs_packages/src/types/project_info.rs +++ b/crates/rattler_installs_packages/src/types/project_info.rs @@ -28,6 +28,9 @@ pub struct ArtifactInfo { pub filename: ArtifactName, /// Url to download the artifact pub url: url::Url, + /// Is url a direct reference + #[serde(skip_serializing)] + pub is_direct_url: bool, /// Hashes of the artifact pub hashes: Option, /// Python requirement @@ -47,6 +50,11 @@ impl ArtifactInfo { pub fn is(&self) -> bool { self.filename.as_inner::().is_some() } + + // /// Returns true if this artifact is gathered by direct reference + // pub fn is_direct_dependency(&self) -> bool { + // self.filename.is_direct_reference() + // } } /// Describes a set of hashes for a certain artifact. In theory all hash algorithms available via From 58ba5951c174b5c08a83b720086945190b858487 Mon Sep 17 00:00:00 2001 From: nichmor Date: Thu, 8 Feb 2024 13:20:50 +0200 Subject: [PATCH 06/19] misc: remove commented code --- ...__tests__get_metadata_for_local_sdist.snap | 240 +++++++++ ...h_without_calling_available_artifacts.snap | 240 +++++++++ ...h_without_calling_available_artifacts.snap | 469 ++++++++++++++++++ ...__tests__get_whl_for_local_sdist_rich.snap | 240 +++++++++ ...__sdist__tests__get_whl_for_local_whl.snap | 469 ++++++++++++++++++ .../src/types/project_info.rs | 5 - 6 files changed, 1658 insertions(+), 5 deletions(-) create mode 100644 crates/rattler_installs_packages/src/artifacts/snapshots/rattler_installs_packages__artifacts__sdist__tests__get_metadata_for_local_sdist.snap create mode 100644 crates/rattler_installs_packages/src/artifacts/snapshots/rattler_installs_packages__artifacts__sdist__tests__get_only_metadata_for_local_sdist_rich_without_calling_available_artifacts.snap create mode 100644 crates/rattler_installs_packages/src/artifacts/snapshots/rattler_installs_packages__artifacts__sdist__tests__get_only_metadata_for_local_whl_rich_without_calling_available_artifacts.snap create mode 100644 crates/rattler_installs_packages/src/artifacts/snapshots/rattler_installs_packages__artifacts__sdist__tests__get_whl_for_local_sdist_rich.snap create mode 100644 crates/rattler_installs_packages/src/artifacts/snapshots/rattler_installs_packages__artifacts__sdist__tests__get_whl_for_local_whl.snap diff --git a/crates/rattler_installs_packages/src/artifacts/snapshots/rattler_installs_packages__artifacts__sdist__tests__get_metadata_for_local_sdist.snap b/crates/rattler_installs_packages/src/artifacts/snapshots/rattler_installs_packages__artifacts__sdist__tests__get_metadata_for_local_sdist.snap new file mode 100644 index 00000000..61c65b4a --- /dev/null +++ b/crates/rattler_installs_packages/src/artifacts/snapshots/rattler_installs_packages__artifacts__sdist__tests__get_metadata_for_local_sdist.snap @@ -0,0 +1,240 @@ +--- +source: crates/rattler_installs_packages/src/artifacts/sdist.rs +expression: wheel_metadata.1 +--- +WheelCoreMetadata { + name: PackageName { + source: "rich", + normalized: "rich", + }, + version: Version { + epoch: 0, + release: [ + 13, + 6, + 0, + ], + pre: None, + post: None, + dev: None, + local: None, + }, + metadata_version: MetadataVersion( + Version { + epoch: 0, + release: [ + 2, + 1, + ], + pre: None, + post: None, + dev: None, + local: None, + }, + ), + requires_dist: [ + Requirement { + name: "ipywidgets", + extras: None, + version_or_url: Some( + VersionSpecifier( + VersionSpecifiers( + [ + VersionSpecifier { + operator: GreaterThanEqual, + version: Version { + epoch: 0, + release: [ + 7, + 5, + 1, + ], + pre: None, + post: None, + dev: None, + local: None, + }, + }, + VersionSpecifier { + operator: LessThan, + version: Version { + epoch: 0, + release: [ + 9, + ], + pre: None, + post: None, + dev: None, + local: None, + }, + }, + ], + ), + ), + ), + marker: Some( + Expression( + MarkerExpression { + l_value: Extra, + operator: Equal, + r_value: QuotedString( + "jupyter", + ), + }, + ), + ), + }, + Requirement { + name: "markdown-it-py", + extras: None, + version_or_url: Some( + VersionSpecifier( + VersionSpecifiers( + [ + VersionSpecifier { + operator: GreaterThanEqual, + version: Version { + epoch: 0, + release: [ + 2, + 2, + 0, + ], + pre: None, + post: None, + dev: None, + local: None, + }, + }, + ], + ), + ), + ), + marker: None, + }, + Requirement { + name: "pygments", + extras: None, + version_or_url: Some( + VersionSpecifier( + VersionSpecifiers( + [ + VersionSpecifier { + operator: GreaterThanEqual, + version: Version { + epoch: 0, + release: [ + 2, + 13, + 0, + ], + pre: None, + post: None, + dev: None, + local: None, + }, + }, + VersionSpecifier { + operator: LessThan, + version: Version { + epoch: 0, + release: [ + 3, + 0, + 0, + ], + pre: None, + post: None, + dev: None, + local: None, + }, + }, + ], + ), + ), + ), + marker: None, + }, + Requirement { + name: "typing-extensions", + extras: None, + version_or_url: Some( + VersionSpecifier( + VersionSpecifiers( + [ + VersionSpecifier { + operator: GreaterThanEqual, + version: Version { + epoch: 0, + release: [ + 4, + 0, + 0, + ], + pre: None, + post: None, + dev: None, + local: None, + }, + }, + VersionSpecifier { + operator: LessThan, + version: Version { + epoch: 0, + release: [ + 5, + 0, + ], + pre: None, + post: None, + dev: None, + local: None, + }, + }, + ], + ), + ), + ), + marker: Some( + Expression( + MarkerExpression { + l_value: MarkerEnvVersion( + PythonVersion, + ), + operator: LessThan, + r_value: QuotedString( + "3.9", + ), + }, + ), + ), + }, + ], + requires_python: Some( + VersionSpecifiers( + [ + VersionSpecifier { + operator: GreaterThanEqual, + version: Version { + epoch: 0, + release: [ + 3, + 7, + 0, + ], + pre: None, + post: None, + dev: None, + local: None, + }, + }, + ], + ), + ), + extras: { + Extra { + source: "jupyter", + normalized: "jupyter", + }, + }, +} diff --git a/crates/rattler_installs_packages/src/artifacts/snapshots/rattler_installs_packages__artifacts__sdist__tests__get_only_metadata_for_local_sdist_rich_without_calling_available_artifacts.snap b/crates/rattler_installs_packages/src/artifacts/snapshots/rattler_installs_packages__artifacts__sdist__tests__get_only_metadata_for_local_sdist_rich_without_calling_available_artifacts.snap new file mode 100644 index 00000000..61c65b4a --- /dev/null +++ b/crates/rattler_installs_packages/src/artifacts/snapshots/rattler_installs_packages__artifacts__sdist__tests__get_only_metadata_for_local_sdist_rich_without_calling_available_artifacts.snap @@ -0,0 +1,240 @@ +--- +source: crates/rattler_installs_packages/src/artifacts/sdist.rs +expression: wheel_metadata.1 +--- +WheelCoreMetadata { + name: PackageName { + source: "rich", + normalized: "rich", + }, + version: Version { + epoch: 0, + release: [ + 13, + 6, + 0, + ], + pre: None, + post: None, + dev: None, + local: None, + }, + metadata_version: MetadataVersion( + Version { + epoch: 0, + release: [ + 2, + 1, + ], + pre: None, + post: None, + dev: None, + local: None, + }, + ), + requires_dist: [ + Requirement { + name: "ipywidgets", + extras: None, + version_or_url: Some( + VersionSpecifier( + VersionSpecifiers( + [ + VersionSpecifier { + operator: GreaterThanEqual, + version: Version { + epoch: 0, + release: [ + 7, + 5, + 1, + ], + pre: None, + post: None, + dev: None, + local: None, + }, + }, + VersionSpecifier { + operator: LessThan, + version: Version { + epoch: 0, + release: [ + 9, + ], + pre: None, + post: None, + dev: None, + local: None, + }, + }, + ], + ), + ), + ), + marker: Some( + Expression( + MarkerExpression { + l_value: Extra, + operator: Equal, + r_value: QuotedString( + "jupyter", + ), + }, + ), + ), + }, + Requirement { + name: "markdown-it-py", + extras: None, + version_or_url: Some( + VersionSpecifier( + VersionSpecifiers( + [ + VersionSpecifier { + operator: GreaterThanEqual, + version: Version { + epoch: 0, + release: [ + 2, + 2, + 0, + ], + pre: None, + post: None, + dev: None, + local: None, + }, + }, + ], + ), + ), + ), + marker: None, + }, + Requirement { + name: "pygments", + extras: None, + version_or_url: Some( + VersionSpecifier( + VersionSpecifiers( + [ + VersionSpecifier { + operator: GreaterThanEqual, + version: Version { + epoch: 0, + release: [ + 2, + 13, + 0, + ], + pre: None, + post: None, + dev: None, + local: None, + }, + }, + VersionSpecifier { + operator: LessThan, + version: Version { + epoch: 0, + release: [ + 3, + 0, + 0, + ], + pre: None, + post: None, + dev: None, + local: None, + }, + }, + ], + ), + ), + ), + marker: None, + }, + Requirement { + name: "typing-extensions", + extras: None, + version_or_url: Some( + VersionSpecifier( + VersionSpecifiers( + [ + VersionSpecifier { + operator: GreaterThanEqual, + version: Version { + epoch: 0, + release: [ + 4, + 0, + 0, + ], + pre: None, + post: None, + dev: None, + local: None, + }, + }, + VersionSpecifier { + operator: LessThan, + version: Version { + epoch: 0, + release: [ + 5, + 0, + ], + pre: None, + post: None, + dev: None, + local: None, + }, + }, + ], + ), + ), + ), + marker: Some( + Expression( + MarkerExpression { + l_value: MarkerEnvVersion( + PythonVersion, + ), + operator: LessThan, + r_value: QuotedString( + "3.9", + ), + }, + ), + ), + }, + ], + requires_python: Some( + VersionSpecifiers( + [ + VersionSpecifier { + operator: GreaterThanEqual, + version: Version { + epoch: 0, + release: [ + 3, + 7, + 0, + ], + pre: None, + post: None, + dev: None, + local: None, + }, + }, + ], + ), + ), + extras: { + Extra { + source: "jupyter", + normalized: "jupyter", + }, + }, +} diff --git a/crates/rattler_installs_packages/src/artifacts/snapshots/rattler_installs_packages__artifacts__sdist__tests__get_only_metadata_for_local_whl_rich_without_calling_available_artifacts.snap b/crates/rattler_installs_packages/src/artifacts/snapshots/rattler_installs_packages__artifacts__sdist__tests__get_only_metadata_for_local_whl_rich_without_calling_available_artifacts.snap new file mode 100644 index 00000000..af22f094 --- /dev/null +++ b/crates/rattler_installs_packages/src/artifacts/snapshots/rattler_installs_packages__artifacts__sdist__tests__get_only_metadata_for_local_whl_rich_without_calling_available_artifacts.snap @@ -0,0 +1,469 @@ +--- +source: crates/rattler_installs_packages/src/artifacts/sdist.rs +expression: wheel_metadata.1.requires_dist +--- +[ + Requirement { + name: "click", + extras: None, + version_or_url: Some( + VersionSpecifier( + VersionSpecifiers( + [ + VersionSpecifier { + operator: GreaterThanEqual, + version: Version { + epoch: 0, + release: [ + 8, + 0, + 0, + ], + pre: None, + post: None, + dev: None, + local: None, + }, + }, + ], + ), + ), + ), + marker: None, + }, + Requirement { + name: "mypy-extensions", + extras: None, + version_or_url: Some( + VersionSpecifier( + VersionSpecifiers( + [ + VersionSpecifier { + operator: GreaterThanEqual, + version: Version { + epoch: 0, + release: [ + 0, + 4, + 3, + ], + pre: None, + post: None, + dev: None, + local: None, + }, + }, + ], + ), + ), + ), + marker: None, + }, + Requirement { + name: "packaging", + extras: None, + version_or_url: Some( + VersionSpecifier( + VersionSpecifiers( + [ + VersionSpecifier { + operator: GreaterThanEqual, + version: Version { + epoch: 0, + release: [ + 22, + 0, + ], + pre: None, + post: None, + dev: None, + local: None, + }, + }, + ], + ), + ), + ), + marker: None, + }, + Requirement { + name: "pathspec", + extras: None, + version_or_url: Some( + VersionSpecifier( + VersionSpecifiers( + [ + VersionSpecifier { + operator: GreaterThanEqual, + version: Version { + epoch: 0, + release: [ + 0, + 9, + 0, + ], + pre: None, + post: None, + dev: None, + local: None, + }, + }, + ], + ), + ), + ), + marker: None, + }, + Requirement { + name: "platformdirs", + extras: None, + version_or_url: Some( + VersionSpecifier( + VersionSpecifiers( + [ + VersionSpecifier { + operator: GreaterThanEqual, + version: Version { + epoch: 0, + release: [ + 2, + ], + pre: None, + post: None, + dev: None, + local: None, + }, + }, + ], + ), + ), + ), + marker: None, + }, + Requirement { + name: "tomli", + extras: None, + version_or_url: Some( + VersionSpecifier( + VersionSpecifiers( + [ + VersionSpecifier { + operator: GreaterThanEqual, + version: Version { + epoch: 0, + release: [ + 1, + 1, + 0, + ], + pre: None, + post: None, + dev: None, + local: None, + }, + }, + ], + ), + ), + ), + marker: Some( + Expression( + MarkerExpression { + l_value: MarkerEnvVersion( + PythonVersion, + ), + operator: LessThan, + r_value: QuotedString( + "3.11", + ), + }, + ), + ), + }, + Requirement { + name: "typed-ast", + extras: None, + version_or_url: Some( + VersionSpecifier( + VersionSpecifiers( + [ + VersionSpecifier { + operator: GreaterThanEqual, + version: Version { + epoch: 0, + release: [ + 1, + 4, + 2, + ], + pre: None, + post: None, + dev: None, + local: None, + }, + }, + ], + ), + ), + ), + marker: Some( + And( + [ + Expression( + MarkerExpression { + l_value: MarkerEnvVersion( + PythonVersion, + ), + operator: LessThan, + r_value: QuotedString( + "3.8", + ), + }, + ), + Expression( + MarkerExpression { + l_value: MarkerEnvString( + ImplementationName, + ), + operator: Equal, + r_value: QuotedString( + "cpython", + ), + }, + ), + ], + ), + ), + }, + Requirement { + name: "typing-extensions", + extras: None, + version_or_url: Some( + VersionSpecifier( + VersionSpecifiers( + [ + VersionSpecifier { + operator: GreaterThanEqual, + version: Version { + epoch: 0, + release: [ + 3, + 10, + 0, + 0, + ], + pre: None, + post: None, + dev: None, + local: None, + }, + }, + ], + ), + ), + ), + marker: Some( + Expression( + MarkerExpression { + l_value: MarkerEnvVersion( + PythonVersion, + ), + operator: LessThan, + r_value: QuotedString( + "3.10", + ), + }, + ), + ), + }, + Requirement { + name: "colorama", + extras: None, + version_or_url: Some( + VersionSpecifier( + VersionSpecifiers( + [ + VersionSpecifier { + operator: GreaterThanEqual, + version: Version { + epoch: 0, + release: [ + 0, + 4, + 3, + ], + pre: None, + post: None, + dev: None, + local: None, + }, + }, + ], + ), + ), + ), + marker: Some( + Expression( + MarkerExpression { + l_value: Extra, + operator: Equal, + r_value: QuotedString( + "colorama", + ), + }, + ), + ), + }, + Requirement { + name: "aiohttp", + extras: None, + version_or_url: Some( + VersionSpecifier( + VersionSpecifiers( + [ + VersionSpecifier { + operator: GreaterThanEqual, + version: Version { + epoch: 0, + release: [ + 3, + 7, + 4, + ], + pre: None, + post: None, + dev: None, + local: None, + }, + }, + ], + ), + ), + ), + marker: Some( + Expression( + MarkerExpression { + l_value: Extra, + operator: Equal, + r_value: QuotedString( + "d", + ), + }, + ), + ), + }, + Requirement { + name: "ipython", + extras: None, + version_or_url: Some( + VersionSpecifier( + VersionSpecifiers( + [ + VersionSpecifier { + operator: GreaterThanEqual, + version: Version { + epoch: 0, + release: [ + 7, + 8, + 0, + ], + pre: None, + post: None, + dev: None, + local: None, + }, + }, + ], + ), + ), + ), + marker: Some( + Expression( + MarkerExpression { + l_value: Extra, + operator: Equal, + r_value: QuotedString( + "jupyter", + ), + }, + ), + ), + }, + Requirement { + name: "tokenize-rt", + extras: None, + version_or_url: Some( + VersionSpecifier( + VersionSpecifiers( + [ + VersionSpecifier { + operator: GreaterThanEqual, + version: Version { + epoch: 0, + release: [ + 3, + 2, + 0, + ], + pre: None, + post: None, + dev: None, + local: None, + }, + }, + ], + ), + ), + ), + marker: Some( + Expression( + MarkerExpression { + l_value: Extra, + operator: Equal, + r_value: QuotedString( + "jupyter", + ), + }, + ), + ), + }, + Requirement { + name: "uvloop", + extras: None, + version_or_url: Some( + VersionSpecifier( + VersionSpecifiers( + [ + VersionSpecifier { + operator: GreaterThanEqual, + version: Version { + epoch: 0, + release: [ + 0, + 15, + 2, + ], + pre: None, + post: None, + dev: None, + local: None, + }, + }, + ], + ), + ), + ), + marker: Some( + Expression( + MarkerExpression { + l_value: Extra, + operator: Equal, + r_value: QuotedString( + "uvloop", + ), + }, + ), + ), + }, +] diff --git a/crates/rattler_installs_packages/src/artifacts/snapshots/rattler_installs_packages__artifacts__sdist__tests__get_whl_for_local_sdist_rich.snap b/crates/rattler_installs_packages/src/artifacts/snapshots/rattler_installs_packages__artifacts__sdist__tests__get_whl_for_local_sdist_rich.snap new file mode 100644 index 00000000..fd3b9512 --- /dev/null +++ b/crates/rattler_installs_packages/src/artifacts/snapshots/rattler_installs_packages__artifacts__sdist__tests__get_whl_for_local_sdist_rich.snap @@ -0,0 +1,240 @@ +--- +source: crates/rattler_installs_packages/src/artifacts/sdist.rs +expression: whl_metadata.1 +--- +WheelCoreMetadata { + name: PackageName { + source: "rich", + normalized: "rich", + }, + version: Version { + epoch: 0, + release: [ + 13, + 6, + 0, + ], + pre: None, + post: None, + dev: None, + local: None, + }, + metadata_version: MetadataVersion( + Version { + epoch: 0, + release: [ + 2, + 1, + ], + pre: None, + post: None, + dev: None, + local: None, + }, + ), + requires_dist: [ + Requirement { + name: "ipywidgets", + extras: None, + version_or_url: Some( + VersionSpecifier( + VersionSpecifiers( + [ + VersionSpecifier { + operator: GreaterThanEqual, + version: Version { + epoch: 0, + release: [ + 7, + 5, + 1, + ], + pre: None, + post: None, + dev: None, + local: None, + }, + }, + VersionSpecifier { + operator: LessThan, + version: Version { + epoch: 0, + release: [ + 9, + ], + pre: None, + post: None, + dev: None, + local: None, + }, + }, + ], + ), + ), + ), + marker: Some( + Expression( + MarkerExpression { + l_value: Extra, + operator: Equal, + r_value: QuotedString( + "jupyter", + ), + }, + ), + ), + }, + Requirement { + name: "markdown-it-py", + extras: None, + version_or_url: Some( + VersionSpecifier( + VersionSpecifiers( + [ + VersionSpecifier { + operator: GreaterThanEqual, + version: Version { + epoch: 0, + release: [ + 2, + 2, + 0, + ], + pre: None, + post: None, + dev: None, + local: None, + }, + }, + ], + ), + ), + ), + marker: None, + }, + Requirement { + name: "pygments", + extras: None, + version_or_url: Some( + VersionSpecifier( + VersionSpecifiers( + [ + VersionSpecifier { + operator: GreaterThanEqual, + version: Version { + epoch: 0, + release: [ + 2, + 13, + 0, + ], + pre: None, + post: None, + dev: None, + local: None, + }, + }, + VersionSpecifier { + operator: LessThan, + version: Version { + epoch: 0, + release: [ + 3, + 0, + 0, + ], + pre: None, + post: None, + dev: None, + local: None, + }, + }, + ], + ), + ), + ), + marker: None, + }, + Requirement { + name: "typing-extensions", + extras: None, + version_or_url: Some( + VersionSpecifier( + VersionSpecifiers( + [ + VersionSpecifier { + operator: GreaterThanEqual, + version: Version { + epoch: 0, + release: [ + 4, + 0, + 0, + ], + pre: None, + post: None, + dev: None, + local: None, + }, + }, + VersionSpecifier { + operator: LessThan, + version: Version { + epoch: 0, + release: [ + 5, + 0, + ], + pre: None, + post: None, + dev: None, + local: None, + }, + }, + ], + ), + ), + ), + marker: Some( + Expression( + MarkerExpression { + l_value: MarkerEnvVersion( + PythonVersion, + ), + operator: LessThan, + r_value: QuotedString( + "3.9", + ), + }, + ), + ), + }, + ], + requires_python: Some( + VersionSpecifiers( + [ + VersionSpecifier { + operator: GreaterThanEqual, + version: Version { + epoch: 0, + release: [ + 3, + 7, + 0, + ], + pre: None, + post: None, + dev: None, + local: None, + }, + }, + ], + ), + ), + extras: { + Extra { + source: "jupyter", + normalized: "jupyter", + }, + }, +} diff --git a/crates/rattler_installs_packages/src/artifacts/snapshots/rattler_installs_packages__artifacts__sdist__tests__get_whl_for_local_whl.snap b/crates/rattler_installs_packages/src/artifacts/snapshots/rattler_installs_packages__artifacts__sdist__tests__get_whl_for_local_whl.snap new file mode 100644 index 00000000..c6499a2f --- /dev/null +++ b/crates/rattler_installs_packages/src/artifacts/snapshots/rattler_installs_packages__artifacts__sdist__tests__get_whl_for_local_whl.snap @@ -0,0 +1,469 @@ +--- +source: crates/rattler_installs_packages/src/artifacts/sdist.rs +expression: whl_metadata.1.requires_dist +--- +[ + Requirement { + name: "click", + extras: None, + version_or_url: Some( + VersionSpecifier( + VersionSpecifiers( + [ + VersionSpecifier { + operator: GreaterThanEqual, + version: Version { + epoch: 0, + release: [ + 8, + 0, + 0, + ], + pre: None, + post: None, + dev: None, + local: None, + }, + }, + ], + ), + ), + ), + marker: None, + }, + Requirement { + name: "mypy-extensions", + extras: None, + version_or_url: Some( + VersionSpecifier( + VersionSpecifiers( + [ + VersionSpecifier { + operator: GreaterThanEqual, + version: Version { + epoch: 0, + release: [ + 0, + 4, + 3, + ], + pre: None, + post: None, + dev: None, + local: None, + }, + }, + ], + ), + ), + ), + marker: None, + }, + Requirement { + name: "packaging", + extras: None, + version_or_url: Some( + VersionSpecifier( + VersionSpecifiers( + [ + VersionSpecifier { + operator: GreaterThanEqual, + version: Version { + epoch: 0, + release: [ + 22, + 0, + ], + pre: None, + post: None, + dev: None, + local: None, + }, + }, + ], + ), + ), + ), + marker: None, + }, + Requirement { + name: "pathspec", + extras: None, + version_or_url: Some( + VersionSpecifier( + VersionSpecifiers( + [ + VersionSpecifier { + operator: GreaterThanEqual, + version: Version { + epoch: 0, + release: [ + 0, + 9, + 0, + ], + pre: None, + post: None, + dev: None, + local: None, + }, + }, + ], + ), + ), + ), + marker: None, + }, + Requirement { + name: "platformdirs", + extras: None, + version_or_url: Some( + VersionSpecifier( + VersionSpecifiers( + [ + VersionSpecifier { + operator: GreaterThanEqual, + version: Version { + epoch: 0, + release: [ + 2, + ], + pre: None, + post: None, + dev: None, + local: None, + }, + }, + ], + ), + ), + ), + marker: None, + }, + Requirement { + name: "tomli", + extras: None, + version_or_url: Some( + VersionSpecifier( + VersionSpecifiers( + [ + VersionSpecifier { + operator: GreaterThanEqual, + version: Version { + epoch: 0, + release: [ + 1, + 1, + 0, + ], + pre: None, + post: None, + dev: None, + local: None, + }, + }, + ], + ), + ), + ), + marker: Some( + Expression( + MarkerExpression { + l_value: MarkerEnvVersion( + PythonVersion, + ), + operator: LessThan, + r_value: QuotedString( + "3.11", + ), + }, + ), + ), + }, + Requirement { + name: "typed-ast", + extras: None, + version_or_url: Some( + VersionSpecifier( + VersionSpecifiers( + [ + VersionSpecifier { + operator: GreaterThanEqual, + version: Version { + epoch: 0, + release: [ + 1, + 4, + 2, + ], + pre: None, + post: None, + dev: None, + local: None, + }, + }, + ], + ), + ), + ), + marker: Some( + And( + [ + Expression( + MarkerExpression { + l_value: MarkerEnvVersion( + PythonVersion, + ), + operator: LessThan, + r_value: QuotedString( + "3.8", + ), + }, + ), + Expression( + MarkerExpression { + l_value: MarkerEnvString( + ImplementationName, + ), + operator: Equal, + r_value: QuotedString( + "cpython", + ), + }, + ), + ], + ), + ), + }, + Requirement { + name: "typing-extensions", + extras: None, + version_or_url: Some( + VersionSpecifier( + VersionSpecifiers( + [ + VersionSpecifier { + operator: GreaterThanEqual, + version: Version { + epoch: 0, + release: [ + 3, + 10, + 0, + 0, + ], + pre: None, + post: None, + dev: None, + local: None, + }, + }, + ], + ), + ), + ), + marker: Some( + Expression( + MarkerExpression { + l_value: MarkerEnvVersion( + PythonVersion, + ), + operator: LessThan, + r_value: QuotedString( + "3.10", + ), + }, + ), + ), + }, + Requirement { + name: "colorama", + extras: None, + version_or_url: Some( + VersionSpecifier( + VersionSpecifiers( + [ + VersionSpecifier { + operator: GreaterThanEqual, + version: Version { + epoch: 0, + release: [ + 0, + 4, + 3, + ], + pre: None, + post: None, + dev: None, + local: None, + }, + }, + ], + ), + ), + ), + marker: Some( + Expression( + MarkerExpression { + l_value: Extra, + operator: Equal, + r_value: QuotedString( + "colorama", + ), + }, + ), + ), + }, + Requirement { + name: "aiohttp", + extras: None, + version_or_url: Some( + VersionSpecifier( + VersionSpecifiers( + [ + VersionSpecifier { + operator: GreaterThanEqual, + version: Version { + epoch: 0, + release: [ + 3, + 7, + 4, + ], + pre: None, + post: None, + dev: None, + local: None, + }, + }, + ], + ), + ), + ), + marker: Some( + Expression( + MarkerExpression { + l_value: Extra, + operator: Equal, + r_value: QuotedString( + "d", + ), + }, + ), + ), + }, + Requirement { + name: "ipython", + extras: None, + version_or_url: Some( + VersionSpecifier( + VersionSpecifiers( + [ + VersionSpecifier { + operator: GreaterThanEqual, + version: Version { + epoch: 0, + release: [ + 7, + 8, + 0, + ], + pre: None, + post: None, + dev: None, + local: None, + }, + }, + ], + ), + ), + ), + marker: Some( + Expression( + MarkerExpression { + l_value: Extra, + operator: Equal, + r_value: QuotedString( + "jupyter", + ), + }, + ), + ), + }, + Requirement { + name: "tokenize-rt", + extras: None, + version_or_url: Some( + VersionSpecifier( + VersionSpecifiers( + [ + VersionSpecifier { + operator: GreaterThanEqual, + version: Version { + epoch: 0, + release: [ + 3, + 2, + 0, + ], + pre: None, + post: None, + dev: None, + local: None, + }, + }, + ], + ), + ), + ), + marker: Some( + Expression( + MarkerExpression { + l_value: Extra, + operator: Equal, + r_value: QuotedString( + "jupyter", + ), + }, + ), + ), + }, + Requirement { + name: "uvloop", + extras: None, + version_or_url: Some( + VersionSpecifier( + VersionSpecifiers( + [ + VersionSpecifier { + operator: GreaterThanEqual, + version: Version { + epoch: 0, + release: [ + 0, + 15, + 2, + ], + pre: None, + post: None, + dev: None, + local: None, + }, + }, + ], + ), + ), + ), + marker: Some( + Expression( + MarkerExpression { + l_value: Extra, + operator: Equal, + r_value: QuotedString( + "uvloop", + ), + }, + ), + ), + }, +] diff --git a/crates/rattler_installs_packages/src/types/project_info.rs b/crates/rattler_installs_packages/src/types/project_info.rs index a4877667..504671c8 100644 --- a/crates/rattler_installs_packages/src/types/project_info.rs +++ b/crates/rattler_installs_packages/src/types/project_info.rs @@ -50,11 +50,6 @@ impl ArtifactInfo { pub fn is(&self) -> bool { self.filename.as_inner::().is_some() } - - // /// Returns true if this artifact is gathered by direct reference - // pub fn is_direct_dependency(&self) -> bool { - // self.filename.is_direct_reference() - // } } /// Describes a set of hashes for a certain artifact. In theory all hash algorithms available via From bfea618bb24bf9f1d150a9af6ad6ac765657e22e Mon Sep 17 00:00:00 2001 From: nichmor Date: Thu, 8 Feb 2024 14:25:43 +0200 Subject: [PATCH 07/19] misc: fix intra-doc links --- crates/rattler_installs_packages/src/artifacts/sdist.rs | 4 ++-- crates/rattler_installs_packages/src/resolve/solve_options.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/rattler_installs_packages/src/artifacts/sdist.rs b/crates/rattler_installs_packages/src/artifacts/sdist.rs index 0e92821d..08643ace 100644 --- a/crates/rattler_installs_packages/src/artifacts/sdist.rs +++ b/crates/rattler_installs_packages/src/artifacts/sdist.rs @@ -268,8 +268,8 @@ mod tests { use crate::resolve::PypiVersion; use crate::types::{ArtifactFromSource, PackageName}; use crate::types::{ - ArtifactInfo, ArtifactName, DistInfoMetadata, Extra, - NormalizedPackageName, STreeFilename, WheelFilename, Yanked, + ArtifactInfo, ArtifactName, DistInfoMetadata, Extra, NormalizedPackageName, STreeFilename, + WheelFilename, Yanked, }; use crate::types::{SDistFilename, SDistFormat}; use crate::wheel_builder::WheelBuilder; diff --git a/crates/rattler_installs_packages/src/resolve/solve_options.rs b/crates/rattler_installs_packages/src/resolve/solve_options.rs index 69549712..69f0efbe 100644 --- a/crates/rattler_installs_packages/src/resolve/solve_options.rs +++ b/crates/rattler_installs_packages/src/resolve/solve_options.rs @@ -186,7 +186,7 @@ pub enum OnWheelBuildFailure { } /// Additional options that may influence the solver. In general passing [`Default::default`] to -/// the [`resolve::resolve`] function should provide sane defaults, however if you want to fine tune the +/// the [`crate::resolve::resolve`] function should provide sane defaults, however if you want to fine tune the /// resolver you can do so via this struct. #[derive(Default, Clone)] pub struct ResolveOptions { From f54fb42bb284dc5829513e7a0e539b29d2d92b8b Mon Sep 17 00:00:00 2001 From: nichmor Date: Thu, 8 Feb 2024 14:28:55 +0200 Subject: [PATCH 08/19] misc: remove direct url from wheel struct --- crates/rattler_installs_packages/src/artifacts/wheel.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/crates/rattler_installs_packages/src/artifacts/wheel.rs b/crates/rattler_installs_packages/src/artifacts/wheel.rs index d8324605..c0959de1 100644 --- a/crates/rattler_installs_packages/src/artifacts/wheel.rs +++ b/crates/rattler_installs_packages/src/artifacts/wheel.rs @@ -47,8 +47,6 @@ use crate::win::launcher::{build_windows_launcher, LauncherType, WindowsLauncher pub struct Wheel { /// Name of wheel pub name: WheelFilename, - /// Possible direct url - pub direct_url: Option, archive: Mutex>>, } @@ -66,7 +64,6 @@ impl ArtifactFromBytes for Wheel { Ok(Self { name, archive: Mutex::new(ZipArchive::new(bytes).into_diagnostic()?), - direct_url: None, }) } } From 8ebfba57bebf31b7d27e991a0138dbf69af4fa4c Mon Sep 17 00:00:00 2001 From: nichmor Date: Thu, 8 Feb 2024 14:30:20 +0200 Subject: [PATCH 09/19] misc: remove unused url --- crates/rattler_installs_packages/src/artifacts/wheel.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/rattler_installs_packages/src/artifacts/wheel.rs b/crates/rattler_installs_packages/src/artifacts/wheel.rs index c0959de1..f106d9f6 100644 --- a/crates/rattler_installs_packages/src/artifacts/wheel.rs +++ b/crates/rattler_installs_packages/src/artifacts/wheel.rs @@ -36,7 +36,6 @@ use std::{ }; use thiserror::Error; use tokio_util::compat::TokioAsyncReadCompatExt; -use url::Url; use zip::{result::ZipError, ZipArchive}; use crate::win::launcher::{build_windows_launcher, LauncherType, WindowsLauncherArch}; From c85d172daba3a7730983cdc4a67ab6930ec2ccd6 Mon Sep 17 00:00:00 2001 From: nichmor Date: Thu, 8 Feb 2024 15:02:06 +0200 Subject: [PATCH 10/19] feat: record direc url json --- .../src/artifacts/sdist.rs | 27 ++++++++-- .../src/artifacts/stree.rs | 1 + .../src/artifacts/wheel.rs | 4 +- .../src/index/direct_url/file.rs | 14 +++-- .../src/index/direct_url/git.rs | 16 ++++-- .../src/index/direct_url/http.rs | 20 +++++-- .../src/index/git_interop.rs | 4 +- .../src/index/package_database.rs | 54 ++++++++++++++++--- .../src/types/direct_url_json.rs | 2 +- .../src/wheel_builder/build_environment.rs | 13 +++-- crates/rip_bin/src/main.rs | 14 +++-- 11 files changed, 134 insertions(+), 35 deletions(-) diff --git a/crates/rattler_installs_packages/src/artifacts/sdist.rs b/crates/rattler_installs_packages/src/artifacts/sdist.rs index 08643ace..7a3741cc 100644 --- a/crates/rattler_installs_packages/src/artifacts/sdist.rs +++ b/crates/rattler_installs_packages/src/artifacts/sdist.rs @@ -1,7 +1,7 @@ use crate::resolve::PypiVersion; use crate::types::{ - ArtifactFromBytes, ArtifactFromSource, HasArtifactName, NormalizedPackageName, PackageInfo, - ReadPyProjectError, SDistFilename, SDistFormat, SourceArtifactName, + ArtifactFromBytes, ArtifactFromSource, DirectUrlJson, HasArtifactName, NormalizedPackageName, + PackageInfo, ReadPyProjectError, SDistFilename, SDistFormat, SourceArtifactName, }; use crate::types::{WheelCoreMetaDataError, WheelCoreMetadata}; use crate::utils::ReadAndSeek; @@ -920,7 +920,7 @@ mod tests { yanked: Yanked::default(), }; - let whl = package_db + let (whl, _) = package_db .0 .get_wheel(&artifact_info, Some(&wheel_builder)) .await @@ -983,12 +983,29 @@ mod tests { yanked: Yanked::default(), }; - let whl = package_db + let (whl, _) = package_db .0 .get_wheel(&artifact_info, Some(&wheel_builder)) .await .unwrap(); + // Install wheel to test if all vitals are correctly built + let tmpdir = tempdir().unwrap(); + + let venv = VEnv::create(tmpdir.path(), PythonLocation::System).unwrap(); + + venv.install_wheel(&whl, &Default::default()).unwrap(); + + // Check to make sure that the headers directory was created + assert!(venv + .root() + .join( + venv.install_paths() + .site_packages() + .join("rich/__init__.py") + ) + .exists()); + let whl_metadata = whl.metadata().unwrap(); assert_debug_snapshot!(whl_metadata.1); @@ -1026,7 +1043,7 @@ mod tests { yanked: Yanked::default(), }; - let whl = package_db + let (whl, _) = package_db .0 .get_wheel(&artifact_info, Some(&wheel_builder)) .await diff --git a/crates/rattler_installs_packages/src/artifacts/stree.rs b/crates/rattler_installs_packages/src/artifacts/stree.rs index 3e54ba3c..ec42448c 100644 --- a/crates/rattler_installs_packages/src/artifacts/stree.rs +++ b/crates/rattler_installs_packages/src/artifacts/stree.rs @@ -1,5 +1,6 @@ use crate::resolve::PypiVersion; use crate::types::ArtifactFromSource; +use crate::types::DirectUrlJson; use crate::types::ReadPyProjectError; use crate::types::{HasArtifactName, STreeFilename, SourceArtifactName}; use fs_err as fs; diff --git a/crates/rattler_installs_packages/src/artifacts/wheel.rs b/crates/rattler_installs_packages/src/artifacts/wheel.rs index f106d9f6..4b93aed6 100644 --- a/crates/rattler_installs_packages/src/artifacts/wheel.rs +++ b/crates/rattler_installs_packages/src/artifacts/wheel.rs @@ -1450,9 +1450,9 @@ mod test { let direct_url = DirectUrlJson { url: Url::from_directory_path(&package_path).unwrap(), source: DirectUrlSource::Archive { - hashes: DirectUrlHashes { + hashes: Some(DirectUrlHashes { sha256: "95a7e86f46de9b5da6ec9365e1e96d1644c67328".to_string(), - }, + }), }, }; let wheel = venv diff --git a/crates/rattler_installs_packages/src/index/direct_url/file.rs b/crates/rattler_installs_packages/src/index/direct_url/file.rs index e15717ad..d20177ef 100644 --- a/crates/rattler_installs_packages/src/index/direct_url/file.rs +++ b/crates/rattler_installs_packages/src/index/direct_url/file.rs @@ -2,9 +2,9 @@ use crate::artifacts::{SDist, STree, Wheel}; use crate::index::package_database::DirectUrlArtifactResponse; use crate::resolve::PypiVersion; use crate::types::{ - ArtifactFromBytes, ArtifactHashes, ArtifactInfo, ArtifactType, DistInfoMetadata, - NormalizedPackageName, PackageName, SDistFilename, SDistFormat, STreeFilename, - WheelCoreMetadata, Yanked, + ArtifactFromBytes, ArtifactHashes, ArtifactInfo, ArtifactType, DirectUrlJson, DirectUrlSource, + DistInfoMetadata, NormalizedPackageName, PackageName, SDistFilename, SDistFormat, + STreeFilename, WheelCoreMetadata, Yanked, }; use crate::wheel_builder::{WheelBuildError, WheelBuilder}; use indexmap::IndexMap; @@ -129,7 +129,7 @@ pub(crate) async fn get_artifacts_and_metadata>( let normalized_package_name = p.into(); let (metadata_bytes, metadata, artifact) = if path.is_file() && str_name.ends_with(".whl") { - let wheel = Wheel::from_path(&path, &normalized_package_name) + let mut wheel = Wheel::from_path(&path, &normalized_package_name) .map_err(|e| WheelBuildError::Error(format!("Could not build wheel: {}", e))) .into_diagnostic()?; @@ -179,10 +179,16 @@ pub(crate) async fn get_artifacts_and_metadata>( let mut result = IndexMap::default(); result.insert(PypiVersion::Url(url.clone()), vec![artifact_info.clone()]); + let direct_url_json = DirectUrlJson { + url: url.clone(), + source: DirectUrlSource::Dir { editable: None }, + }; + Ok(DirectUrlArtifactResponse { artifact_info, metadata: (metadata_bytes, metadata), artifact_versions: result, artifact, + direct_url_json, }) } diff --git a/crates/rattler_installs_packages/src/index/direct_url/git.rs b/crates/rattler_installs_packages/src/index/direct_url/git.rs index 625da61c..a9808d99 100644 --- a/crates/rattler_installs_packages/src/index/direct_url/git.rs +++ b/crates/rattler_installs_packages/src/index/direct_url/git.rs @@ -2,8 +2,8 @@ use crate::index::git_interop::{git_clone, GitSource, ParsedUrl}; use crate::index::package_database::DirectUrlArtifactResponse; use crate::resolve::PypiVersion; use crate::types::{ - ArtifactHashes, ArtifactInfo, ArtifactName, ArtifactType, DistInfoMetadata, HasArtifactName, - NormalizedPackageName, Yanked, + ArtifactHashes, ArtifactInfo, ArtifactName, ArtifactType, DirectUrlJson, DirectUrlSource, + DirectUrlVcs, DistInfoMetadata, HasArtifactName, NormalizedPackageName, Yanked, }; use crate::wheel_builder::WheelBuilder; use indexmap::IndexMap; @@ -27,7 +27,7 @@ pub(crate) async fn get_artifacts_and_metadata>( rev: parsed_url.revision, }; - let mut location = git_clone(&git_source).into_diagnostic()?; + let (mut location, git_rev) = git_clone(&git_source).into_diagnostic()?; if let Some(subdirectory) = parsed_url.subdirectory { location.push(&subdirectory); @@ -60,6 +60,15 @@ pub(crate) async fn get_artifacts_and_metadata>( reason: None, }; + let direct_url_json = DirectUrlJson { + url: url.clone(), + source: DirectUrlSource::Vcs { + vcs: DirectUrlVcs::Git, + requested_revision: git_source.rev, + commit_id: git_rev.get_commit(), + }, + }; + let project_hash = ArtifactHashes { sha256: Some(compute_bytes_digest::(url.as_str().as_bytes())), }; @@ -82,5 +91,6 @@ pub(crate) async fn get_artifacts_and_metadata>( metadata: (wheel_metadata.0, wheel_metadata.1), artifact_versions: result, artifact: ArtifactType::STree(artifact), + direct_url_json, }) } diff --git a/crates/rattler_installs_packages/src/index/direct_url/http.rs b/crates/rattler_installs_packages/src/index/direct_url/http.rs index 7a74c076..9290cbcc 100644 --- a/crates/rattler_installs_packages/src/index/direct_url/http.rs +++ b/crates/rattler_installs_packages/src/index/direct_url/http.rs @@ -3,8 +3,9 @@ use crate::index::http::Http; use crate::index::{parse_hash, CacheMode}; use crate::resolve::PypiVersion; use crate::types::{ - ArtifactFromBytes, ArtifactHashes, ArtifactInfo, ArtifactType, DistInfoMetadata, - NormalizedPackageName, PackageName, SDistFilename, SDistFormat, WheelCoreMetadata, Yanked, + ArtifactFromBytes, ArtifactHashes, ArtifactInfo, ArtifactType, DirectUrlHashes, DirectUrlJson, + DirectUrlSource, DistInfoMetadata, NormalizedPackageName, PackageName, SDistFilename, + SDistFormat, WheelCoreMetadata, Yanked, }; use crate::utils::ReadAndSeek; use crate::wheel_builder::WheelBuilder; @@ -45,14 +46,14 @@ pub(crate) async fn get_artifacts_and_metadata>( .await .into_diagnostic()?; + let mut bytes_for_hash = vec![]; let artifact_hash = { - let mut bytes_for_hash = vec![]; bytes.rewind().into_diagnostic()?; bytes.read_to_end(&mut bytes_for_hash).into_diagnostic()?; bytes.rewind().into_diagnostic()?; ArtifactHashes { sha256: Some(rattler_digest::compute_bytes_digest::( - bytes_for_hash, + bytes_for_hash.clone(), )), } }; @@ -92,11 +93,22 @@ pub(crate) async fn get_artifacts_and_metadata>( let mut result = IndexMap::default(); result.insert(PypiVersion::Url(url.clone()), vec![artifact_info.clone()]); + let hash_string = String::from_utf8_lossy(&bytes_for_hash); + let direct_url_json = DirectUrlJson { + url: url.clone(), + source: DirectUrlSource::Archive { + hashes: Some(DirectUrlHashes { + sha256: hash_string.to_string(), + }), + }, + }; + Ok(crate::index::package_database::DirectUrlArtifactResponse { artifact_info, metadata: (metadata_bytes, metadata), artifact_versions: result, artifact, + direct_url_json, }) } diff --git a/crates/rattler_installs_packages/src/index/git_interop.rs b/crates/rattler_installs_packages/src/index/git_interop.rs index 72fcec8b..4468e300 100644 --- a/crates/rattler_installs_packages/src/index/git_interop.rs +++ b/crates/rattler_installs_packages/src/index/git_interop.rs @@ -300,7 +300,7 @@ fn get_revision_sha(dest: &PathBuf, rev: Option) -> Result Result { +pub fn git_clone(source: &GitSource) -> Result<(PathBuf, GitRev), SourceError> { // test if git is available locally as we fetch the git from PATH, if !Command::new("git") .arg("--version") @@ -436,5 +436,5 @@ pub fn git_clone(source: &GitSource) -> Result { } } - Ok(cache_path) + Ok((cache_path, git_rev)) } diff --git a/crates/rattler_installs_packages/src/index/package_database.rs b/crates/rattler_installs_packages/src/index/package_database.rs index 6a4cd6e6..4b3c4ba1 100644 --- a/crates/rattler_installs_packages/src/index/package_database.rs +++ b/crates/rattler_installs_packages/src/index/package_database.rs @@ -5,7 +5,10 @@ use crate::index::html::{parse_package_names_html, parse_project_info_html}; use crate::index::http::{CacheMode, Http, HttpRequestError}; use crate::index::package_sources::PackageSources; use crate::resolve::PypiVersion; -use crate::types::{ArtifactInfo, ArtifactType, ProjectInfo, STreeFilename, WheelCoreMetadata}; +use crate::types::{ + ArtifactInfo, ArtifactType, DirectUrlHashes, DirectUrlJson, DirectUrlSource, ProjectInfo, + STreeFilename, WheelCoreMetadata, +}; use crate::wheel_builder::{WheelBuildError, WheelBuilder, WheelCache}; use crate::{ @@ -31,6 +34,8 @@ use std::{fmt::Display, io::Read, path::Path}; use url::Url; +use super::direct_url; + type VersionArtifacts = IndexMap>>; /// Cache of the available packages, artifacts and their metadata. @@ -72,6 +77,7 @@ pub(crate) struct DirectUrlArtifactResponse { pub(crate) artifact_versions: VersionArtifacts, pub(crate) metadata: (Vec, WheelCoreMetadata), pub(crate) artifact: ArtifactType, + pub(crate) direct_url_json: DirectUrlJson, } impl PackageDb { @@ -230,7 +236,7 @@ impl PackageDb { &self, artifact_info: &ArtifactInfo, builder: Option<&'async_recursion WheelBuilder>, - ) -> miette::Result { + ) -> miette::Result<(Wheel, Option)> { // TODO: add support for this currently there are not saved if artifact_info.is_direct_url { if let Some(builder) = builder { @@ -243,12 +249,16 @@ impl PackageDb { .await?; match response.artifact { - ArtifactType::Wheel(wheel) => return Ok(wheel), + ArtifactType::Wheel(wheel) => { + return Ok((wheel, Some(response.direct_url_json))) + } ArtifactType::SDist(sdist) => { - return builder.build_wheel(&sdist).await.into_diagnostic() + let whl = builder.build_wheel(&sdist).await.into_diagnostic()?; + return Ok((whl, None)); } ArtifactType::STree(stree) => { - return builder.build_wheel(&stree).await.into_diagnostic() + let whl = builder.build_wheel(&stree).await.into_diagnostic()?; + return Ok((whl, None)); } } } else { @@ -263,15 +273,45 @@ impl PackageDb { .get_cached_artifact::(artifact_info, CacheMode::Default) .await?; - return builder.build_wheel(&sdist).await.into_diagnostic(); + let whl = builder + .build_wheel(&sdist) + .await + .into_diagnostic() + .expect("cannot build wheel"); + + let direct_url = if artifact_info.is_direct_url { + let direct_url_hash = if let Some(hash) = artifact_info.hashes.clone() { + if let Some(sha256) = hash.sha256 { + let str = format!("{:x}", sha256); + Some(DirectUrlHashes { sha256: str }) + } else { + None + } + } else { + None + }; + Some(DirectUrlJson { + url: artifact_info.url.clone(), + source: DirectUrlSource::Archive { + hashes: direct_url_hash, + }, + }) + } else { + None + }; + + return Ok((whl, direct_url)); } else { miette::bail!("cannot build wheel without a wheel builder"); } } // Otherwise just retrieve the wheel - self.get_cached_artifact::(artifact_info, CacheMode::Default) + let cached_whl = self + .get_cached_artifact::(artifact_info, CacheMode::Default) .await + .expect("cannot build wheel"); + return Ok((cached_whl, None)); } /// Get artifact directly from file, vcs, or url diff --git a/crates/rattler_installs_packages/src/types/direct_url_json.rs b/crates/rattler_installs_packages/src/types/direct_url_json.rs index a52fa19a..ceb4d317 100644 --- a/crates/rattler_installs_packages/src/types/direct_url_json.rs +++ b/crates/rattler_installs_packages/src/types/direct_url_json.rs @@ -23,7 +23,7 @@ pub enum DirectUrlSource { /// Information about the archive file. Archive { /// Hashes of the archive file. - hashes: DirectUrlHashes, + hashes: Option, }, /// Information about a source from a VCS directly #[serde(rename = "vcs_info")] diff --git a/crates/rattler_installs_packages/src/wheel_builder/build_environment.rs b/crates/rattler_installs_packages/src/wheel_builder/build_environment.rs index 95767570..8a1068fb 100644 --- a/crates/rattler_installs_packages/src/wheel_builder/build_environment.rs +++ b/crates/rattler_installs_packages/src/wheel_builder/build_environment.rs @@ -257,14 +257,19 @@ impl BuildEnvironment { package_info.version ); let artifact_info = package_info.artifacts.first().unwrap(); - let artifact = wheel_builder + let (artifact, direct_url_json) = wheel_builder .package_db .get_wheel(artifact_info, Some(wheel_builder)) .await .expect("could not get artifact"); - self.venv - .install_wheel(&artifact, &UnpackWheelOptions::default())?; + self.venv.install_wheel( + &artifact, + &UnpackWheelOptions { + direct_url_json, + ..Default::default() + }, + )?; } } Ok(()) @@ -410,7 +415,7 @@ impl BuildEnvironment { for package_info in resolved_wheels.iter() { let artifact_info = package_info.artifacts.first().unwrap(); - let artifact = wheel_builder + let (artifact, _) = wheel_builder .package_db .get_wheel(artifact_info, Some(wheel_builder)) .await diff --git a/crates/rip_bin/src/main.rs b/crates/rip_bin/src/main.rs index b629d741..12328e0c 100644 --- a/crates/rip_bin/src/main.rs +++ b/crates/rip_bin/src/main.rs @@ -1,5 +1,6 @@ use fs_err as fs; use rattler_installs_packages::resolve::solve_options::{PreReleaseResolution, ResolveOptions}; +use rattler_installs_packages::types::{DirectUrlJson, DirectUrlSource}; use rip_bin::{global_multi_progress, IndicatifWriter}; use serde::Serialize; use std::collections::HashMap; @@ -301,11 +302,18 @@ async fn actual_main() -> miette::Result<()> { console::style(pinned_package.version).italic() ); let artifact_info = pinned_package.artifacts.first().unwrap(); - let artifact = package_db + let (artifact, direct_url_json) = package_db .get_wheel(artifact_info, Some(&wheel_builder)) .await?; - venv.install_wheel(&artifact, &UnpackWheelOptions::default()) - .into_diagnostic()?; + println!("DIRECT URL JSON IS {:?}", direct_url_json); + venv.install_wheel( + &artifact, + &UnpackWheelOptions { + direct_url_json, + ..Default::default() + }, + ) + .into_diagnostic()?; } } From 3979b657257b25d5a922ebf58b49de1b1984f792 Mon Sep 17 00:00:00 2001 From: nichmor Date: Thu, 8 Feb 2024 15:41:43 +0200 Subject: [PATCH 11/19] feat: always record direct_url.json --- .../src/artifacts/sdist.rs | 4 ++-- .../src/artifacts/stree.rs | 1 - .../src/index/direct_url/file.rs | 2 +- .../src/index/direct_url/git.rs | 3 ++- .../src/index/direct_url/http.rs | 15 ++++++++---- .../src/index/git_interop.rs | 2 +- .../src/index/package_database.rs | 24 +++++++++---------- crates/rip_bin/src/main.rs | 1 - 8 files changed, 28 insertions(+), 24 deletions(-) diff --git a/crates/rattler_installs_packages/src/artifacts/sdist.rs b/crates/rattler_installs_packages/src/artifacts/sdist.rs index 7a3741cc..2b1ce2a6 100644 --- a/crates/rattler_installs_packages/src/artifacts/sdist.rs +++ b/crates/rattler_installs_packages/src/artifacts/sdist.rs @@ -1,7 +1,7 @@ use crate::resolve::PypiVersion; use crate::types::{ - ArtifactFromBytes, ArtifactFromSource, DirectUrlJson, HasArtifactName, NormalizedPackageName, - PackageInfo, ReadPyProjectError, SDistFilename, SDistFormat, SourceArtifactName, + ArtifactFromBytes, ArtifactFromSource, HasArtifactName, NormalizedPackageName, PackageInfo, + ReadPyProjectError, SDistFilename, SDistFormat, SourceArtifactName, }; use crate::types::{WheelCoreMetaDataError, WheelCoreMetadata}; use crate::utils::ReadAndSeek; diff --git a/crates/rattler_installs_packages/src/artifacts/stree.rs b/crates/rattler_installs_packages/src/artifacts/stree.rs index ec42448c..3e54ba3c 100644 --- a/crates/rattler_installs_packages/src/artifacts/stree.rs +++ b/crates/rattler_installs_packages/src/artifacts/stree.rs @@ -1,6 +1,5 @@ use crate::resolve::PypiVersion; use crate::types::ArtifactFromSource; -use crate::types::DirectUrlJson; use crate::types::ReadPyProjectError; use crate::types::{HasArtifactName, STreeFilename, SourceArtifactName}; use fs_err as fs; diff --git a/crates/rattler_installs_packages/src/index/direct_url/file.rs b/crates/rattler_installs_packages/src/index/direct_url/file.rs index d20177ef..b4f2c996 100644 --- a/crates/rattler_installs_packages/src/index/direct_url/file.rs +++ b/crates/rattler_installs_packages/src/index/direct_url/file.rs @@ -129,7 +129,7 @@ pub(crate) async fn get_artifacts_and_metadata>( let normalized_package_name = p.into(); let (metadata_bytes, metadata, artifact) = if path.is_file() && str_name.ends_with(".whl") { - let mut wheel = Wheel::from_path(&path, &normalized_package_name) + let wheel = Wheel::from_path(&path, &normalized_package_name) .map_err(|e| WheelBuildError::Error(format!("Could not build wheel: {}", e))) .into_diagnostic()?; diff --git a/crates/rattler_installs_packages/src/index/direct_url/git.rs b/crates/rattler_installs_packages/src/index/direct_url/git.rs index a9808d99..99569fa4 100644 --- a/crates/rattler_installs_packages/src/index/direct_url/git.rs +++ b/crates/rattler_installs_packages/src/index/direct_url/git.rs @@ -9,6 +9,7 @@ use crate::wheel_builder::WheelBuilder; use indexmap::IndexMap; use miette::IntoDiagnostic; use rattler_digest::{compute_bytes_digest, Sha256}; +use std::str::FromStr; use std::sync::Arc; use url::Url; @@ -61,7 +62,7 @@ pub(crate) async fn get_artifacts_and_metadata>( }; let direct_url_json = DirectUrlJson { - url: url.clone(), + url: Url::from_str(parsed_url.url.as_str()).expect("URL should be parseable"), source: DirectUrlSource::Vcs { vcs: DirectUrlVcs::Git, requested_revision: git_source.rev, diff --git a/crates/rattler_installs_packages/src/index/direct_url/http.rs b/crates/rattler_installs_packages/src/index/direct_url/http.rs index 9290cbcc..fdee7e26 100644 --- a/crates/rattler_installs_packages/src/index/direct_url/http.rs +++ b/crates/rattler_installs_packages/src/index/direct_url/http.rs @@ -46,8 +46,8 @@ pub(crate) async fn get_artifacts_and_metadata>( .await .into_diagnostic()?; - let mut bytes_for_hash = vec![]; let artifact_hash = { + let mut bytes_for_hash = vec![]; bytes.rewind().into_diagnostic()?; bytes.read_to_end(&mut bytes_for_hash).into_diagnostic()?; bytes.rewind().into_diagnostic()?; @@ -62,6 +62,13 @@ pub(crate) async fn get_artifacts_and_metadata>( assert_eq!(hash, artifact_hash); }; + let hash_str = format!( + "{:x}", + artifact_hash + .sha256 + .expect("hash should be already calculated") + ); + let (metadata_bytes, metadata, artifact) = if str_name.ends_with(".whl") { let wheel = Wheel::from_url_and_bytes(url.path(), &normalized_package_name, bytes)?; @@ -93,13 +100,11 @@ pub(crate) async fn get_artifacts_and_metadata>( let mut result = IndexMap::default(); result.insert(PypiVersion::Url(url.clone()), vec![artifact_info.clone()]); - let hash_string = String::from_utf8_lossy(&bytes_for_hash); + // let hash_string = String::from_ut(&bytes_for_hash); let direct_url_json = DirectUrlJson { url: url.clone(), source: DirectUrlSource::Archive { - hashes: Some(DirectUrlHashes { - sha256: hash_string.to_string(), - }), + hashes: Some(DirectUrlHashes { sha256: hash_str }), }, }; diff --git a/crates/rattler_installs_packages/src/index/git_interop.rs b/crates/rattler_installs_packages/src/index/git_interop.rs index 4468e300..c6cf9fb7 100644 --- a/crates/rattler_installs_packages/src/index/git_interop.rs +++ b/crates/rattler_installs_packages/src/index/git_interop.rs @@ -263,7 +263,7 @@ fn get_revision_sha(dest: &PathBuf, rev: Option) -> Result>>; /// Cache of the available packages, artifacts and their metadata. @@ -239,6 +237,10 @@ impl PackageDb { ) -> miette::Result<(Wheel, Option)> { // TODO: add support for this currently there are not saved if artifact_info.is_direct_url { + println!( + "IS DIRECT URL !!! {:?}", + artifact_info.filename.distribution_name() + ); if let Some(builder) = builder { let response = super::direct_url::fetch_artifact_and_metadata_by_direct_url( &self.http, @@ -248,19 +250,17 @@ impl PackageDb { ) .await?; - match response.artifact { - ArtifactType::Wheel(wheel) => { - return Ok((wheel, Some(response.direct_url_json))) - } + let whl = match response.artifact { + ArtifactType::Wheel(wheel) => wheel, ArtifactType::SDist(sdist) => { - let whl = builder.build_wheel(&sdist).await.into_diagnostic()?; - return Ok((whl, None)); + builder.build_wheel(&sdist).await.into_diagnostic()? } ArtifactType::STree(stree) => { - let whl = builder.build_wheel(&stree).await.into_diagnostic()?; - return Ok((whl, None)); + builder.build_wheel(&stree).await.into_diagnostic()? } - } + }; + + return Ok((whl, Some(response.direct_url_json))); } else { miette::bail!("cannot build wheel without a wheel builder"); } @@ -311,7 +311,7 @@ impl PackageDb { .get_cached_artifact::(artifact_info, CacheMode::Default) .await .expect("cannot build wheel"); - return Ok((cached_whl, None)); + Ok((cached_whl, None)) } /// Get artifact directly from file, vcs, or url diff --git a/crates/rip_bin/src/main.rs b/crates/rip_bin/src/main.rs index 12328e0c..d2a5f2b8 100644 --- a/crates/rip_bin/src/main.rs +++ b/crates/rip_bin/src/main.rs @@ -1,6 +1,5 @@ use fs_err as fs; use rattler_installs_packages::resolve::solve_options::{PreReleaseResolution, ResolveOptions}; -use rattler_installs_packages::types::{DirectUrlJson, DirectUrlSource}; use rip_bin::{global_multi_progress, IndicatifWriter}; use serde::Serialize; use std::collections::HashMap; From 154b986cb7cbba46e5561e15c0fc310a7ae472b0 Mon Sep 17 00:00:00 2001 From: nichmor Date: Thu, 8 Feb 2024 16:00:31 +0200 Subject: [PATCH 12/19] misc: change tests --- crates/rattler_installs_packages/src/artifacts/sdist.rs | 6 +++--- .../rattler_installs_packages/src/index/direct_url/git.rs | 7 +++---- .../src/index/package_database.rs | 2 +- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/crates/rattler_installs_packages/src/artifacts/sdist.rs b/crates/rattler_installs_packages/src/artifacts/sdist.rs index 08643ace..636ef5dd 100644 --- a/crates/rattler_installs_packages/src/artifacts/sdist.rs +++ b/crates/rattler_installs_packages/src/artifacts/sdist.rs @@ -920,7 +920,7 @@ mod tests { yanked: Yanked::default(), }; - let whl = package_db + let (whl, _) = package_db .0 .get_wheel(&artifact_info, Some(&wheel_builder)) .await @@ -983,7 +983,7 @@ mod tests { yanked: Yanked::default(), }; - let whl = package_db + let (whl, _) = package_db .0 .get_wheel(&artifact_info, Some(&wheel_builder)) .await @@ -1026,7 +1026,7 @@ mod tests { yanked: Yanked::default(), }; - let whl = package_db + let (whl, _) = package_db .0 .get_wheel(&artifact_info, Some(&wheel_builder)) .await diff --git a/crates/rattler_installs_packages/src/index/direct_url/git.rs b/crates/rattler_installs_packages/src/index/direct_url/git.rs index cc3579c8..99569fa4 100644 --- a/crates/rattler_installs_packages/src/index/direct_url/git.rs +++ b/crates/rattler_installs_packages/src/index/direct_url/git.rs @@ -1,10 +1,9 @@ use crate::index::git_interop::{git_clone, GitSource, ParsedUrl}; use crate::index::package_database::DirectUrlArtifactResponse; use crate::resolve::PypiVersion; -use crate::types::{ -ArtifactHashes, ArtifactInfo, ArtifactName, ArtifactType, DirectUrlJson, DirectUrlSource, -DirectUrlVcs, ArtifactName, ArtifactType, DistInfoMetadata, HasArtifactName, HasArtifactName, -NormalizedPackageName, Yanked, +use crate::types::{ + ArtifactHashes, ArtifactInfo, ArtifactName, ArtifactType, DirectUrlJson, DirectUrlSource, + DirectUrlVcs, DistInfoMetadata, HasArtifactName, NormalizedPackageName, Yanked, }; use crate::wheel_builder::WheelBuilder; use indexmap::IndexMap; diff --git a/crates/rattler_installs_packages/src/index/package_database.rs b/crates/rattler_installs_packages/src/index/package_database.rs index 3f3f991f..9303f3b3 100644 --- a/crates/rattler_installs_packages/src/index/package_database.rs +++ b/crates/rattler_installs_packages/src/index/package_database.rs @@ -6,7 +6,7 @@ use crate::index::http::{CacheMode, Http, HttpRequestError}; use crate::index::package_sources::PackageSources; use crate::resolve::PypiVersion; use crate::types::{ - ArtifactInfo, ArtifactType, DirectUrlHashes, DirectUrlJson, DirectUrlSource, ArtifactType, ProjectInfo, + ArtifactInfo, ArtifactType, DirectUrlHashes, DirectUrlJson, DirectUrlSource, ProjectInfo, STreeFilename, WheelCoreMetadata, }; From dee2a7c6e87afdf9bade4051af8411f516b316af Mon Sep 17 00:00:00 2001 From: nichmor Date: Thu, 8 Feb 2024 16:02:36 +0200 Subject: [PATCH 13/19] misc: remove some comments --- crates/rattler_installs_packages/src/index/direct_url/http.rs | 1 - crates/rattler_installs_packages/src/types/artifact_name.rs | 4 ---- crates/rip_bin/src/main.rs | 1 - 3 files changed, 6 deletions(-) diff --git a/crates/rattler_installs_packages/src/index/direct_url/http.rs b/crates/rattler_installs_packages/src/index/direct_url/http.rs index fdee7e26..554aa424 100644 --- a/crates/rattler_installs_packages/src/index/direct_url/http.rs +++ b/crates/rattler_installs_packages/src/index/direct_url/http.rs @@ -100,7 +100,6 @@ pub(crate) async fn get_artifacts_and_metadata>( let mut result = IndexMap::default(); result.insert(PypiVersion::Url(url.clone()), vec![artifact_info.clone()]); - // let hash_string = String::from_ut(&bytes_for_hash); let direct_url_json = DirectUrlJson { url: url.clone(), source: DirectUrlSource::Archive { diff --git a/crates/rattler_installs_packages/src/types/artifact_name.rs b/crates/rattler_installs_packages/src/types/artifact_name.rs index dfce267f..39e02396 100644 --- a/crates/rattler_installs_packages/src/types/artifact_name.rs +++ b/crates/rattler_installs_packages/src/types/artifact_name.rs @@ -435,10 +435,6 @@ impl WheelFilename { let Some((distribution, rest)) = split_into_filename_rest(file_stem, normalized_package_name) else { - println!( - "FILE STEM IS {:?} NORM NAME {:?}", - file_stem, normalized_package_name - ); return Err(ParseArtifactNameError::PackageNameNotFound( normalized_package_name.clone(), s.to_string(), diff --git a/crates/rip_bin/src/main.rs b/crates/rip_bin/src/main.rs index d2a5f2b8..b5a86f77 100644 --- a/crates/rip_bin/src/main.rs +++ b/crates/rip_bin/src/main.rs @@ -304,7 +304,6 @@ async fn actual_main() -> miette::Result<()> { let (artifact, direct_url_json) = package_db .get_wheel(artifact_info, Some(&wheel_builder)) .await?; - println!("DIRECT URL JSON IS {:?}", direct_url_json); venv.install_wheel( &artifact, &UnpackWheelOptions { From 02727e094565851ebc1d02982be916b919630110 Mon Sep 17 00:00:00 2001 From: nichmor Date: Thu, 8 Feb 2024 16:03:41 +0200 Subject: [PATCH 14/19] misc: return ? --- .../rattler_installs_packages/src/index/package_database.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/crates/rattler_installs_packages/src/index/package_database.rs b/crates/rattler_installs_packages/src/index/package_database.rs index 9303f3b3..cf174e31 100644 --- a/crates/rattler_installs_packages/src/index/package_database.rs +++ b/crates/rattler_installs_packages/src/index/package_database.rs @@ -272,8 +272,7 @@ impl PackageDb { let whl = builder .build_wheel(&sdist) .await - .into_diagnostic() - .expect("cannot build wheel"); + .into_diagnostic()?; let direct_url = if artifact_info.is_direct_url { let direct_url_hash = if let Some(hash) = artifact_info.hashes.clone() { @@ -305,8 +304,7 @@ impl PackageDb { // Otherwise just retrieve the wheel let cached_whl = self .get_cached_artifact::(artifact_info, CacheMode::Default) - .await - .expect("cannot build wheel"); + .await?; Ok((cached_whl, None)) } From 583b8a194a09bcb0f4156787bfa74b58413dccc7 Mon Sep 17 00:00:00 2001 From: nichmor Date: Thu, 8 Feb 2024 16:04:56 +0200 Subject: [PATCH 15/19] misc: fmt --- .../rattler_installs_packages/src/index/package_database.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/crates/rattler_installs_packages/src/index/package_database.rs b/crates/rattler_installs_packages/src/index/package_database.rs index cf174e31..b1b68129 100644 --- a/crates/rattler_installs_packages/src/index/package_database.rs +++ b/crates/rattler_installs_packages/src/index/package_database.rs @@ -269,10 +269,7 @@ impl PackageDb { .get_cached_artifact::(artifact_info, CacheMode::Default) .await?; - let whl = builder - .build_wheel(&sdist) - .await - .into_diagnostic()?; + let whl = builder.build_wheel(&sdist).await.into_diagnostic()?; let direct_url = if artifact_info.is_direct_url { let direct_url_hash = if let Some(hash) = artifact_info.hashes.clone() { From b186d1c2ddd1fc77c8d83a1c27e0e19d21906891 Mon Sep 17 00:00:00 2001 From: nichmor Date: Thu, 8 Feb 2024 16:51:37 +0200 Subject: [PATCH 16/19] misc: add tests --- .../src/artifacts/sdist.rs | 171 +++++++++++++++++- ...direct_url_json_by_tag_for_remote_git.snap | 30 +++ ...check_direct_url_json_for_local_wheel.snap | 20 ++ ..._check_direct_url_json_for_remote_git.snap | 30 +++ ...heck_direct_url_json_for_remote_sdist.snap | 30 +++ 5 files changed, 280 insertions(+), 1 deletion(-) create mode 100644 crates/rattler_installs_packages/src/artifacts/snapshots/rattler_installs_packages__artifacts__sdist__tests__check_direct_url_json_by_tag_for_remote_git.snap create mode 100644 crates/rattler_installs_packages/src/artifacts/snapshots/rattler_installs_packages__artifacts__sdist__tests__check_direct_url_json_for_local_wheel.snap create mode 100644 crates/rattler_installs_packages/src/artifacts/snapshots/rattler_installs_packages__artifacts__sdist__tests__check_direct_url_json_for_remote_git.snap create mode 100644 crates/rattler_installs_packages/src/artifacts/snapshots/rattler_installs_packages__artifacts__sdist__tests__check_direct_url_json_for_remote_sdist.snap diff --git a/crates/rattler_installs_packages/src/artifacts/sdist.rs b/crates/rattler_installs_packages/src/artifacts/sdist.rs index 636ef5dd..569fa1ef 100644 --- a/crates/rattler_installs_packages/src/artifacts/sdist.rs +++ b/crates/rattler_installs_packages/src/artifacts/sdist.rs @@ -260,7 +260,7 @@ fn generic_archive_reader( #[cfg(test)] mod tests { - use crate::artifacts::SDist; + use crate::artifacts::{SDist, STree}; use crate::index::PackageDb; use crate::index::{ArtifactRequest, PackageSourcesBuilder}; use crate::python_env::{Pep508EnvMakers, PythonLocation, VEnv}; @@ -1124,4 +1124,173 @@ mod tests { assert_debug_snapshot!(wheel_metadata.1.requires_dist); } + + #[tokio::test(flavor = "multi_thread")] + pub async fn check_direct_url_json_for_local_wheel() { + let path = Path::new(env!("CARGO_MANIFEST_DIR")) + .join("../../test-data/wheels/miniblack-23.1.0-py3-none-any.whl"); + + let url = Url::from_file_path(path.canonicalize().unwrap()).unwrap(); + + let package_db = get_package_db(); + let env_markers = Arc::new(Pep508EnvMakers::from_env().await.unwrap().0); + let wheel_builder = WheelBuilder::new( + package_db.0.clone(), + env_markers, + None, + ResolveOptions::default(), + HashMap::default(), + ) + .unwrap(); + + let package_name = PackageName::from_str("miniblack").unwrap(); + let norm_name = NormalizedPackageName::from(package_name); + let whl_file_name = + WheelFilename::from_filename("miniblack-23.1.0-py3-none-any.whl", &norm_name).unwrap(); + + let artifact_info = ArtifactInfo { + filename: ArtifactName::Wheel(whl_file_name), + url: url.clone(), + is_direct_url: true, + hashes: None, + requires_python: None, + dist_info_metadata: DistInfoMetadata::default(), + yanked: Yanked::default(), + }; + + let (_, direct_url_json) = package_db + .0 + .get_wheel(&artifact_info, Some(&wheel_builder)) + .await + .unwrap(); + let mut json = direct_url_json.unwrap(); + // reset the path so it does not fail when running for different users + // where path to whl differ + json.url.set_path(""); + + assert_debug_snapshot!(json); + } + + #[tokio::test(flavor = "multi_thread")] + pub async fn check_direct_url_json_with_commit_for_remote_git() { + let url = Url::parse( + "git+https://github.com/mahmoud/boltons.git@47c8046492d4db49f163bb977d20d5942e4ddb25", + ) + .unwrap(); + + let package_db = get_package_db(); + let env_markers = Arc::new(Pep508EnvMakers::from_env().await.unwrap().0); + let wheel_builder = WheelBuilder::new( + package_db.0.clone(), + env_markers, + None, + ResolveOptions::default(), + HashMap::default(), + ) + .unwrap(); + + let norm_name = PackageName::from_str("rich").unwrap(); + let git_stree_filename = STreeFilename { + distribution: norm_name, + version: Version::from_str("0.0.0").unwrap(), + url: url.clone(), + }; + let artifact_info = ArtifactInfo { + filename: ArtifactName::STree(git_stree_filename), + url: url.clone(), + is_direct_url: true, + hashes: None, + requires_python: None, + dist_info_metadata: DistInfoMetadata::default(), + yanked: Yanked::default(), + }; + + let (_, direct_url_json) = package_db + .0 + .get_wheel(&artifact_info, Some(&wheel_builder)) + .await + .unwrap(); + + assert_debug_snapshot!(direct_url_json); + } + + #[tokio::test(flavor = "multi_thread")] + pub async fn check_direct_url_json_by_tag_for_remote_git() { + let url = Url::parse("git+https://github.com/mahmoud/boltons.git@21.0.0").unwrap(); + + let package_db = get_package_db(); + let env_markers = Arc::new(Pep508EnvMakers::from_env().await.unwrap().0); + let wheel_builder = WheelBuilder::new( + package_db.0.clone(), + env_markers, + None, + ResolveOptions::default(), + HashMap::default(), + ) + .unwrap(); + + let norm_name = PackageName::from_str("rich").unwrap(); + let git_stree_filename = STreeFilename { + distribution: norm_name, + version: Version::from_str("0.0.0").unwrap(), + url: url.clone(), + }; + let artifact_info = ArtifactInfo { + filename: ArtifactName::STree(git_stree_filename), + url: url.clone(), + is_direct_url: true, + hashes: None, + requires_python: None, + dist_info_metadata: DistInfoMetadata::default(), + yanked: Yanked::default(), + }; + + let (_, direct_url_json) = package_db + .0 + .get_wheel(&artifact_info, Some(&wheel_builder)) + .await + .unwrap(); + + assert_debug_snapshot!(direct_url_json); + } + + #[tokio::test(flavor = "multi_thread")] + pub async fn check_direct_url_json_for_remote_sdist() { + let url = Url::parse("https://files.pythonhosted.org/packages/ea/65/163134cb3c06d42557c0d1a7bc0b53d28fb674c16489f990d9e1bbccfa7b/boltons-20.2.1.tar.gz").unwrap(); + + let package_db = get_package_db(); + let env_markers = Arc::new(Pep508EnvMakers::from_env().await.unwrap().0); + let wheel_builder = WheelBuilder::new( + package_db.0.clone(), + env_markers, + None, + ResolveOptions::default(), + HashMap::default(), + ) + .unwrap(); + + let norm_name = PackageName::from_str("boltons").unwrap(); + let sdist_remote_filename = SDistFilename { + distribution: norm_name, + version: Version::from_str("0.0.0").unwrap(), + format: SDistFormat::TarGz, + }; + let artifact_info = ArtifactInfo { + filename: ArtifactName::SDist(sdist_remote_filename), + url: url.clone(), + is_direct_url: true, + hashes: None, + requires_python: None, + dist_info_metadata: DistInfoMetadata::default(), + yanked: Yanked::default(), + }; + + let (_, direct_url_json) = package_db + .0 + .get_wheel(&artifact_info, Some(&wheel_builder)) + .await + .unwrap(); + + assert_debug_snapshot!(direct_url_json); + } } diff --git a/crates/rattler_installs_packages/src/artifacts/snapshots/rattler_installs_packages__artifacts__sdist__tests__check_direct_url_json_by_tag_for_remote_git.snap b/crates/rattler_installs_packages/src/artifacts/snapshots/rattler_installs_packages__artifacts__sdist__tests__check_direct_url_json_by_tag_for_remote_git.snap new file mode 100644 index 00000000..21ff8e4c --- /dev/null +++ b/crates/rattler_installs_packages/src/artifacts/snapshots/rattler_installs_packages__artifacts__sdist__tests__check_direct_url_json_by_tag_for_remote_git.snap @@ -0,0 +1,30 @@ +--- +source: crates/rattler_installs_packages/src/artifacts/sdist.rs +expression: direct_url_json +--- +Some( + DirectUrlJson { + url: Url { + scheme: "https", + cannot_be_a_base: false, + username: "", + password: None, + host: Some( + Domain( + "github.com", + ), + ), + port: None, + path: "/mahmoud/boltons.git", + query: None, + fragment: None, + }, + source: Vcs { + vcs: Git, + requested_revision: Some( + "21.0.0", + ), + commit_id: "737daafc388a2380da5c5c517fc1d08f9db36990", + }, + }, +) diff --git a/crates/rattler_installs_packages/src/artifacts/snapshots/rattler_installs_packages__artifacts__sdist__tests__check_direct_url_json_for_local_wheel.snap b/crates/rattler_installs_packages/src/artifacts/snapshots/rattler_installs_packages__artifacts__sdist__tests__check_direct_url_json_for_local_wheel.snap new file mode 100644 index 00000000..211c8e88 --- /dev/null +++ b/crates/rattler_installs_packages/src/artifacts/snapshots/rattler_installs_packages__artifacts__sdist__tests__check_direct_url_json_for_local_wheel.snap @@ -0,0 +1,20 @@ +--- +source: crates/rattler_installs_packages/src/artifacts/sdist.rs +expression: json +--- +DirectUrlJson { + url: Url { + scheme: "file", + cannot_be_a_base: false, + username: "", + password: None, + host: None, + port: None, + path: "/", + query: None, + fragment: None, + }, + source: Dir { + editable: None, + }, +} diff --git a/crates/rattler_installs_packages/src/artifacts/snapshots/rattler_installs_packages__artifacts__sdist__tests__check_direct_url_json_for_remote_git.snap b/crates/rattler_installs_packages/src/artifacts/snapshots/rattler_installs_packages__artifacts__sdist__tests__check_direct_url_json_for_remote_git.snap new file mode 100644 index 00000000..ac2d71fd --- /dev/null +++ b/crates/rattler_installs_packages/src/artifacts/snapshots/rattler_installs_packages__artifacts__sdist__tests__check_direct_url_json_for_remote_git.snap @@ -0,0 +1,30 @@ +--- +source: crates/rattler_installs_packages/src/artifacts/sdist.rs +expression: direct_url_json +--- +Some( + DirectUrlJson { + url: Url { + scheme: "https", + cannot_be_a_base: false, + username: "", + password: None, + host: Some( + Domain( + "github.com", + ), + ), + port: None, + path: "/mahmoud/boltons.git", + query: None, + fragment: None, + }, + source: Vcs { + vcs: Git, + requested_revision: Some( + "47c8046492d4db49f163bb977d20d5942e4ddb25", + ), + commit_id: "47c8046492d4db49f163bb977d20d5942e4ddb25", + }, + }, +) diff --git a/crates/rattler_installs_packages/src/artifacts/snapshots/rattler_installs_packages__artifacts__sdist__tests__check_direct_url_json_for_remote_sdist.snap b/crates/rattler_installs_packages/src/artifacts/snapshots/rattler_installs_packages__artifacts__sdist__tests__check_direct_url_json_for_remote_sdist.snap new file mode 100644 index 00000000..7e500041 --- /dev/null +++ b/crates/rattler_installs_packages/src/artifacts/snapshots/rattler_installs_packages__artifacts__sdist__tests__check_direct_url_json_for_remote_sdist.snap @@ -0,0 +1,30 @@ +--- +source: crates/rattler_installs_packages/src/artifacts/sdist.rs +expression: direct_url_json +--- +Some( + DirectUrlJson { + url: Url { + scheme: "https", + cannot_be_a_base: false, + username: "", + password: None, + host: Some( + Domain( + "files.pythonhosted.org", + ), + ), + port: None, + path: "/packages/ea/65/163134cb3c06d42557c0d1a7bc0b53d28fb674c16489f990d9e1bbccfa7b/boltons-20.2.1.tar.gz", + query: None, + fragment: None, + }, + source: Archive { + hashes: Some( + DirectUrlHashes { + sha256: "dd362291a460cc1e0c2e91cc6a60da3036ced77099b623112e8f833e6734bdc5", + }, + ), + }, + }, +) From 24a64b508b2ce87f5d56d2185ea7eeb88b7721f6 Mon Sep 17 00:00:00 2001 From: nichmor Date: Fri, 9 Feb 2024 10:12:10 +0200 Subject: [PATCH 17/19] feat: remove unused import --- crates/rattler_installs_packages/src/artifacts/sdist.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/rattler_installs_packages/src/artifacts/sdist.rs b/crates/rattler_installs_packages/src/artifacts/sdist.rs index 569fa1ef..32e69554 100644 --- a/crates/rattler_installs_packages/src/artifacts/sdist.rs +++ b/crates/rattler_installs_packages/src/artifacts/sdist.rs @@ -260,7 +260,7 @@ fn generic_archive_reader( #[cfg(test)] mod tests { - use crate::artifacts::{SDist, STree}; + use crate::artifacts::SDist; use crate::index::PackageDb; use crate::index::{ArtifactRequest, PackageSourcesBuilder}; use crate::python_env::{Pep508EnvMakers, PythonLocation, VEnv}; From 8145cfafe48eb3c1806820ad357d8ef9ae0c9f37 Mon Sep 17 00:00:00 2001 From: nichmor Date: Fri, 9 Feb 2024 10:17:54 +0200 Subject: [PATCH 18/19] misc: add snapshot --- ...t_url_json_with_commit_for_remote_git.snap | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 crates/rattler_installs_packages/src/artifacts/snapshots/rattler_installs_packages__artifacts__sdist__tests__check_direct_url_json_with_commit_for_remote_git.snap diff --git a/crates/rattler_installs_packages/src/artifacts/snapshots/rattler_installs_packages__artifacts__sdist__tests__check_direct_url_json_with_commit_for_remote_git.snap b/crates/rattler_installs_packages/src/artifacts/snapshots/rattler_installs_packages__artifacts__sdist__tests__check_direct_url_json_with_commit_for_remote_git.snap new file mode 100644 index 00000000..ac2d71fd --- /dev/null +++ b/crates/rattler_installs_packages/src/artifacts/snapshots/rattler_installs_packages__artifacts__sdist__tests__check_direct_url_json_with_commit_for_remote_git.snap @@ -0,0 +1,30 @@ +--- +source: crates/rattler_installs_packages/src/artifacts/sdist.rs +expression: direct_url_json +--- +Some( + DirectUrlJson { + url: Url { + scheme: "https", + cannot_be_a_base: false, + username: "", + password: None, + host: Some( + Domain( + "github.com", + ), + ), + port: None, + path: "/mahmoud/boltons.git", + query: None, + fragment: None, + }, + source: Vcs { + vcs: Git, + requested_revision: Some( + "47c8046492d4db49f163bb977d20d5942e4ddb25", + ), + commit_id: "47c8046492d4db49f163bb977d20d5942e4ddb25", + }, + }, +) From 092f14b62e048b5fd4c2888c98ba71e5a434b3ae Mon Sep 17 00:00:00 2001 From: nichmor Date: Fri, 9 Feb 2024 10:21:27 +0200 Subject: [PATCH 19/19] misc: add snapshot --- ...l_json_with_commit_for_remote_git.snap.new | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 crates/rattler_installs_packages/src/artifacts/snapshots/rattler_installs_packages__artifacts__sdist__tests__check_direct_url_json_with_commit_for_remote_git.snap.new diff --git a/crates/rattler_installs_packages/src/artifacts/snapshots/rattler_installs_packages__artifacts__sdist__tests__check_direct_url_json_with_commit_for_remote_git.snap.new b/crates/rattler_installs_packages/src/artifacts/snapshots/rattler_installs_packages__artifacts__sdist__tests__check_direct_url_json_with_commit_for_remote_git.snap.new new file mode 100644 index 00000000..6e8cd12d --- /dev/null +++ b/crates/rattler_installs_packages/src/artifacts/snapshots/rattler_installs_packages__artifacts__sdist__tests__check_direct_url_json_with_commit_for_remote_git.snap.new @@ -0,0 +1,31 @@ +--- +source: crates/rattler_installs_packages/src/artifacts/sdist.rs +assertion_line: 1214 +expression: direct_url_json +--- +Some( + DirectUrlJson { + url: Url { + scheme: "https", + cannot_be_a_base: false, + username: "", + password: None, + host: Some( + Domain( + "github.com", + ), + ), + port: None, + path: "/mahmoud/boltons.git", + query: None, + fragment: None, + }, + source: Vcs { + vcs: Git, + requested_revision: Some( + "47c8046492d4db49f163bb977d20d5942e4ddb25", + ), + commit_id: "47c8046492d4db49f163bb977d20d5942e4ddb25", + }, + }, +)