Skip to content
Snippets Groups Projects
Commit 68fcd64c authored by Dominik Seeger's avatar Dominik Seeger :ghost:
Browse files

fixed issues regarding ipython notebooks

Hektor will no longer attempt to parse empty files as ipython notebooks.
Long outputs will be truncated to 50 lines at most.
parent 6599d2e0
No related branches found
No related tags found
No related merge requests found
/target
**/*.rs.bk
*.json
.idea
......@@ -158,6 +158,8 @@ pub struct CodeCell {
pub execution_count: Option<i64>,
}
const MAX_OUTPUT_LINES: usize = 50;
impl Display for CodeCell {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
let exec_count_as_str = self
......@@ -168,8 +170,33 @@ impl Display for CodeCell {
writeln!(f, "{}\n", self.source)?;
writeln!(f, "# Out[{}]:\n", exec_count_as_str)?;
let mut has_stream_output = false;
for output in &self.outputs {
writeln!(f, "{}", comment_out(output.to_string()))?;
let mut out_str = output.to_string();
// IPython batches stream outputs if they are too long
// we only want to show the first batch of stream outputs.
// Also, we want to truncate too long output streams.
if let Output::Stream(stream) = output {
if has_stream_output {
continue;
}
has_stream_output = true;
out_str = stream
.to_string()
.lines()
.take(MAX_OUTPUT_LINES)
.collect::<Vec<_>>()
.join("\n");
if out_str.lines().count() == MAX_OUTPUT_LINES {
out_str.push_str("\nOUTPUT HAS BEEN TRUNCATED. SEE ORIGINAL NOTEBOOK FOR FULL OUTPUT.");
}
}
writeln!(f, "{}", comment_out(out_str))?;
}
Ok(())
}
......
......@@ -49,7 +49,7 @@ pub fn transform_submissions(
tests: vec![],
};
if sub_type.programming_language == ProgrammingLang::Python {
if sub_type.programming_language == ProgrammingLang::Python && submission.code.len() > 0 {
render_code::<Notebook>(&mut submission)?;
}
Ok(submission)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment