Skip to content

Commit

Permalink
minor progress_bar changes
Browse files Browse the repository at this point in the history
  • Loading branch information
dmichaels-harvard committed Apr 19, 2024
1 parent 069c68d commit aeaaccb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
16 changes: 9 additions & 7 deletions dcicutils/progress_bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ def reset(self, total: int, progress: int = 0, description: Optional[str] = None
self.set_total(total, _norefresh=True)
self.set_progress(progress, _norefresh=True)
self.set_description(description)
self.enable()
self._done = False
self._bar.reset()
self._started = time.time()

def done(self, description: Optional[str] = None) -> None:
Expand Down Expand Up @@ -311,12 +314,15 @@ def remove_extra_trailing_spaces(text: str) -> str: # noqa
if self._captured_output_for_testing is not None:
# For testing only we replace vacilliting values in the out like rate,
# time elapsed, and ETA with static values; so that something like this:
# > Working / 20% ◀|█████████▌ | 1/5 | 536.00/s | 00:01 | ETA: 00:02
# > Working 20% ◀|█████████▌ | 1/5 | 536.00/s | 00:01 | ETA: 00:02
# becomes something more static like this after calling this function:
# > Working | 20% ◀|### | 1/5 | 0.0/s | 00:00 | ETA: 00:00
# This function obviously has intimate knowledge of the output; better here than in tests.
def replace_time_dependent_values_with_static(text: str) -> str:
blocks = "\u2587|\u2588|\u2589|\u258a|\u258b|\u258c|\u258d|\u258e|\u258f"
if text.endswith("| "):
# In case "|" is in the trailing spinner it messes up regex below.
text = set_nth(text, len(text) - 2, "-")
if (n := find_nth_from_end(text, "|", 5)) >= 8:
pattern = re.compile(
rf"(\s*)(\d*%? ◀\|)(?:\s*{blocks}|#)*\s*(\|\s*\d+/\d+)?(\s*\|\s*)"
Expand All @@ -337,12 +343,8 @@ def restore_stdout_write() -> None: # noqa
sys.stdout.write = sys_stdout_write
def ascii_spinners() -> list: # noqa
# Fun with ASCII spinners.
return list("⣾⣽⣻⢿⡿⣟⣯⣷") # borrowed from rich python package
# return list("⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏") # borrowed from rich python package
# return list("⠿⠻⠽⠾⠷⠯⠟")
# return list("⠏⠛⠹⠼⠶⠧")
# return list("⠻⠽⠾⠷⠯⠟")
# return list("|/—◦\\")
spinner_chars = "⣾⣽⣻⢿⡿⣟⣯⣷" # borrowed from rich python package (other: ⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏)
return (list(spinner_chars[::-1]) * 7) + (list("|/-\\") * 2)
sys.stdout.write = tidy_stdout_write
spina = ascii_spinners() ; spini = 0 ; spinn = len(spina) # noqa
sentinel = "[progress]" ; sentinel_internal = f"{sentinel}:" # noqa
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "dcicutils"
version = "8.8.3.1b20" # TODO: To become 8.8.4
version = "8.8.3.1b21" # TODO: To become 8.8.4
description = "Utility package for interacting with the 4DN Data Portal and other 4DN resources"
authors = ["4DN-DCIC Team <[email protected]>"]
license = "MIT"
Expand Down

0 comments on commit aeaaccb

Please sign in to comment.