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

Update file paths relative to input path #104

Merged
merged 1 commit into from
Feb 12, 2024
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
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
Loading