Skip to content

Commit

Permalink
TODOs app: adds the ability to exclude directories and patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
jontsai committed Sep 18, 2024
1 parent ff29e4b commit cc352cf
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
2 changes: 2 additions & 0 deletions admintools/dataclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class TodosConfig:

name: str
directory: str
exclude_dirs: T.Optional[list[str]] = None
exclude_patterns: T.Optional[list[str]] = None

@property
def key(self):
Expand Down
30 changes: 18 additions & 12 deletions admintools/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,18 +113,24 @@ def todos_view(
data = wrap_data(request)

def _build_todos_section(todos_config):
result = subprocess.run(
[
'grep',
'-n', # display line numbers
'-R', # recursive
'-C 5', # show context, 5 lines before/after
f'--group-separator={"~" * 10}', # a unique string that won't occur in code
'TODO',
todos_config.directory,
],
capture_output=True,
)
commands = [
'grep',
'-n', # display line numbers
'-R', # recursive
'-C 5', # show context, 5 lines before/after
f'--group-separator={"~" * 10}', # a unique string that won't occur in code
'TODO',
]
if todos_config.exclude_dirs:
for exclude_dir in todos_config.exclude_dirs:
commands.append(f'--exclude-dir={exclude_dir}')
if todos_config.exclude_patterns:
for exclude_pattern in todos_config.exclude_patterns:
commands.append(f'--exclude={exclude_pattern}')

commands.append(todos_config.directory)

result = subprocess.run(commands, capture_output=True)
todos_groups = (
result.stdout.decode()
.replace(todos_config.exclusion_pattern, '')
Expand Down

0 comments on commit cc352cf

Please sign in to comment.