fix: retry path resolution if failed

This commit is contained in:
Shunsuke Shibayama 2023-05-25 11:58:09 +09:00
parent a9025507d3
commit dab9def08a
2 changed files with 51 additions and 7 deletions

View file

@ -2,6 +2,7 @@
//!
//! コマンドオプション(パーサー)を定義する
use std::env;
use std::ffi::OsStr;
use std::fmt;
use std::fs::File;
use std::io::{stdin, BufRead, BufReader, Read, Write};
@ -319,6 +320,26 @@ impl Input {
}
}
pub fn module_name(&self) -> String {
match &self.kind {
InputKind::File(filename) => {
let file_stem = if filename.file_stem() == Some(OsStr::new("__init__")) {
filename.parent().and_then(|p| p.file_stem())
} else {
filename.file_stem()
};
file_stem
.and_then(|f| f.to_str())
.unwrap_or("_")
.to_string()
}
InputKind::REPL | InputKind::Pipe(_) => "<stdin>".to_string(),
InputKind::DummyREPL(stdin) => stdin.name.clone(),
InputKind::Str(_) => "<string>".to_string(),
InputKind::Dummy => "<dummy>".to_string(),
}
}
pub fn read(&mut self) -> String {
match &mut self.kind {
InputKind::File(filename) => {