Skip to content

Commit

Permalink
feat: add support for stree in get_metadata (#199)
Browse files Browse the repository at this point in the history
refactor a little get_metadata so it's support returning metadata for
stree also

---------

Co-authored-by: Tim de Jager <[email protected]>
  • Loading branch information
nichmor and tdejager authored Feb 6, 2024
1 parent 717d667 commit b047c9e
Show file tree
Hide file tree
Showing 7 changed files with 399 additions and 43 deletions.
50 changes: 49 additions & 1 deletion crates/rattler_installs_packages/src/artifacts/sdist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,10 +266,14 @@ mod tests {
use crate::resolve::PypiVersion;
use crate::resolve::SDistResolution;
use crate::types::PackageName;
use crate::types::{ArtifactFromSource, Extra};
use crate::types::{
ArtifactFromSource, ArtifactInfo, ArtifactName, DistInfoMetadata, Extra, STreeFilename,
Yanked,
};
use crate::wheel_builder::WheelBuilder;
use crate::{index::PackageDb, resolve::ResolveOptions};
use insta::{assert_debug_snapshot, assert_ron_snapshot};
use pep440_rs::Version;
use reqwest::Client;
use reqwest_middleware::ClientWithMiddleware;
use std::collections::{HashMap, HashSet};
Expand Down Expand Up @@ -835,4 +839,48 @@ mod tests {

assert_debug_snapshot!(wheel_metadata.1);
}

#[tokio::test(flavor = "multi_thread")]
pub async fn get_only_metadata_for_local_stree_rich_without_calling_available_artifacts() {
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 = vec![ArtifactInfo {
filename: ArtifactName::STree(stree_file_name),
url: url,
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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,236 @@
---
source: crates/rattler_installs_packages/src/artifacts/sdist.rs
expression: wheel_metadata.unwrap().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",
},
},
}
4 changes: 2 additions & 2 deletions crates/rattler_installs_packages/src/index/direct_url/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ pub(crate) async fn get_artifacts_and_metadata<P: Into<NormalizedPackageName>>(
filename: artifact_name,
url: url.clone(),
hashes: Some(artifact_hash),
requires_python: metadata.requires_python,
requires_python: metadata.requires_python.clone(),
dist_info_metadata: DistInfoMetadata::default(),
yanked: Yanked::default(),
});
Expand All @@ -175,7 +175,7 @@ pub(crate) async fn get_artifacts_and_metadata<P: Into<NormalizedPackageName>>(

Ok(DirectUrlArtifactResponse {
artifact_info,
metadata_bytes,
metadata: (metadata_bytes, metadata),
artifact_versions: result,
})
}
4 changes: 2 additions & 2 deletions crates/rattler_installs_packages/src/index/direct_url/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub(crate) async fn get_artifacts_and_metadata<P: Into<NormalizedPackageName>>(
)
.await?;

let requires_python = wheel_metadata.1.requires_python;
let requires_python = wheel_metadata.1.requires_python.clone();

let dist_info_metadata = DistInfoMetadata {
available: false,
Expand Down Expand Up @@ -78,7 +78,7 @@ pub(crate) async fn get_artifacts_and_metadata<P: Into<NormalizedPackageName>>(

Ok(DirectUrlArtifactResponse {
artifact_info,
metadata_bytes: wheel_metadata.0,
metadata: (wheel_metadata.0, wheel_metadata.1),
artifact_versions: result,
})
}
4 changes: 2 additions & 2 deletions crates/rattler_installs_packages/src/index/direct_url/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ pub(crate) async fn get_artifacts_and_metadata<P: Into<NormalizedPackageName>>(
filename,
url: url.clone(),
hashes: Some(artifact_hash),
requires_python: metadata.requires_python,
requires_python: metadata.requires_python.clone(),
dist_info_metadata: DistInfoMetadata::default(),
yanked: Yanked::default(),
});
Expand All @@ -91,7 +91,7 @@ pub(crate) async fn get_artifacts_and_metadata<P: Into<NormalizedPackageName>>(

Ok(crate::index::package_database::DirectUrlArtifactResponse {
artifact_info,
metadata_bytes,
metadata: (metadata_bytes, metadata),
artifact_versions: result,
})
}
Expand Down
35 changes: 35 additions & 0 deletions crates/rattler_installs_packages/src/index/direct_url/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,38 @@
use crate::index::http::Http;
use crate::index::package_database::DirectUrlArtifactResponse;
use crate::types::NormalizedPackageName;
use crate::wheel_builder::WheelBuilder;
use url::Url;

pub(crate) mod file;
pub(crate) mod git;
pub(crate) mod http;

/// Get artifact directly from file, vcs, or url
pub(crate) async fn fetch_artifact_and_metadata_by_direct_url<P: Into<NormalizedPackageName>>(
http: &Http,
p: P,
url: Url,
wheel_builder: &WheelBuilder,
) -> miette::Result<DirectUrlArtifactResponse> {
let p = p.into();

let response = if url.scheme() == "file" {
// This can result in a Wheel, Sdist or STree
super::direct_url::file::get_artifacts_and_metadata(p.clone(), url, wheel_builder).await
} else if url.scheme() == "https" {
// This can be a Wheel or SDist artifact
super::direct_url::http::get_artifacts_and_metadata(http, p.clone(), url, wheel_builder)
.await
} else if url.scheme() == "git+https" || url.scheme() == "git+file" {
// This can be a STree artifact
super::direct_url::git::get_artifacts_and_metadata(p.clone(), url, wheel_builder).await
} else {
Err(miette::miette!(
"Usage of insecure protocol or unsupported scheme {:?}",
url.scheme()
))
}?;

Ok(response)
}
Loading

0 comments on commit b047c9e

Please sign in to comment.