Skip to content

Commit

Permalink
feat: uploading to prefix.dev and add progress bars to other uploader (
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfv authored Dec 21, 2023
1 parent 4d2005d commit b6313f8
Show file tree
Hide file tree
Showing 5 changed files with 250 additions and 73 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ dunce = "1.0.4"
fs-err = "2.11.0"
which = "5.0.0"
clap_complete = "4.4.4"
tokio-util = "0.7.10"

tar = "0.4.40"
zip = { version = "0.6.6", default-features = false, features = [
Expand Down
56 changes: 48 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ struct RebuildOpts {
#[derive(Parser)]
struct UploadOpts {
/// The package file to upload
package_file: PathBuf,
#[arg(global = true, required = false)]
package_files: Vec<PathBuf>,

/// The server type
#[clap(subcommand)]
Expand All @@ -189,6 +190,7 @@ struct UploadOpts {
enum ServerType {
Quetz(QuetzOpts),
Artifactory(ArtifactoryOpts),
Prefix(PrefixOpts),
}

#[derive(Clone, Debug, PartialEq, Parser)]
Expand Down Expand Up @@ -229,6 +231,28 @@ struct ArtifactoryOpts {
password: Option<String>,
}

/// Options for uploading to a Quetz server
/// Authentication is used from the keychain / auth-file
#[derive(Clone, Debug, PartialEq, Parser)]
struct PrefixOpts {
/// The URL to the prefix.dev server (only necessary for self-hosted instances)
#[arg(
short,
long,
env = "PREFIX_SERVER_URL",
default_value = "https://prefix.dev"
)]
url: Url,

/// The channel to upload the package to
#[arg(short, long, env = "PREFIX_CHANNEL")]
channel: String,

/// The prefix.dev API key, if none is provided, the token is read from the keychain / auth-file
#[arg(short, long, env = "PREFIX_API_KEY")]
api_key: Option<String>,
}

#[tokio::main]
async fn main() -> miette::Result<()> {
let args = App::parse();
Expand Down Expand Up @@ -580,11 +604,17 @@ async fn rebuild_from_args(args: RebuildOpts) -> miette::Result<()> {
}

async fn upload_from_args(args: UploadOpts) -> miette::Result<()> {
if ArchiveType::try_from(&args.package_file).is_none() {
return Err(miette::miette!(
"The file {} does not appear to be a conda package.",
args.package_file.to_string_lossy()
));
if args.package_files.is_empty() {
return Err(miette::miette!("No package files were provided."));
}

for package_file in &args.package_files {
if ArchiveType::try_from(package_file).is_none() {
return Err(miette::miette!(
"The file {} does not appear to be a conda package.",
package_file.to_string_lossy()
));
}
}

let store = get_auth_store(args.common.auth_file);
Expand All @@ -594,7 +624,7 @@ async fn upload_from_args(args: UploadOpts) -> miette::Result<()> {
upload::upload_package_to_quetz(
&store,
quetz_opts.api_key,
args.package_file,
&args.package_files,
quetz_opts.url,
quetz_opts.channel,
)
Expand All @@ -605,12 +635,22 @@ async fn upload_from_args(args: UploadOpts) -> miette::Result<()> {
&store,
artifactory_opts.username,
artifactory_opts.password,
args.package_file,
&args.package_files,
artifactory_opts.url,
artifactory_opts.channel,
)
.await?;
}
ServerType::Prefix(prefix_opts) => {
upload::upload_package_to_prefix(
&store,
prefix_opts.api_key,
&args.package_files,
prefix_opts.url,
prefix_opts.channel,
)
.await?;
}
}

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion src/render/solver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ pub async fn create_environment(
// Each channel contains multiple subdirectories. Users can specify the subdirectories they want
// to use when specifying their channels. If the user didn't specify the default subdirectories
// we use defaults based on the current platform.
let platforms = vec![Platform::NoArch, *target_platform];
let platforms = [Platform::NoArch, *target_platform];
let channel_urls = channels
.iter()
.flat_map(|channel| {
Expand Down
Loading

0 comments on commit b6313f8

Please sign in to comment.