Skip to content

Commit 20d11b4

Browse files
authored
Merge pull request #117 from Pennycook/progress-bars
Add progress bars to finder.find()
2 parents c62fba3 + 7659b1b commit 20d11b4

File tree

4 files changed

+30
-5
lines changed

4 files changed

+30
-5
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ portability and maintainability of an application's source code.
4040
- Python 3
4141
- PyYAML
4242
- SciPy
43+
- tqdm
4344

4445

4546
## Installation

codebasin/__main__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ def main():
321321
codebase,
322322
configuration,
323323
legacy_warnings=False,
324+
show_progress=True,
324325
)
325326

326327
# Generate meta-warnings and statistics.

codebasin/finder.py

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import os
1111
from pathlib import Path
1212

13+
from tqdm import tqdm
14+
1315
from codebasin import file_parser, platform, preprocessor
1416
from codebasin.language import FileLanguage
1517
from codebasin.walkers.tree_associator import TreeAssociator
@@ -78,6 +80,7 @@ def find(
7880
*,
7981
summarize_only=True,
8082
legacy_warnings=True,
83+
show_progress=False,
8184
):
8285
"""
8386
Find codepaths in the files provided and return a mapping of source
@@ -91,8 +94,7 @@ def find(
9194

9295
# Build a tree for each unique file for all platforms.
9396
state = ParserState(summarize_only)
94-
for f in codebase:
95-
state.insert_file(f)
97+
filenames = set(codebase)
9698
for p in configuration:
9799
for e in configuration[p]:
98100
if e["file"] not in codebase:
@@ -102,11 +104,31 @@ def find(
102104
f"{filename} found in definition of platform {p} "
103105
+ "but missing from codebase",
104106
)
105-
state.insert_file(e["file"])
107+
filenames.add(e["file"])
108+
for f in tqdm(
109+
filenames,
110+
desc="Parsing",
111+
unit=" file",
112+
leave=False,
113+
disable=not show_progress,
114+
):
115+
state.insert_file(f)
106116

107117
# Process each tree, by associating nodes with platforms
108-
for p in configuration:
109-
for e in configuration[p]:
118+
for p in tqdm(
119+
configuration,
120+
desc="Preprocessing",
121+
unit=" platform",
122+
leave=False,
123+
disable=not show_progress,
124+
):
125+
for e in tqdm(
126+
configuration[p],
127+
desc=p,
128+
unit=" file",
129+
leave=False,
130+
disable=not show_progress,
131+
):
110132
file_platform = platform.Platform(p, rootdir)
111133

112134
for path in e["include_paths"]:

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ dependencies = [
3131
"pyyaml==6.0.1",
3232
"scipy==1.12.0",
3333
"jsonschema==4.21.1",
34+
"tqdm==4.66.5",
3435
]
3536

3637
[project.scripts]

0 commit comments

Comments
 (0)