Skip to content
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
30 changes: 24 additions & 6 deletions codesectools/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,30 @@ def group_successive(numbers_list: list[int]) -> list[list[int]]:
return groups


def shorten_path(p: str) -> str:
"""Shorten a file path for display if it's too long."""
path = Path(p)
if len(path.parts) > 3:
return str(Path("...") / path.parts[-2] / path.parts[-1])
return p
def shorten_path(path: str, max_len: int = 20) -> str:
"""Shorten a file path for display if it's too long.

Args:
path: The file path to shorten.
max_len: The maximum length allowed for the path string.

Returns:
The shortened path string, potentially prefixed with an ellipsis.

"""
original_path = Path(path)
shortened_path = Path(original_path.parts[-1])

for i in range(-2, -len(original_path.parts) - 1, -1):
if len(str(Path(original_path.parts[i], shortened_path))) < max_len:
shortened_path = Path(original_path.parts[i], shortened_path)
else:
break

if shortened_path != shortened_path.absolute():
shortened_path = Path("...", shortened_path)

return str(shortened_path)


CPU_COUNT = os.cpu_count()
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "CodeSecTools"
version = "0.13.1"
version = "0.13.2"
description = "A framework for code security that provides abstractions for static analysis tools and datasets to support their integration, testing, and evaluation."
readme = "README.md"
license = "AGPL-3.0-only"
Expand Down
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.