use std::fs;
use std::path::Path;
const STUB: &str = "nkscan.pyi";
fn main() -> Result<(), Box<dyn std::error::Error>> {
nkscan::python_stub_info()?.generate()?;
unqualify_local_classes(Path::new(STUB))?;
println!("wrote {STUB}");
Ok(())
}
fn unqualify_local_classes(path: &Path) -> std::io::Result<()> {
let stub = fs::read_to_string(path)?;
let declared: Vec<String> = stub
.lines()
.filter_map(|line| line.strip_prefix("class "))
.filter_map(|rest| rest.split(['(', ':']).next())
.map(str::to_owned)
.collect();
let fixed = declared.iter().fold(stub.clone(), |stub, name| {
stub.replace(&format!("builtins.{name}"), name)
});
if fixed != stub {
fs::write(path, fixed)?;
}
Ok(())
}