mirror of
https://github.com/erg-lang/erg.git
synced 2025-09-30 12:51:10 +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()
|
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)]
|
#[derive(Debug, Clone)]
|
||||||
|
|
|
@ -1293,22 +1293,24 @@ impl Context {
|
||||||
Ok(path)
|
Ok(path)
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
// pylyzer is a static analysis tool for Python.
|
if let Ok(path) = self.cfg.input.local_py_resolve(Path::new(&__name__[..])) {
|
||||||
// It can convert a Python script to an Erg AST for code analysis.
|
// pylyzer is a static analysis tool for Python.
|
||||||
// There is also an option to output the analysis result as `d.er`. Use this if the system have pylyzer installed.
|
// It can convert a Python script to an Erg AST for code analysis.
|
||||||
match Command::new("pylyzer")
|
// There is also an option to output the analysis result as `d.er`. Use this if the system have pylyzer installed.
|
||||||
.arg("--dump-decl")
|
match Command::new("pylyzer")
|
||||||
.arg(format!("{__name__}.py"))
|
.arg("--dump-decl")
|
||||||
.output()
|
.arg(path.to_str().unwrap())
|
||||||
{
|
.output()
|
||||||
Ok(out) if out.status.success() => {
|
{
|
||||||
if let Some(path) =
|
Ok(out) if out.status.success() => {
|
||||||
Self::resolve_decl_path(&self.cfg, Path::new(&__name__[..]))
|
if let Some(path) =
|
||||||
{
|
Self::resolve_decl_path(&self.cfg, Path::new(&__name__[..]))
|
||||||
return Ok(path);
|
{
|
||||||
|
return Ok(path);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
_ => {}
|
||||||
}
|
}
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
let err = TyCheckError::import_error(
|
let err = TyCheckError::import_error(
|
||||||
self.cfg.input.clone(),
|
self.cfg.input.clone(),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue