#![doc = include_str!("readme.md")]
pub mod marshal;
pub mod reader;
pub mod writer;
use crate::program::PythonVersion;
use gaia_types::{GaiaDiagnostics, GaiaError};
use std::{fs::File, io::BufReader, path::Path};
#[derive(Debug, Clone, Copy)]
pub struct PycReadConfig {
pub version: PythonVersion,
}
impl Default for PycReadConfig {
fn default() -> Self {
Self { version: PythonVersion::Unknown }
}
}
#[derive(Debug, Clone, Copy)]
pub struct PycWriteConfig {
pub version: PythonVersion,
}
impl Default for PycWriteConfig {
fn default() -> Self {
Self { version: PythonVersion::Python3_9 }
}
}
pub fn pyc_read_path<P: AsRef<Path>>(path: P, config: &PycReadConfig) -> GaiaDiagnostics<crate::program::PythonProgram> {
let file = match File::open(path) {
Ok(f) => f,
Err(e) => return GaiaDiagnostics { result: Err(GaiaError::from(e)), diagnostics: Vec::new() },
};
let buf_reader = BufReader::new(file);
let reader = config.as_reader(buf_reader);
reader.finish()
}