Skip to content

Commit

Permalink
Update file paths relative to input path (#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
mehrinkiani authored Feb 12, 2024
1 parent 2e15e17 commit 3b59900
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion modelscan/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def scan(
if not pathlibPath.exists():
raise FileNotFoundError(f"Path {path} does not exist")
else:
modelscan.scan(pathlibPath)
modelscan.scan(path)
else:
raise click.UsageError("Command line must include a path")

Expand Down
22 changes: 17 additions & 5 deletions modelscan/modelscan.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ def scan(
self._skipped = []
self._scanned = []
self._input_path = str(path)

self._scan_path(Path(path))
pathlibPath = Path().cwd() if path == "." else Path(path).absolute()
self._scan_path(Path(pathlibPath))
return self._generate_results()

def _scan_path(
Expand Down Expand Up @@ -138,6 +138,10 @@ def _scan_zip(
def _generate_results(self) -> Dict[str, Any]:
report: Dict[str, Any] = {}

absolute_path = Path(self._input_path).resolve()
if Path(self._input_path).is_file():
absolute_path = Path(absolute_path).parent

issues_by_severity = self._issues.group_by_severity()
total_issue_count = len(self._issues.all_issues)

Expand All @@ -151,22 +155,30 @@ def _generate_results(self) -> Dict[str, Any]:
report["summary"]["total_issues_by_severity"][severity.name] = 0

report["summary"]["total_issues"] = total_issue_count
report["summary"]["input_path"] = self._input_path
report["summary"]["input_path"] = str(self._input_path)
report["summary"]["absolute_path"] = str(absolute_path)
report["summary"]["modelscan_version"] = __version__
report["summary"]["timestamp"] = datetime.now().isoformat()
report["summary"]["skipped"] = {"total_skipped": len(self._skipped)}
report["summary"]["skipped"]["skipped_files"] = [
str(file_name) for file_name in self._skipped
str(Path(file_name).relative_to(Path(absolute_path)))
for file_name in self._skipped
]
report["summary"]["scanned"] = {"total_scanned": len(self._scanned)}
report["summary"]["scanned"]["scanned_files"] = [
str(file_name) for file_name in self._scanned
str(Path(file_name).relative_to(Path(absolute_path)))
for file_name in self._scanned
]

report["issues"] = [
issue.details.output_json() for issue in self._issues.all_issues
]

for issue in report["issues"]:
issue["source"] = str(
Path(issue["source"]).relative_to(Path(absolute_path))
)

report["errors"] = [str(error) for index, error in enumerate(self._errors)]

return report
Expand Down

0 comments on commit 3b59900

Please sign in to comment.