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: uploading to prefix.dev #432

Merged
merged 6 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
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 @@ -85,6 +85,7 @@ dunce = "1.0.4"
fs-err = "2.11.0"
which = "5.0.0"
clap_complete = "4.4.4"
tokio-util = "0.7.10"

[dev-dependencies]
insta = { version = "1.34.0", features = ["yaml"] }
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 @@
#[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 @@
enum ServerType {
Quetz(QuetzOpts),
Artifactory(ArtifactoryOpts),
Prefix(PrefixOpts),
}

#[derive(Clone, Debug, PartialEq, Parser)]
Expand Down Expand Up @@ -229,6 +231,28 @@
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 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() {

Check failure on line 612 in src/main.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

[clippy] reported by reviewdog 🐶 error: the borrowed expression implements the required traits --> src/main.rs:612:34 | 612 | if ArchiveType::try_from(&package_file).is_none() { | ^^^^^^^^^^^^^ help: change this to: `package_file` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow Raw Output: src/main.rs:612:34:e:error: the borrowed expression implements the required traits --> src/main.rs:612:34 | 612 | if ArchiveType::try_from(&package_file).is_none() { | ^^^^^^^^^^^^^ help: change this to: `package_file` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow __END__

Check failure on line 612 in src/main.rs

View workflow job for this annotation

GitHub Actions / test (macos-latest)

[clippy] reported by reviewdog 🐶 error: the borrowed expression implements the required traits --> src/main.rs:612:34 | 612 | if ArchiveType::try_from(&package_file).is_none() { | ^^^^^^^^^^^^^ help: change this to: `package_file` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow Raw Output: src/main.rs:612:34:e:error: the borrowed expression implements the required traits --> src/main.rs:612:34 | 612 | if ArchiveType::try_from(&package_file).is_none() { | ^^^^^^^^^^^^^ help: change this to: `package_file` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow __END__
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 @@
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 @@
&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
Loading