Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: always record direct_url.json #211

Merged
merged 21 commits into from
Feb 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
175 changes: 172 additions & 3 deletions crates/rattler_installs_packages/src/artifacts/sdist.rs
Original file line number Diff line number Diff line change
@@ -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
@@ -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/[email protected]").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);
}
}
Original file line number Diff line number Diff line change
@@ -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",
},
},
)
Original file line number Diff line number Diff line change
@@ -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,
},
}
Original file line number Diff line number Diff line change
@@ -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",
},
},
)
Original file line number Diff line number Diff line change
@@ -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",
},
),
},
},
)
Original file line number Diff line number Diff line change
@@ -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",
},
},
)
Original file line number Diff line number Diff line change
@@ -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",
},
},
)
4 changes: 2 additions & 2 deletions crates/rattler_installs_packages/src/artifacts/wheel.rs
Original file line number Diff line number Diff line change
@@ -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
Loading