mirror of
https://github.com/erg-lang/erg.git
synced 2025-09-30 04:44:44 +00:00
Fix python resolving
This commit is contained in:
parent
3d69353bf6
commit
481761e50b
2 changed files with 33 additions and 14 deletions
|
@ -167,6 +167,23 @@ impl Input {
|
|||
dir.canonicalize()
|
||||
})
|
||||
}
|
||||
|
||||
pub fn local_py_resolve(&self, path: &Path) -> Result<PathBuf, std::io::Error> {
|
||||
let mut dir = if let Self::File(mut path) = self.clone() {
|
||||
path.pop();
|
||||
path
|
||||
} else {
|
||||
PathBuf::new()
|
||||
};
|
||||
dir.push(path);
|
||||
dir.set_extension("py");
|
||||
dir.canonicalize().or_else(|_| {
|
||||
dir.pop();
|
||||
dir.push(path);
|
||||
dir.push("__init__.py"); // {path}/__init__.er
|
||||
dir.canonicalize()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
|
|
|
@ -1293,12 +1293,13 @@ impl Context {
|
|||
Ok(path)
|
||||
}
|
||||
None => {
|
||||
if let Ok(path) = self.cfg.input.local_py_resolve(Path::new(&__name__[..])) {
|
||||
// pylyzer is a static analysis tool for Python.
|
||||
// It can convert a Python script to an Erg AST for code analysis.
|
||||
// There is also an option to output the analysis result as `d.er`. Use this if the system have pylyzer installed.
|
||||
match Command::new("pylyzer")
|
||||
.arg("--dump-decl")
|
||||
.arg(format!("{__name__}.py"))
|
||||
.arg(path.to_str().unwrap())
|
||||
.output()
|
||||
{
|
||||
Ok(out) if out.status.success() => {
|
||||
|
@ -1310,6 +1311,7 @@ impl Context {
|
|||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
let err = TyCheckError::import_error(
|
||||
self.cfg.input.clone(),
|
||||
line!() as usize,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue