Skip to content
Merged
Show file tree
Hide file tree
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
12 changes: 6 additions & 6 deletions src/cmd/submit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,10 +295,10 @@ impl App {
.clone()
.ok_or_else(|| anyhow!("Submission mode not selected"))?;

// Read file content
// Read file content as bytes (supports both text and archive files)
let mut file = File::open(&filepath)?;
let mut file_content = String::new();
file.read_to_string(&mut file_content)?;
let mut file_content = Vec::new();
file.read_to_end(&mut file_content)?;

self.submission_task = Some(tokio::spawn(async move {
service::submit_solution(
Expand Down Expand Up @@ -734,10 +734,10 @@ pub async fn run_submit_plain(
anyhow!("Submission mode not specified. Use --mode flag (test, benchmark, leaderboard, profile)")
})?;

// Read file content
// Read file content as bytes (supports both text and archive files)
let mut file = File::open(&file_to_submit)?;
let mut file_content = String::new();
file.read_to_string(&mut file_content)?;
let mut file_content = Vec::new();
file.read_to_end(&mut file_content)?;

eprintln!("Submitting to leaderboard: {}", final_leaderboard);
eprintln!("GPU: {}", final_gpu);
Expand Down
6 changes: 3 additions & 3 deletions src/service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ pub async fn delete_user_submission(client: &Client, submission_id: i64) -> Resu
pub async fn submit_solution<P: AsRef<Path>>(
client: &Client,
filepath: P,
file_content: &str,
file_content: &[u8],
leaderboard: &str,
gpu: &str,
submission_mode: &str,
Expand All @@ -465,7 +465,7 @@ pub async fn submit_solution<P: AsRef<Path>>(
.ok_or_else(|| anyhow!("Invalid filepath"))?
.to_string_lossy();

let part = Part::bytes(file_content.as_bytes().to_vec()).file_name(filename.to_string());
let part = Part::bytes(file_content.to_vec()).file_name(filename.to_string());

let form = Form::new().part("file", part);

Expand Down Expand Up @@ -824,7 +824,7 @@ mod tests {
let result = submit_solution(
&client,
"test.py",
"print('hello')",
b"print('hello')",
"test-leaderboard",
"H100",
"test",
Expand Down
21 changes: 21 additions & 0 deletions src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,28 @@ pub struct PopcornDirectives {
pub gpus: Vec<String>,
}

pub fn is_archive_file<P: AsRef<Path>>(filepath: P) -> bool {
let path = filepath.as_ref();
let name = path
.file_name()
.unwrap_or_default()
.to_string_lossy()
.to_lowercase();
name.ends_with(".tar.gz") || name.ends_with(".tgz") || name.ends_with(".zip")
}

pub fn get_popcorn_directives<P: AsRef<Path>>(filepath: P) -> Result<(PopcornDirectives, bool)> {
// Archive files (tarballs, zips) are binary and cannot contain directives
if is_archive_file(&filepath) {
return Ok((
PopcornDirectives {
leaderboard_name: String::new(),
gpus: Vec::new(),
},
false,
));
}

let content = fs::read_to_string(filepath)?;

let mut gpus: Vec<String> = Vec::new();
Expand Down