From 6defb63bf73587bba756dacd711c5189b73c4f48 Mon Sep 17 00:00:00 2001 From: seem Date: Fri, 22 Jul 2022 14:30:09 +1000 Subject: [PATCH] support unknown `total` by passing `total='noinfer'` --- Example.ipynb | 43 ++---- docs/core.html | 62 ++++---- docs/fastprogress.html | 273 ++++++++++++++++++++++------------- fastprogress/core.py | 6 +- fastprogress/fastprogress.py | 32 ++-- nbs/00_core.ipynb | 71 +++------ nbs/01_fastprogress.ipynb | 234 ++++++++++++++++++++---------- 7 files changed, 418 insertions(+), 303 deletions(-) diff --git a/Example.ipynb b/Example.ipynb index c9ca9ba..6fc1fed 100644 --- a/Example.ipynb +++ b/Example.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -19,7 +19,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -54,7 +54,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -63,7 +63,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -117,7 +117,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -170,7 +170,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -179,7 +179,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -217,7 +217,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -227,7 +227,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -274,31 +274,6 @@ "display_name": "Python 3", "language": "python", "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.7.4" - }, - "toc": { - "base_numbering": 1, - "nav_menu": {}, - "number_sections": false, - "sideBar": true, - "skip_h1_title": false, - "title_cell": "Table of Contents", - "title_sidebar": "Contents", - "toc_cell": false, - "toc_position": {}, - "toc_section_display": true, - "toc_window_display": false } }, "nbformat": 4, diff --git a/docs/core.html b/docs/core.html index c5cc128..2bd6e18 100644 --- a/docs/core.html +++ b/docs/core.html @@ -39,13 +39,6 @@

Display

-
- {% endraw %} - - {% raw %} - -
-
@@ -53,7 +46,9 @@

Display

-

format_time[source]

format_time(t)

+

format_time[source]

+
+

format_time(t)

Format t (in seconds) to (h):mm:ss

@@ -64,6 +59,13 @@

format_time +

{% endraw %} @@ -90,13 +92,6 @@

format_time -

- {% endraw %} - - {% raw %} - -
-
@@ -104,7 +99,9 @@

format_time -

html_progress_bar[source]

html_progress_bar(value, total, label, interrupted=False)

+

html_progress_bar[source]

+
+

html_progress_bar(value, total, label, interrupted=False)

Html code for a progress bar value/total with label

@@ -136,7 +133,9 @@

html_progress_bar -

text2html_table[source]

text2html_table(items)

+

text2html_table[source]

+
+

text2html_table(items)

Put the texts in items in an HTML table.

@@ -150,12 +149,6 @@

text2html_table {% endraw %} - {% raw %}
@@ -163,6 +156,12 @@

Detect if in or out notebook +

{% raw %}
@@ -174,7 +173,9 @@

Detect if in or out notebook -

in_colab[source]

in_colab()

+

in_colab[source]

+
+

in_colab()

Check if the code is running in Google Colaboratory

@@ -206,7 +207,9 @@

in_colab -

in_notebook[source]

in_notebook()

+

in_notebook[source]

+
+

in_notebook()

Check if the code is running in a jupyter notebook

@@ -217,6 +220,13 @@

in_notebook +

{% endraw %} @@ -272,5 +282,5 @@

in_notebookBase class -

- {% endraw %} - - {% raw %} - -
-
@@ -60,7 +53,9 @@

Base class -

class ProgressBar[source]

ProgressBar(gen, total=None, display=True, leave=True, parent=None, master=None, comment='')

+

class ProgressBar[source]

+
+

ProgressBar(gen=None, total=None, display=True, leave=True, parent=None, master=None, comment='')

@@ -70,6 +65,13 @@

class ProgressBar

+
+ {% endraw %} + + {% raw %} + +
+
{% endraw %} @@ -162,13 +164,6 @@

class ProgressBar -

- {% endraw %} - - {% raw %} - -
-
@@ -176,7 +171,9 @@

class ProgressBar -

class MasterBar[source]

MasterBar(gen, total=None) :: ProgressBar

+

class MasterBar[source]

+
+

MasterBar(gen, cls, total=None) :: ProgressBar

@@ -186,6 +183,13 @@

class MasterBar<

+
+ {% endraw %} + + {% raw %} + +
+
{% endraw %} @@ -270,13 +274,6 @@

Notebook progress bars -

- {% endraw %} - - {% raw %} - -
-
@@ -284,7 +281,9 @@

Notebook progress bars -

class NBProgressBar[source]

NBProgressBar(gen, total=None, display=True, leave=True, parent=None, master=None, comment='') :: ProgressBar

+

class NBProgressBar[source]

+
+

NBProgressBar(gen=None, total=None, display=True, leave=True, parent=None, master=None, comment='') :: ProgressBar

@@ -294,6 +293,13 @@

class NBProgressBar

+
+ {% endraw %} + + {% raw %} + +
+
{% endraw %} @@ -319,25 +325,31 @@

class NBProgressBar
+ +
+ + + +
+ +
- 100.00% [100/100 00:05<00:00]
- -
+
@@ -372,25 +384,31 @@

class NBProgressBar
+ +
+ + + +
+ +
- Interrupted
- -
+
@@ -404,13 +422,6 @@

class NBProgressBar
-
- {% endraw %} - - {% raw %} - -
-
@@ -418,7 +429,9 @@

class NBProgressBar
-

class NBMasterBar[source]

NBMasterBar(gen, total=None, hide_graph=False, order=None, clean_on_interrupt=False, total_time=False) :: MasterBar

+

class NBMasterBar[source]

+
+

NBMasterBar(gen, total=None, hide_graph=False, order=None, clean_on_interrupt=False, total_time=False) :: MasterBar

@@ -428,6 +441,13 @@

class NBMasterBar

+
+ {% endraw %} + + {% raw %} + +
+
{% endraw %} @@ -457,9 +477,27 @@

class NBMasterBar -Finished loop 0.

Finished loop 1.

Finished loop 2.

Finished loop 3.

Finished loop 4. + +

+ +
+ + +
Finished loop 0.

Finished loop 1.

Finished loop 2.

Finished loop 3.

Finished loop 4.

+
@@ -497,11 +535,29 @@

class NBMasterBar -Finished loop 0.

Finished loop 1.

Finished loop 2.

Finished loop 3.

Finished loop 4. + +

+ + +
Finished loop 0.

Finished loop 1.

Finished loop 2.

Finished loop 3.

Finished loop 4.

+ +
+ @@ -525,13 +581,6 @@

Console progress bars - - {% endraw %} - - {% raw %} - -
-
@@ -539,8 +588,11 @@

Console progress bars -

printing[source]

printing()

+

printing[source]

+
+

printing()

+

True if we want to print progress

@@ -570,7 +622,9 @@

printing -

class ConsoleProgressBar[source]

ConsoleProgressBar(gen, total=None, display=True, leave=True, parent=None, master=None, txt_len=60) :: ProgressBar

+

class ConsoleProgressBar[source]

+
+

ConsoleProgressBar(gen, total=None, display=True, leave=True, parent=None, master=None, txt_len=60) :: ProgressBar

@@ -580,6 +634,13 @@

class ConsoleP

+ + {% endraw %} + + {% raw %} + +
+
{% endraw %} @@ -604,7 +665,7 @@

class ConsoleP
-
+
 |████████████████████████████████████████| 100.00% [100/100 00:05<00:00]
@@ -638,7 +699,7 @@

class ConsoleP
-
+
 |██████████████████----------------------| 47.00% [47/100 00:02<00:02]
@@ -652,13 +713,6 @@

class ConsoleP
-
- {% endraw %} - - {% raw %} - -
-
@@ -666,7 +720,9 @@

class ConsoleP
-

print_and_maybe_save(line)

+ +
+

print_and_maybe_save(line)

@@ -697,7 +753,9 @@

@@ -707,6 +765,13 @@

class ConsoleMas

+ + {% endraw %} + + {% raw %} + +
+
{% endraw %} @@ -736,11 +801,11 @@

class ConsoleMas
-
Finished loop 0.
-Finished loop 1.
-Finished loop 2.
-Finished loop 3.
-Finished loop 4.
+
Finished loop 0.                                                                  
+Finished loop 1.                                                                  
+Finished loop 2.                                                                  
+Finished loop 3.                                                                  
+Finished loop 4.                                                                  
 
@@ -783,11 +848,11 @@

class ConsoleMas
-
Finished loop 0.
-Finished loop 1.
-Finished loop 2.
-Finished loop 3.
-Finished loop 4.
+
Finished loop 0.                                                                  
+Finished loop 1.                                                                  
+Finished loop 2.                                                                  
+Finished loop 3.                                                                  
+Finished loop 4.                                                                  
 
@@ -816,13 +881,6 @@

class ConsoleMas
-
- {% endraw %} - - {% raw %} - -
-
@@ -830,7 +888,9 @@

class ConsoleMas
-

force_console_behavior[source]

force_console_behavior()

+

force_console_behavior[source]

+
+

force_console_behavior()

Return the console progress bars

@@ -862,7 +922,9 @@

force_console_behavior<
-

workaround_empty_console_output[source]

workaround_empty_console_output()

+

workaround_empty_console_output[source]

+
+

workaround_empty_console_output()

Change console output behaviour to correctly show progress in consoles not recognizing at the end of line

@@ -874,6 +936,13 @@

workaround_emp

+

+ {% endraw %} + + {% raw %} + +
+
{% endraw %} @@ -911,5 +980,5 @@

workaround_emp {% endraw %}

- + diff --git a/fastprogress/core.py b/fastprogress/core.py index 27d3a00..5f2da12 100644 --- a/fastprogress/core.py +++ b/fastprogress/core.py @@ -24,6 +24,9 @@ def format_time(t): /* Needs to be in here for Safari polyfill so background images work as expected. */ background-size: auto; } + progress:not([value]), progress:not([value])::-webkit-progress-bar { + background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px); + } .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar { background: #F44336; } @@ -33,9 +36,10 @@ def format_time(t): def html_progress_bar(value, total, label, interrupted=False): "Html code for a progress bar `value`/`total` with `label`" bar_style = 'progress-bar-interrupted' if interrupted else '' + val = '' if total is None else f"value='{value}'" return f"""
- + {label}
""" diff --git a/fastprogress/fastprogress.py b/fastprogress/fastprogress.py index ed043ce..a5dfc14 100644 --- a/fastprogress/fastprogress.py +++ b/fastprogress/fastprogress.py @@ -12,11 +12,11 @@ # Cell class ProgressBar(): - update_every,first_its = 0.2,5 + update_every,first_its,lt = 0.2,5,'<' def __init__(self, gen, total=None, display=True, leave=True, parent=None, master=None, comment=''): self.gen,self.parent,self.master,self.comment = gen,parent,master,comment - self.total = len(gen) if total is None else total + self.total = None if total=='noinfer' else len(gen) if total is None else total self.last_v = 0 if parent is None: self.leave,self.display = leave,display else: @@ -39,9 +39,12 @@ def __iter__(self): if self.total != 0: self.update(0) try: for i,o in enumerate(self.gen): - if i >= self.total: break + if self.total and i >= self.total: break yield o self.update(i+1) + if self.total is None and self.last_v is not None: + self.total = i+1 + self.update(self.total) except Exception as e: self.on_interrupt() raise e @@ -52,28 +55,30 @@ def update(self, val): self.last_v = 0 if val == 0: self.start_t = self.last_t = time.time() - self.pred_t,self.last_v,self.wait_for = 0,0,1 + self.pred_t,self.last_v,self.wait_for = None,0,1 self.update_bar(0) - elif val <= self.first_its or val >= self.last_v + self.wait_for or val >= self.total: + elif val <= self.first_its or val >= self.last_v + self.wait_for or (self.total and val >= self.total): cur_t = time.time() avg_t = (cur_t - self.start_t) / val self.wait_for = max(int(self.update_every / (avg_t+1e-8)),1) - self.pred_t = avg_t * self.total + self.pred_t = None if self.total is None else avg_t * self.total self.last_v,self.last_t = val,cur_t self.update_bar(val) - if val >= self.total: + if self.total is not None and val >= self.total: self.on_iter_end() self.last_v = None def update_bar(self, val): + if self.total == 0: + warn("Your generator is empty.") + return self.on_update(0, '100% [0/0]') + pct = '' if self.total is None else f'{100 * val/self.total:.2f}% ' + tot = '?' if self.total is None else str(self.total) elapsed_t = self.last_t - self.start_t - remaining_t = format_time(self.pred_t - elapsed_t) + remaining_t = '?' if self.pred_t is None else format_time(self.pred_t - elapsed_t) elapsed_t = format_time(elapsed_t) end = '' if len(self.comment) == 0 else f' {self.comment}' - if self.total == 0: - warn("Your generator is empty.") - self.on_update(0, '100% [0/0]') - else: self.on_update(val, f'{100 * val/self.total:.2f}% [{val}/{self.total} {elapsed_t}<{remaining_t}{end}]') + self.on_update(val, f'{pct}[{val}/{tot} {elapsed_t}{self.lt}{remaining_t}{end}]') # Cell class MasterBar(ProgressBar): @@ -104,6 +109,7 @@ def update(self, val): self.main_bar.update(val) # Cell class NBProgressBar(ProgressBar): + lt = '<' def on_iter_begin(self): super().on_iter_begin() self.progress = html_progress_bar(0, self.total, "") @@ -246,7 +252,7 @@ def on_update(self, val, text): filled_len = int(self.length * val // self.total) if self.total else 0 bar = self.fill * filled_len + '-' * (self.length - filled_len) to_write = f'\r{self.prefix} |{bar}| {text}' - if val >= self.total: end = '\r' + if self.total and val >= self.total: end = '\r' else: end = self.end if len(to_write) > self.max_len: self.max_len=len(to_write) if printing(): WRITER_FN(to_write, end=end, flush=FLUSH) diff --git a/nbs/00_core.ipynb b/nbs/00_core.ipynb index fa294d5..95aa9c2 100644 --- a/nbs/00_core.ipynb +++ b/nbs/00_core.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -20,19 +20,15 @@ }, { "cell_type": "markdown", - "metadata": { - "heading_collapsed": true - }, + "metadata": {}, "source": [ "## Display" ] }, { "cell_type": "code", - "execution_count": 2, - "metadata": { - "hidden": true - }, + "execution_count": null, + "metadata": {}, "outputs": [], "source": [ "# export\n", @@ -46,10 +42,8 @@ }, { "cell_type": "code", - "execution_count": 3, - "metadata": { - "hidden": true - }, + "execution_count": null, + "metadata": {}, "outputs": [], "source": [ "assert format_time(12) == '00:12'\n", @@ -59,10 +53,8 @@ }, { "cell_type": "code", - "execution_count": 4, - "metadata": { - "hidden": true - }, + "execution_count": null, + "metadata": {}, "outputs": [], "source": [ "# export\n", @@ -78,6 +70,9 @@ " /* Needs to be in here for Safari polyfill so background images work as expected. */\n", " background-size: auto;\n", " }\n", + " progress:not([value]), progress:not([value])::-webkit-progress-bar {\n", + " background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n", + " }\n", " .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n", " background: #F44336;\n", " }\n", @@ -87,9 +82,10 @@ "def html_progress_bar(value, total, label, interrupted=False):\n", " \"Html code for a progress bar `value`/`total` with `label`\"\n", " bar_style = 'progress-bar-interrupted' if interrupted else ''\n", + " val = '' if total is None else f\"value='{value}'\"\n", " return f\"\"\"\n", "
\n", - " \n", + " \n", " {label}\n", "
\n", " \"\"\"" @@ -97,10 +93,8 @@ }, { "cell_type": "code", - "execution_count": 5, - "metadata": { - "hidden": true - }, + "execution_count": null, + "metadata": {}, "outputs": [], "source": [ "# export\n", @@ -127,7 +121,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -144,7 +138,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -167,7 +161,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -184,7 +178,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -204,34 +198,9 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.7.7" - }, - "toc": { - "base_numbering": 1, - "nav_menu": {}, - "number_sections": false, - "sideBar": true, - "skip_h1_title": true, - "title_cell": "Table of Contents", - "title_sidebar": "Contents", - "toc_cell": false, - "toc_position": {}, - "toc_section_display": true, - "toc_window_display": false } }, "nbformat": 4, diff --git a/nbs/01_fastprogress.ipynb b/nbs/01_fastprogress.ipynb index fa50223..5db6b11 100644 --- a/nbs/01_fastprogress.ipynb +++ b/nbs/01_fastprogress.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -15,7 +15,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -31,17 +31,17 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#export\n", "class ProgressBar():\n", - " update_every,first_its = 0.2,5\n", + " update_every,first_its,lt = 0.2,5,'<'\n", "\n", " def __init__(self, gen, total=None, display=True, leave=True, parent=None, master=None, comment=''):\n", " self.gen,self.parent,self.master,self.comment = gen,parent,master,comment\n", - " self.total = len(gen) if total is None else total\n", + " self.total = None if total=='noinfer' else len(gen) if total is None else total\n", " self.last_v = 0\n", " if parent is None: self.leave,self.display = leave,display\n", " else:\n", @@ -64,9 +64,12 @@ " if self.total != 0: self.update(0)\n", " try:\n", " for i,o in enumerate(self.gen):\n", - " if i >= self.total: break\n", + " if self.total and i >= self.total: break\n", " yield o\n", " self.update(i+1)\n", + " if self.total is None and self.last_v is not None:\n", + " self.total = i+1\n", + " self.update(self.total)\n", " except Exception as e:\n", " self.on_interrupt()\n", " raise e\n", @@ -77,33 +80,35 @@ " self.last_v = 0\n", " if val == 0:\n", " self.start_t = self.last_t = time.time()\n", - " self.pred_t,self.last_v,self.wait_for = 0,0,1\n", + " self.pred_t,self.last_v,self.wait_for = None,0,1\n", " self.update_bar(0)\n", - " elif val <= self.first_its or val >= self.last_v + self.wait_for or val >= self.total:\n", + " elif val <= self.first_its or val >= self.last_v + self.wait_for or (self.total and val >= self.total):\n", " cur_t = time.time()\n", " avg_t = (cur_t - self.start_t) / val\n", " self.wait_for = max(int(self.update_every / (avg_t+1e-8)),1)\n", - " self.pred_t = avg_t * self.total\n", + " self.pred_t = None if self.total is None else avg_t * self.total\n", " self.last_v,self.last_t = val,cur_t\n", " self.update_bar(val)\n", - " if val >= self.total: \n", + " if self.total is not None and val >= self.total:\n", " self.on_iter_end()\n", " self.last_v = None\n", "\n", " def update_bar(self, val):\n", + " if self.total == 0:\n", + " warn(\"Your generator is empty.\")\n", + " return self.on_update(0, '100% [0/0]')\n", + " pct = '' if self.total is None else f'{100 * val/self.total:.2f}% '\n", + " tot = '?' if self.total is None else str(self.total)\n", " elapsed_t = self.last_t - self.start_t\n", - " remaining_t = format_time(self.pred_t - elapsed_t)\n", + " remaining_t = '?' if self.pred_t is None else format_time(self.pred_t - elapsed_t)\n", " elapsed_t = format_time(elapsed_t)\n", " end = '' if len(self.comment) == 0 else f' {self.comment}'\n", - " if self.total == 0:\n", - " warn(\"Your generator is empty.\")\n", - " self.on_update(0, '100% [0/0]')\n", - " else: self.on_update(val, f'{100 * val/self.total:.2f}% [{val}/{self.total} {elapsed_t}<{remaining_t}{end}]')" + " self.on_update(val, f'{pct}[{val}/{tot} {elapsed_t}{self.lt}{remaining_t}{end}]')" ] }, { "cell_type": "code", - "execution_count": 5, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -116,7 +121,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -126,13 +131,12 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ "tst_pb = VerboseProgressBar(range(6))\n", - "s = io.StringIO()\n", - "with redirect_stdout(s): \n", + "with redirect_stdout(io.StringIO()) as s:\n", " for i in tst_pb: time.sleep(0.1)\n", "\n", "assert s.getvalue() == '\\n'.join(['on_iter_begin'] + [f'on_update {i}' for i in range(7)] + ['on_iter_end']) + '\\n'" @@ -140,13 +144,12 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ "tst_pb = VerboseProgressBar(range(6))\n", - "s = io.StringIO()\n", - "with redirect_stdout(s): \n", + "with redirect_stdout(io.StringIO()) as s:\n", " for i in range(7): \n", " tst_pb.update(i)\n", " time.sleep(0.1)\n", @@ -156,7 +159,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -181,7 +184,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -195,7 +198,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -223,7 +226,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -241,7 +244,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -257,12 +260,13 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#export\n", "class NBProgressBar(ProgressBar):\n", + " lt = '<'\n", " def on_iter_begin(self):\n", " super().on_iter_begin()\n", " self.progress = html_progress_bar(0, self.total, \"\")\n", @@ -289,7 +293,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -304,6 +308,9 @@ " /* Needs to be in here for Safari polyfill so background images work as expected. */\n", " background-size: auto;\n", " }\n", + " progress:not([value]), progress:not([value])::-webkit-progress-bar {\n", + " background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n", + " }\n", " .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n", " background: #F44336;\n", " }\n", @@ -322,7 +329,7 @@ "\n", "
\n", " \n", - " 100.00% [100/100 00:05<00:00]\n", + " 100.00% [100/100 00:05<00:00]\n", "
\n", " " ], @@ -341,7 +348,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -356,6 +363,9 @@ " /* Needs to be in here for Safari polyfill so background images work as expected. */\n", " background-size: auto;\n", " }\n", + " progress:not([value]), progress:not([value])::-webkit-progress-bar {\n", + " background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n", + " }\n", " .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n", " background: #F44336;\n", " }\n", @@ -396,7 +406,64 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "\n", + "
\n", + " \n", + " [47/? 00:02<?]\n", + "
\n", + " " + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "tst = NBProgressBar(range(100), total='noinfer')\n", + "for i in range(50):\n", + " time.sleep(0.05)\n", + " tst.update(i)" + ] + }, + { + "cell_type": "code", + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -406,7 +473,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -487,7 +554,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -502,6 +569,9 @@ " /* Needs to be in here for Safari polyfill so background images work as expected. */\n", " background-size: auto;\n", " }\n", + " progress:not([value]), progress:not([value])::-webkit-progress-bar {\n", + " background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n", + " }\n", " .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n", " background: #F44336;\n", " }\n", @@ -538,7 +608,7 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -553,6 +623,9 @@ " /* Needs to be in here for Safari polyfill so background images work as expected. */\n", " background-size: auto;\n", " }\n", + " progress:not([value]), progress:not([value])::-webkit-progress-bar {\n", + " background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n", + " }\n", " .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n", " background: #F44336;\n", " }\n", @@ -599,7 +672,7 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -614,7 +687,7 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -627,7 +700,7 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -662,7 +735,7 @@ " filled_len = int(self.length * val // self.total) if self.total else 0\n", " bar = self.fill * filled_len + '-' * (self.length - filled_len)\n", " to_write = f'\\r{self.prefix} |{bar}| {text}'\n", - " if val >= self.total: end = '\\r'\n", + " if self.total and val >= self.total: end = '\\r'\n", " else: end = self.end\n", " if len(to_write) > self.max_len: self.max_len=len(to_write)\n", " if printing(): WRITER_FN(to_write, end=end, flush=FLUSH)" @@ -670,7 +743,7 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -688,7 +761,7 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -709,7 +782,41 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " |----------------------------------------| [47/? 00:02