File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -217,12 +217,30 @@ def group_successive(numbers_list: list[int]) -> list[list[int]]:
217217 return groups
218218
219219
220- def shorten_path (p : str ) -> str :
221- """Shorten a file path for display if it's too long."""
222- path = Path (p )
223- if len (path .parts ) > 3 :
224- return str (Path ("..." ) / path .parts [- 2 ] / path .parts [- 1 ])
225- return p
220+ def shorten_path (path : str , max_len : int = 20 ) -> str :
221+ """Shorten a file path for display if it's too long.
222+
223+ Args:
224+ path: The file path to shorten.
225+ max_len: The maximum length allowed for the path string.
226+
227+ Returns:
228+ The shortened path string, potentially prefixed with an ellipsis.
229+
230+ """
231+ original_path = Path (path )
232+ shortened_path = Path (original_path .parts [- 1 ])
233+
234+ for i in range (- 2 , - len (original_path .parts ) - 1 , - 1 ):
235+ if len (str (Path (original_path .parts [i ], shortened_path ))) < max_len :
236+ shortened_path = Path (original_path .parts [i ], shortened_path )
237+ else :
238+ break
239+
240+ if shortened_path != shortened_path .absolute ():
241+ shortened_path = Path ("..." , shortened_path )
242+
243+ return str (shortened_path )
226244
227245
228246CPU_COUNT = os .cpu_count ()
You can’t perform that action at this time.
0 commit comments