Skip to content

Commit

Permalink
Merge branch 'master' of github.com:michaelb/sniprun
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelb committed Nov 16, 2021
2 parents ae0c5cf + 57ddc9d commit ee257b7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## v1.0.4
- fix python3 fifo and sage interpreters empty line in indented bloc bug

## v1.0.3
- configurable filetypes

Expand Down
17 changes: 11 additions & 6 deletions src/interpreters/Python3_fifo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,8 @@ impl Python3_fifo {
if !err_to_display.trim().is_empty() {
info!("err found");
if err_to_display.lines().count() > 2 {
let mut err_to_display_vec = err_to_display
.lines()
.skip(2)
.collect::<Vec<&str>>();
let mut err_to_display_vec =
err_to_display.lines().skip(2).collect::<Vec<&str>>();
err_to_display_vec.dedup();
err_to_display = err_to_display_vec.join("\n");
}
Expand Down Expand Up @@ -170,7 +168,9 @@ impl Python3_fifo {

fn fetch_config(&mut self) {
let default_interpreter = String::from("python3");
if let Some(used_interpreter) = Python3_fifo::get_interpreter_option(&self.get_data(), "interpreter") {
if let Some(used_interpreter) =
Python3_fifo::get_interpreter_option(&self.get_data(), "interpreter")
{
if let Some(interpreter_string) = used_interpreter.as_str() {
info!("Using custom interpreter: {}", interpreter_string);
self.interpreter = interpreter_string.to_string();
Expand All @@ -179,7 +179,9 @@ impl Python3_fifo {
self.interpreter = default_interpreter;

if let Ok(path) = env::current_dir() {
if let Some(venv_array_config) = Python3_fifo::get_interpreter_option(&self.get_data(), "venv") {
if let Some(venv_array_config) =
Python3_fifo::get_interpreter_option(&self.get_data(), "venv")
{
if let Some(actual_vec_of_venv) = venv_array_config.as_array() {
for possible_venv in actual_vec_of_venv.iter() {
if let Some(possible_venv_str) = possible_venv.as_str() {
Expand Down Expand Up @@ -383,6 +385,9 @@ impl ReplLikeInterpreter for Python3_fifo {
+ &self.current_output_id.to_string()
+ "\", file=sys.stderr)\n";

// remove empty lines interpreted as 'enter' by python
self.code = self.code.lines().filter(|l| !l.trim().is_empty()).collect::<Vec<&str>>().join("\n");

let all_code = self.imports.clone() + "\n" + &self.code + "\n\n";
self.code = String::from("\nimport sys\n\n")
+ &start_mark
Expand Down
3 changes: 3 additions & 0 deletions src/interpreters/Sage_fifo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,9 @@ impl ReplLikeInterpreter for Sage_fifo {
+ &self.current_output_id.to_string()
+ "\", file=sys.stderr)\n";

// remove empty lines interpreted as 'enter' by the sage interpreter
self.code = self.code.lines().filter(|l| !l.trim().is_empty()).collect::<Vec<&str>>().join("\n");

let all_code = self.imports.clone() + "\n" + &self.code;
self.code = String::from("\nimport sys\n\n") + &start_mark + &start_mark_err + &all_code + &end_mark + &end_mark_err;
Ok(())
Expand Down

0 comments on commit ee257b7

Please sign in to comment.