Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve viz --lite logs #2266

Merged
merged 1 commit into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions package/kedro_viz/integrations/kedro/lite_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,17 @@ def parse(self, target_path: Path) -> Union[Dict[str, Set[str]], None]:
unresolved_imports: Dict[str, Set[str]] = {}

if target_path.is_file():
missing_dependencies = self._get_unresolved_imports(target_path)
if len(missing_dependencies) > 0:
unresolved_imports[str(target_path)] = missing_dependencies
try:
missing_dependencies = self._get_unresolved_imports(target_path)
if len(missing_dependencies) > 0:
unresolved_imports[str(target_path)] = missing_dependencies
except Exception as exc: # noqa: BLE001
logger.error(
"An error occurred in LiteParser while mocking dependencies in %s : %s",
target_path,
exc,
)

return unresolved_imports

# handling directories
Expand All @@ -263,7 +271,8 @@ def parse(self, target_path: Path) -> Union[Dict[str, Set[str]], None]:
unresolved_imports[str(file_path)] = missing_dependencies
except Exception as exc: # noqa: BLE001 # pragma: no cover
logger.error(
"An error occurred in LiteParser while mocking dependencies : %s",
"An error occurred in LiteParser while mocking dependencies in %s : %s",
file_path,
exc,
)
continue
Expand Down
19 changes: 19 additions & 0 deletions package/tests/test_integrations/test_lite_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,25 @@ def test_file_parse(self, lite_parser, sample_project_path):

assert unresolved_imports == {str(file_path): {"nonexistentmodule"}}

def test_parse_logs_error_on_exception(self, lite_parser, tmp_path, caplog):
file_path = Path(tmp_path / "mock_spaceflights/data_processing_non_utf.py")
file_path.parent.mkdir(parents=True, exist_ok=True)

# Write non-UTF characters (e.g., using ISO-8859-1 encoding)
non_utf_content = "This is a test with non-UTF characters: é, ñ, ü"

# Write the file in ISO-8859-1 encoding
with open(file_path, "w", encoding="ISO-8859-1") as f:
f.write(non_utf_content)

assert file_path.exists()

lite_parser.parse(file_path)
assert (
f"An error occurred in LiteParser while mocking dependencies in {str(file_path)}"
in caplog.text
)

def test_directory_parse(self, lite_parser, sample_project_path):
unresolved_imports = lite_parser.parse(sample_project_path)
expected_file_path = Path(
Expand Down
Loading