Skip to content

Commit c05ea22

Browse files
Merge pull request #123 from source-foundry/progress-indicators
Add indeterminate progress indicator during processing
2 parents 8db9d3e + 8d00659 commit c05ea22

File tree

5 files changed

+99
-67
lines changed

5 files changed

+99
-67
lines changed

lib/fdiff/__main__.py

Lines changed: 57 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import sys
66
from typing import Iterable, Iterator, List, Optional, Text, Tuple
77

8+
from rich.console import Console # type: ignore
9+
810
from . import __version__
911
from .color import color_unified_diff_line
1012
from .diff import external_diff, u_diff
@@ -105,6 +107,9 @@ def run(argv: List[Text]) -> None:
105107
#
106108
# /////////////////////////////////////////////////////////
107109

110+
# instantiate a rich Console
111+
console = Console()
112+
108113
# parse explicitly included or excluded tables in
109114
# the command line arguments
110115
# set as a Python list if it was defined on the command line
@@ -137,24 +142,25 @@ def run(argv: List[Text]) -> None:
137142
sys.exit(1)
138143

139144
try:
140-
ext_diff: Iterable[Tuple[Text, Optional[int]]] = external_diff(
141-
args.external,
142-
args.PREFILE,
143-
args.POSTFILE,
144-
include_tables=include_list,
145-
exclude_tables=exclude_list,
146-
use_multiprocess=use_mp,
147-
)
148-
149-
# write stdout from external tool
150-
for line, exit_code in ext_diff:
151-
# format with color if color flag is entered on command line
152-
if args.color:
153-
sys.stdout.write(color_unified_diff_line(line))
154-
else:
155-
sys.stdout.write(line)
156-
if exit_code is not None:
157-
sys.exit(exit_code)
145+
with console.status("Processing...", spinner="dots10"):
146+
ext_diff: Iterable[Tuple[Text, Optional[int]]] = external_diff(
147+
args.external,
148+
args.PREFILE,
149+
args.POSTFILE,
150+
include_tables=include_list,
151+
exclude_tables=exclude_list,
152+
use_multiprocess=use_mp,
153+
)
154+
155+
# write stdout from external tool
156+
for line, exit_code in ext_diff:
157+
# format with color if color flag is entered on command line
158+
if args.color:
159+
sys.stdout.write(color_unified_diff_line(line))
160+
else:
161+
sys.stdout.write(line)
162+
if exit_code is not None:
163+
sys.exit(exit_code)
158164
except Exception as e:
159165
sys.stderr.write(f"[*] ERROR: {e}{os.linesep}")
160166
sys.exit(1)
@@ -163,38 +169,39 @@ def run(argv: List[Text]) -> None:
163169
# Unified diff
164170
# ---------------
165171
# perform the unified diff analysis
166-
try:
167-
uni_diff: Iterator[Text] = u_diff(
168-
args.PREFILE,
169-
args.POSTFILE,
170-
context_lines=args.lines,
171-
include_tables=include_list,
172-
exclude_tables=exclude_list,
173-
use_multiprocess=use_mp,
174-
)
175-
except Exception as e:
176-
sys.stderr.write(f"[*] ERROR: {e}{os.linesep}")
177-
sys.exit(1)
178-
179-
# re-define the line contents of the diff iterable
180-
# if head or tail is requested
181-
if args.head:
182-
iterable = head(uni_diff, args.head)
183-
elif args.tail:
184-
iterable = tail(uni_diff, args.tail)
185-
else:
186-
iterable = uni_diff
187-
188-
# print unified diff results to standard output stream
189-
has_diff = False
190-
if args.color:
191-
for line in iterable:
192-
has_diff = True
193-
sys.stdout.write(color_unified_diff_line(line))
194-
else:
195-
for line in iterable:
196-
has_diff = True
197-
sys.stdout.write(line)
172+
with console.status("Processing...", spinner="dots10"):
173+
try:
174+
uni_diff: Iterator[Text] = u_diff(
175+
args.PREFILE,
176+
args.POSTFILE,
177+
context_lines=args.lines,
178+
include_tables=include_list,
179+
exclude_tables=exclude_list,
180+
use_multiprocess=use_mp,
181+
)
182+
except Exception as e:
183+
sys.stderr.write(f"[*] ERROR: {e}{os.linesep}")
184+
sys.exit(1)
185+
186+
# re-define the line contents of the diff iterable
187+
# if head or tail is requested
188+
if args.head:
189+
iterable = head(uni_diff, args.head)
190+
elif args.tail:
191+
iterable = tail(uni_diff, args.tail)
192+
else:
193+
iterable = uni_diff
194+
195+
# print unified diff results to standard output stream
196+
has_diff = False
197+
if args.color:
198+
for line in iterable:
199+
has_diff = True
200+
sys.stdout.write(color_unified_diff_line(line))
201+
else:
202+
for line in iterable:
203+
has_diff = True
204+
sys.stdout.write(line)
198205

199206
# if no difference was found, tell the user instead of
200207
# simply closing with zero exit status code.

lib/fdiff/diff.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
from fontTools.ttLib import TTFont # type: ignore
1313

1414
from .exceptions import AIOError
15-
from .remote import (_get_filepath_from_url,
16-
create_async_get_request_session_and_run)
15+
from .remote import _get_filepath_from_url, create_async_get_request_session_and_run
1716
from .utils import get_file_modtime
1817

1918
#

lib/fdiff/remote.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import asyncio
44
import os.path
55
import urllib.parse
6+
67
# from collections import namedtuple
78
from typing import Any, AnyStr, List, NamedTuple, Optional, Text, Tuple
89

requirements.txt

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,41 @@
44
#
55
# pip-compile
66
#
7-
aiodns==2.0.0 # via fdiff (setup.py)
8-
aiofiles==0.6.0 # via fdiff (setup.py)
9-
aiohttp==3.7.4.post0 # via fdiff (setup.py)
10-
async-timeout==3.0.1 # via aiohttp
11-
attrs==21.2.0 # via aiohttp
12-
cffi==1.14.5 # via pycares
13-
chardet==3.0.4 # via aiohttp
14-
fonttools==4.23.1 # via fdiff (setup.py)
15-
idna==3.1 # via yarl
16-
multidict==5.1.0 # via aiohttp, yarl
17-
pycares==4.0.0 # via aiodns
18-
pycparser==2.20 # via cffi
19-
typing-extensions==3.10.0.0 # via aiohttp
20-
yarl==1.6.3 # via aiohttp
7+
aiodns==3.0.0
8+
# via fdiff (setup.py)
9+
aiofiles==0.6.0
10+
# via fdiff (setup.py)
11+
aiohttp==3.7.4.post0
12+
# via fdiff (setup.py)
13+
async-timeout==3.0.1
14+
# via aiohttp
15+
attrs==21.2.0
16+
# via aiohttp
17+
cffi==1.14.5
18+
# via pycares
19+
chardet==4.0.0
20+
# via aiohttp
21+
colorama==0.4.4
22+
# via rich
23+
commonmark==0.9.1
24+
# via rich
25+
fonttools==4.23.1
26+
# via fdiff (setup.py)
27+
idna==3.1
28+
# via yarl
29+
multidict==5.1.0
30+
# via
31+
# aiohttp
32+
# yarl
33+
pycares==4.0.0
34+
# via aiodns
35+
pycparser==2.20
36+
# via cffi
37+
pygments==2.9.0
38+
# via rich
39+
rich==10.2.0
40+
# via fdiff (setup.py)
41+
typing-extensions==3.10.0.0
42+
# via aiohttp
43+
yarl==1.6.3
44+
# via aiohttp

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
"fontTools >= 4.0.0",
1717
"aiohttp >= 3.6.0",
1818
"aiodns >= 2.0.0",
19-
"aiofiles >= 0.4.0"
19+
"aiofiles >= 0.4.0",
20+
"rich",
2021
]
2122
# Optional packages
2223
EXTRAS_REQUIRES = {

0 commit comments

Comments
 (0)