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

Merge branch 'fix-python-issues' into 'master'

Fix python issues

Closes #11

See merge request !4
parents 6599d2e0 68fcd64c
Branches
Tags
1 merge request!4Fix python issues
Pipeline #134063 passed with warnings
/target /target
**/*.rs.bk **/*.rs.bk
*.json *.json
.idea
...@@ -158,6 +158,8 @@ pub struct CodeCell { ...@@ -158,6 +158,8 @@ pub struct CodeCell {
pub execution_count: Option<i64>, pub execution_count: Option<i64>,
} }
const MAX_OUTPUT_LINES: usize = 50;
impl Display for CodeCell { impl Display for CodeCell {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
let exec_count_as_str = self let exec_count_as_str = self
...@@ -168,8 +170,33 @@ impl Display for CodeCell { ...@@ -168,8 +170,33 @@ impl Display for CodeCell {
writeln!(f, "{}\n", self.source)?; writeln!(f, "{}\n", self.source)?;
writeln!(f, "# Out[{}]:\n", exec_count_as_str)?; writeln!(f, "# Out[{}]:\n", exec_count_as_str)?;
let mut has_stream_output = false;
for output in &self.outputs { 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(()) Ok(())
} }
......
...@@ -49,7 +49,7 @@ pub fn transform_submissions( ...@@ -49,7 +49,7 @@ pub fn transform_submissions(
tests: vec![], 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)?; render_code::<Notebook>(&mut submission)?;
} }
Ok(submission) Ok(submission)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment