Skip to content

Commit

Permalink
Add better logging for import resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
Glyphack committed Sep 28, 2023
1 parent 9e35d4b commit 4910541
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
3 changes: 1 addition & 2 deletions enderpy/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ mod cli;

fn main() -> Result<()> {
let cli = Cli::parse();

match &cli.command {
Commands::Tokenize { file } => tokenize(file),
Commands::Parse { file } => parse(file),
Expand Down Expand Up @@ -80,7 +79,7 @@ fn parse(file: &PathBuf) -> Result<()> {

fn check(path: &PathBuf) -> Result<()> {
if path.is_dir() {
return bail!("Path must be a file");
bail!("Path must be a file");
}
let source = fs::read_to_string(path)?;
let initial_source = BuildSource {
Expand Down
18 changes: 15 additions & 3 deletions typechecker/src/build.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::{collections::HashMap, path::PathBuf};
use env_logger::Builder;
use log::info;

use enderpy_python_parser::Parser;
Expand Down Expand Up @@ -52,6 +53,12 @@ impl BuildManager {

modules.insert(mod_name, State::new(file));
}

if options.debug {
let mut builder = Builder::new();
builder.filter(None, log::LevelFilter::Debug);
builder.init();
}

BuildManager {
errors: vec![],
Expand Down Expand Up @@ -97,11 +104,13 @@ impl BuildManager {
// Entry point to analyze the program
pub fn build(&mut self) {
let files = self.modules.values().collect();
info!("files: {:#?}", files);
let new_files = self.gather_files(files);
for file in new_files {
self.modules.insert(file.file.module_name.clone(), file);
}
for module in self.modules.values() {
info!("file: {:#?}", module.file.module_name);
}

self.pre_analysis();
}
Expand Down Expand Up @@ -181,6 +190,8 @@ impl BuildManager {
// Adding a blank path to the extra paths is a hack to make the resolver work
extra_paths: vec![PathBuf::from("")],
};
log::debug!("import options: {:?}", execution_environment);

let import_config = &Config {
typeshed_path: None,
stub_path: None,
Expand Down Expand Up @@ -221,8 +232,9 @@ impl BuildManager {
host,
);
if !resolved.is_import_found {
let error = format!("cannot import name '{:#?}'", import_desc.name_parts,);
println!("import error: {:#?}", error);
let error = format!("cannot import name '{}'", import_desc.name());
log::warn!("{}", error);

}
if resolved.is_import_found {
for resolved_path in resolved.resolved_paths.iter() {
Expand Down
2 changes: 1 addition & 1 deletion typechecker/src/project.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::path::{Path, PathBuf};
const PROJECT_ROOT_MARKERS: [&str; 2] = ["__init__.py", "pyproject.toml"];
const PROJECT_ROOT_MARKERS: [&str; 1] = ["pyproject.toml"];

pub fn find_project_root(path: &PathBuf) -> &Path {
let root = path
Expand Down
1 change: 0 additions & 1 deletion typechecker/src/semantic_analyzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,6 @@ impl TraversalVisitor for SemanticAnalyzer {
}

fn visit_import(&mut self, _i: &parser::ast::Import) {
println!("import {:?}", _i);
for alias in &_i.names {
self.create_import_alias_symbol(alias, DeclarationPath {
module_name: self.file.module_name.clone(),
Expand Down

0 comments on commit 4910541

Please sign in to comment.