pub fn save<S>(&self, figure_path: &S) -> Result<(), &'static str>
    where
        S: AsRef<OsStr> + ?Sized,
    {
        // update commands
        let fig_path = Path::new(figure_path);
        let commands = format!(
            "{}\nfn='{}'\nplt.savefig(fn, bbox_inches='tight', bbox_extra_artists=EXTRA_ARTISTS)\n",
            self.buffer,
            fig_path.to_string_lossy(),
        );

        // call python
        let mut path = Path::new(figure_path).to_path_buf();
        path.set_extension("py");
        let output = call_python3(&commands, &path)?;

        // handle error => write log file
        if output != "" {
            let mut log_path = Path::new(figure_path).to_path_buf();
            log_path.set_extension("log");
            let mut log_file = File::create(log_path).map_err(|_| "cannot create log file")?;
            log_file
                .write_all(output.as_bytes())
                .map_err(|_| "cannot write to log file")?;

            // TODO: if not CI, do not print the log file by default
            // self.print_log_file(&figure_path)?;

            return Err("python3 failed; please see the log file");
        }
        Ok(())
    }
/// Calls python3 and saves the python script and figure
///
/// # Input
///
/// * `figure_path` -- may be a String, &str, or Path
Calls python3 and saves the python script and figure
Calls python3 and saves the python script and figure
pub fn save<S>(&self, figure_path: &S) -> Result<(), &'static str>
    where
        S: AsRef<OsStr> + ?Sized,
    {
        // update commands
        let fig_path = Path::new(figure_path);
        let commands = format!(
            "{}\nfn='{}'\nplt.savefig(fn, bbox_inches='tight', bbox_extra_artists=EXTRA_ARTISTS)\n",
            self.buffer,
            fig_path.to_string_lossy(),
        );
        // call python
        let mut path = Path::new(figure_path).to_path_buf();
        path.set_extension("py");
        let output = call_python3(&commands, &path)?;
        // handle error => write log file
        if output != "" {
            let mut log_path = Path::new(figure_path).to_path_buf();
            log_path.set_extension("log");
            let mut log_file = File::create(log_path).map_err(|_| "cannot create log file")?;
            log_file
                .write_all(output.as_bytes())
                .map_err(|_| "cannot write to log file")?;
            // TODO: if not CI, do not print the log file by default
            // self.print_log_file(&figure_path)?;
            return Err("python3 failed; please see the log file");
        }
        Ok(())
    }
pub fn save < S > ( & self , figure_path : & S ) -> Result < ( ) , & ' static str > where S : AsRef < OsStr > + ? Sized , { // update commands let fig_path = Path :: new ( figure_path ) ; let commands = format ! ( " \n \n \n " self buffer fig_path to_string_lossy ( ) ) ; // call python let mut path = Path :: new ( figure_path ) . to_path_buf ( ) ; path . set_extension ( " " ) ; let output = call_python3 ( & commands , & path ) ? ; // handle error => write log file if output != " " { let mut log_path = Path :: new ( figure_path ) . to_path_buf ( ) ; log_path . set_extension ( " " ) ; let mut log_file = File :: create ( log_path ) . map_err ( | _ | " " ) ? ; log_file . write_all ( output . as_bytes ( ) ) . map_err ( | _ | " " ) ? ; // TODO: if not CI, do not print the log file by default // self.print_log_file(&figure_path)?; return Err ( " " ) ; } Ok ( ( ) ) }
Calls python3 and saves the python script and figure
Calls python3 and saves the python script and figure
&self
figure_path
&S
&self
figure_path
&S
input
`figure_path` -- may be a String, &str, or Path
` figure_path ` -- may be a String &str or Path