Skip to content

Commit

Permalink
fix symlink issue in path resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
willarmiros committed Mar 4, 2024
1 parent 8172cb8 commit 6ce4a6c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
default_language_version:
python: python3.11
repos:
- repo: https://github.com/psf/black
rev: 22.8.0
Expand Down
23 changes: 17 additions & 6 deletions modelscan/modelscan.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,19 @@ def _generate_results(self) -> Dict[str, Any]:
report["summary"]["scanned"] = {"total_scanned": len(self._scanned)}

if self._scanned:
report["summary"]["scanned"]["scanned_files"] = [
str(Path(file_name).relative_to(Path(absolute_path)))
for file_name in self._scanned
]
scanned_files = []
try:
for file_name in self._scanned:
resolved_file = Path(file_name).resolve()
scanned_files.append(
str(resolved_file.relative_to(Path(absolute_path)))
)
except Exception:
logger.warning(
f"Could not record scanned file {file_name}", exc_info=True
)

report["summary"]["scanned"]["scanned_files"] = scanned_files

if self._issues.all_issues:
report["issues"] = [
Expand All @@ -245,8 +254,9 @@ def _generate_results(self) -> Dict[str, Any]:
if error.message:
error_information["description"] = error.message
if error.source is not None:
resolved_file = Path(error.source).resolve()
error_information["source"] = str(
Path(str(error.source)).relative_to(Path(absolute_path))
resolved_file.relative_to(Path(absolute_path))
)

all_errors.append(error_information)
Expand All @@ -261,8 +271,9 @@ def _generate_results(self) -> Dict[str, Any]:
skipped_file_information = {}
skipped_file_information["category"] = str(skipped_file.category.name)
skipped_file_information["description"] = str(skipped_file.message)
resolved_file = Path(skipped_file.source).resolve()
skipped_file_information["source"] = str(
Path(skipped_file.source).relative_to(Path(absolute_path))
resolved_file.relative_to(Path(absolute_path))
)
all_skipped_files.append(skipped_file_information)

Expand Down

0 comments on commit 6ce4a6c

Please sign in to comment.