Skip to content

Commit

Permalink
Improve debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
cpburnz committed Dec 9, 2023
1 parent 67ddd73 commit f092e32
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
2 changes: 2 additions & 0 deletions pathspec/gitignore.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,11 @@ def _match_file(

if pattern.include and dir_mark:
out_include = pattern.include
out_index = index
out_priority = priority
elif priority >= out_priority:
out_include = pattern.include
out_index = index
out_priority = priority

return out_include, out_index
18 changes: 12 additions & 6 deletions tests/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
This module provides utility functions shared by tests.
"""

import itertools
import os
import os.path
import pathlib
Expand Down Expand Up @@ -32,6 +33,10 @@ def debug_results(spec: PathSpec, results: Iterable[CheckResult[str]]) -> str:
"""
patterns = cast(list[RegexPattern], spec.patterns)

pattern_table = []
for index, pattern in enumerate(patterns, 1):
pattern_table.append((f"{index}:{pattern.pattern}", repr(pattern.regex.pattern)))

result_table = []
for result in results:
if result.index is not None:
Expand All @@ -42,18 +47,19 @@ def debug_results(spec: PathSpec, results: Iterable[CheckResult[str]]) -> str:

result_table.sort(key=lambda r: r[1])

first_max_len = max((len(__row[0]) for __row in result_table), default=0)
first_max_len = max((
len(__row[0]) for __row in itertools.chain(pattern_table, result_table)
), default=0)
first_width = min(first_max_len, 20)

pattern_lines = []
for row in pattern_table:
pattern_lines.append(f" {row[0]:<{first_width}} {row[1]}")

result_lines = []
for row in result_table:
result_lines.append(f" {row[0]:<{first_width}} {row[1]}")

pattern_lines = []
for index, pattern in enumerate(patterns, 1):
first_col = f"{index}:{pattern.pattern}"
pattern_lines.append(f" {first_col:<{first_width}} {pattern.regex.pattern!r}")

return "\n".join([
"\n",
" DEBUG ".center(32, "-"),
Expand Down

0 comments on commit f092e32

Please sign in to comment.