-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add tool to generate resolvo snapshots (#741)
- Loading branch information
1 parent
39c6a74
commit 9bec6cb
Showing
6 changed files
with
153 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
[package] | ||
name = "create-resolvo-snapshot" | ||
version = "0.1.0" | ||
description = "Create a resolvo snapshot of a conda channel" | ||
homepage.workspace = true | ||
repository.workspace = true | ||
license.workspace = true | ||
edition.workspace = true | ||
readme = "README.md" | ||
publish = false | ||
|
||
[dependencies] | ||
clap = { workspace = true } | ||
itertools = { workspace = true } | ||
rattler_cache = { path = "../../crates/rattler_cache" } | ||
rattler_conda_types = { path = "../../crates/rattler_conda_types" } | ||
rattler_repodata_gateway = { path = "../../crates/rattler_repodata_gateway", default-features = false, features = ["rustls-tls"] } | ||
rattler_solve = { path = "../../crates/rattler_solve" } | ||
reqwest = { workspace = true, default-features = false, features = ["rustls-tls"] } | ||
resolvo = { workspace = true, features = ["serde"] } | ||
serde_json = { workspace = true } | ||
tokio = { workspace = true, features = ["rt-multi-thread"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Create-resolvo-snapshot | ||
|
||
A tool to create a resolvo snapshot from a conda channel. | ||
|
||
#### How-to-use | ||
|
||
``` | ||
create-resolvo-snapshot conda-forge --subdir linux-64 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
use std::{collections::HashSet, io::BufWriter, path::Path}; | ||
|
||
use clap::Parser; | ||
use itertools::Itertools; | ||
use rattler_conda_types::{Channel, ChannelConfig, Platform}; | ||
use rattler_repodata_gateway::fetch::FetchRepoDataOptions; | ||
use rattler_solve::{ChannelPriority, SolveStrategy}; | ||
use reqwest::Client; | ||
|
||
#[derive(Parser)] | ||
#[clap(about)] | ||
struct Args { | ||
/// The channel to make the snapshot for. | ||
channel: String, | ||
|
||
/// The subdirs to query. | ||
#[clap(short, long, num_args=1..)] | ||
subdir: Vec<Platform>, | ||
|
||
/// The output path | ||
#[clap(short)] | ||
output: Option<String>, | ||
} | ||
|
||
#[tokio::main] | ||
async fn main() { | ||
let args: Args = Args::parse(); | ||
|
||
// Determine the channel | ||
let channel = Channel::from_str( | ||
&args.channel, | ||
&ChannelConfig::default_with_root_dir(std::env::current_dir().unwrap()), | ||
) | ||
.unwrap(); | ||
|
||
// Fetch the repodata for all the subdirs. | ||
let mut subdirs: HashSet<Platform> = HashSet::from_iter(args.subdir); | ||
if subdirs.is_empty() { | ||
subdirs.insert(Platform::current()); | ||
} | ||
subdirs.insert(Platform::NoArch); | ||
|
||
let client = Client::default(); | ||
let mut records = Vec::new(); | ||
for &subdir in &subdirs { | ||
eprintln!("fetching repodata for {subdir:?}.."); | ||
let repodata = rattler_repodata_gateway::fetch::fetch_repo_data( | ||
channel.platform_url(subdir), | ||
client.clone().into(), | ||
rattler_cache::default_cache_dir().unwrap().join("repodata"), | ||
FetchRepoDataOptions::default(), | ||
None, | ||
) | ||
.await | ||
.unwrap(); | ||
|
||
eprintln!("parsing repodata.."); | ||
let repodata = rattler_conda_types::RepoData::from_path(repodata.repo_data_json_path) | ||
.unwrap() | ||
.into_repo_data_records(&channel); | ||
|
||
records.push(repodata); | ||
} | ||
|
||
// Create the dependency provider | ||
let provider = rattler_solve::resolvo::CondaDependencyProvider::new( | ||
records | ||
.iter() | ||
.map(rattler_solve::resolvo::RepoData::from_iter), | ||
&[], | ||
&[], | ||
&[], | ||
&[], | ||
None, | ||
ChannelPriority::default(), | ||
None, | ||
SolveStrategy::default(), | ||
) | ||
.unwrap(); | ||
|
||
eprintln!("creating snapshot.."); | ||
let package_names = provider.package_names().collect::<Vec<_>>(); | ||
let snapshot = | ||
resolvo::snapshot::DependencySnapshot::from_provider(provider, package_names, [], []) | ||
.unwrap(); | ||
|
||
let output_file = args.output.unwrap_or_else(|| { | ||
format!( | ||
"snapshot-{}-{}.json", | ||
channel.name(), | ||
subdirs | ||
.iter() | ||
.copied() | ||
.map(Platform::as_str) | ||
.sorted() | ||
.join("-") | ||
) | ||
}); | ||
eprintln!("serializing snapshot to {}", &output_file); | ||
let snapshot_path = Path::new(&output_file); | ||
if let Some(dir) = snapshot_path.parent() { | ||
std::fs::create_dir_all(dir).unwrap(); | ||
} | ||
let snapshot_file = BufWriter::new(std::fs::File::create(snapshot_path).unwrap()); | ||
serde_json::to_writer(snapshot_file, &snapshot).unwrap(); | ||
} |