From 6ce4a6c1bfb680ec4d4a5297b643c6d4856398c6 Mon Sep 17 00:00:00 2001 From: William Armiros Date: Mon, 4 Mar 2024 15:20:31 -0800 Subject: [PATCH 1/2] fix symlink issue in path resolution --- .pre-commit-config.yaml | 2 ++ modelscan/modelscan.py | 23 +++++++++++++++++------ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f883a47..3d4ec75 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,3 +1,5 @@ +default_language_version: + python: python3.11 repos: - repo: https://github.com/psf/black rev: 22.8.0 diff --git a/modelscan/modelscan.py b/modelscan/modelscan.py index e177578..8f91b4a 100644 --- a/modelscan/modelscan.py +++ b/modelscan/modelscan.py @@ -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"] = [ @@ -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) @@ -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) From 08f666fdcdaac8a1d7af755d5145913ddf94b9b3 Mon Sep 17 00:00:00 2001 From: William Armiros Date: Mon, 4 Mar 2024 15:24:14 -0800 Subject: [PATCH 2/2] one more --- modelscan/modelscan.py | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/modelscan/modelscan.py b/modelscan/modelscan.py index 8f91b4a..7627fac 100644 --- a/modelscan/modelscan.py +++ b/modelscan/modelscan.py @@ -221,15 +221,10 @@ def _generate_results(self) -> Dict[str, Any]: if 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 + for file_name in self._scanned: + resolved_file = Path(file_name).resolve() + scanned_files.append( + str(resolved_file.relative_to(Path(absolute_path))) ) report["summary"]["scanned"]["scanned_files"] = scanned_files @@ -240,9 +235,8 @@ def _generate_results(self) -> Dict[str, Any]: ] for issue in report["issues"]: - issue["source"] = str( - Path(issue["source"]).relative_to(Path(absolute_path)) - ) + resolved_file = Path(issue["source"]).resolve() + issue["source"] = str(resolved_file.relative_to(Path(absolute_path))) else: report["issues"] = []