Skip to content

Commit 259d161

Browse files
committed
Update progress bars on gilda utilities
1 parent 1284994 commit 259d161

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

src/pyobo/gilda_utils.py

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"""PyOBO's Gilda utilities."""
44

55
import logging
6+
from subprocess import CalledProcessError
67
from typing import Iterable, List, Optional, Tuple, Type, Union
78

89
import bioregistry
@@ -96,6 +97,7 @@ def get_grounder(
9697
versions: Union[None, str, Iterable[Union[str, None]]] = None,
9798
strict: bool = True,
9899
skip_obsolete: bool = False,
100+
progress: bool = True,
99101
) -> Grounder:
100102
"""Get a Gilda grounder for the given prefix(es)."""
101103
unnamed = set() if unnamed is None else set(unnamed)
@@ -113,7 +115,7 @@ def get_grounder(
113115
raise ValueError
114116

115117
terms: List[gilda.term.Term] = []
116-
for prefix, version in zip(prefixes, versions):
118+
for prefix, version in zip(tqdm(prefixes, leave=False, disable=not progress), versions):
117119
try:
118120
p_terms = list(
119121
get_gilda_terms(
@@ -122,9 +124,10 @@ def get_grounder(
122124
version=version,
123125
strict=strict,
124126
skip_obsolete=skip_obsolete,
127+
progress=progress,
125128
)
126129
)
127-
except NoBuild:
130+
except (NoBuild, CalledProcessError):
128131
continue
129132
else:
130133
terms.extend(p_terms)
@@ -164,13 +167,20 @@ def get_gilda_terms(
164167
version: Optional[str] = None,
165168
strict: bool = True,
166169
skip_obsolete: bool = False,
170+
progress: bool = True,
167171
) -> Iterable[gilda.term.Term]:
168172
"""Get gilda terms for the given namespace."""
169173
id_to_name = get_id_name_mapping(prefix, version=version, strict=strict)
170174
id_to_species = get_id_species_mapping(prefix, version=version, strict=strict)
171175
obsoletes = get_obsolete(prefix, version=version, strict=strict) if skip_obsolete else set()
172176

173-
it = tqdm(id_to_name.items(), desc=f"[{prefix}] mapping", unit_scale=True, unit="name")
177+
it = tqdm(
178+
id_to_name.items(),
179+
desc=f"[{prefix}] mapping",
180+
unit_scale=True,
181+
unit="name",
182+
disable=not progress,
183+
)
174184
for identifier, name in it:
175185
if identifier in obsoletes:
176186
continue
@@ -186,7 +196,11 @@ def get_gilda_terms(
186196
id_to_synonyms = get_id_synonyms_mapping(prefix, version=version)
187197
if id_to_synonyms:
188198
it = tqdm(
189-
id_to_synonyms.items(), desc=f"[{prefix}] mapping", unit_scale=True, unit="synonym"
199+
id_to_synonyms.items(),
200+
desc=f"[{prefix}] mapping",
201+
unit_scale=True,
202+
unit="synonym",
203+
disable=not progress,
190204
)
191205
for identifier, synonyms in it:
192206
if identifier in obsoletes:
@@ -205,7 +219,13 @@ def get_gilda_terms(
205219
)
206220

207221
if identifiers_are_names:
208-
it = tqdm(get_ids(prefix), desc=f"[{prefix}] mapping", unit_scale=True, unit="id")
222+
it = tqdm(
223+
get_ids(prefix),
224+
desc=f"[{prefix}] mapping",
225+
unit_scale=True,
226+
unit="id",
227+
disable=not progress,
228+
)
209229
for identifier in it:
210230
if identifier in obsoletes:
211231
continue

0 commit comments

Comments
 (0)