From 2b276648154767470ebacbd25058596ef8b0e7a9 Mon Sep 17 00:00:00 2001 From: Bradley Dice Date: Sun, 27 Feb 2022 11:23:35 -0600 Subject: [PATCH 1/4] Fix: tqdm.auto requires ipywidgets for notebook support. --- flow/project.py | 11 ++++++++++- flow/render_status.py | 10 +++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/flow/project.py b/flow/project.py index 228fc6ce8..1ec2bc22e 100644 --- a/flow/project.py +++ b/flow/project.py @@ -36,7 +36,16 @@ import signac from jinja2 import TemplateNotFound as Jinja2TemplateNotFound from signac.contrib.filterparse import parse_filter_arg -from tqdm.auto import tqdm + +try: + # If ipywidgets is installed, use "auto" tqdm to improve notebook support. + # Otherwise, use only text-based progress bars. This workaround can be + # removed after https://github.com/tqdm/tqdm/pull/1218. + import ipywidgets # noqa: F401 +except ImportError: + from tqdm import tqdm +else: + from tqdm.auto import tqdm from .aggregates import ( _AggregatesCursor, diff --git a/flow/render_status.py b/flow/render_status.py index 32324bd02..fa4e582b8 100644 --- a/flow/render_status.py +++ b/flow/render_status.py @@ -2,7 +2,15 @@ # All rights reserved. # This software is licensed under the BSD 3-Clause License. """Status rendering logic.""" -from tqdm.auto import tqdm +try: + # If ipywidgets is installed, use "auto" tqdm to improve notebook support. + # Otherwise, use only text-based progress bars. This workaround can be + # removed after https://github.com/tqdm/tqdm/pull/1218. + import ipywidgets # noqa: F401 +except ImportError: + from tqdm import tqdm +else: + from tqdm.auto import tqdm from .scheduling.base import JobStatus from .util import mistune From bcadcdc4694fa991134eeeb7a33e91b871cde09b Mon Sep 17 00:00:00 2001 From: Bradley Dice Date: Sun, 27 Feb 2022 11:26:27 -0600 Subject: [PATCH 2/4] Update changelog. --- changelog.txt | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/changelog.txt b/changelog.txt index bf93c0971..e15f98213 100644 --- a/changelog.txt +++ b/changelog.txt @@ -5,6 +5,17 @@ Changelog The **signac-flow** package follows `semantic versioning `_. The numbers in brackets denote the related GitHub issue and/or pull request. +Version 0.19 +============ + +[0.19.0] -- 2022-xx-xx +---------------------- + +Fixed ++++++ + +- Progress bars shown in notebooks fall back to text-based output if ipywidgets is not available (#602, #614). + Version 0.18 ============ From 91d4a9afb49304987b3a51d1eac2eb35e27985cb Mon Sep 17 00:00:00 2001 From: Bradley Dice Date: Sun, 27 Feb 2022 11:52:49 -0600 Subject: [PATCH 3/4] Use tqdm_class to avoid bug in automatic detection. --- flow/project.py | 11 +---------- flow/render_status.py | 11 +---------- flow/util/misc.py | 18 ++++++++++++++++-- 3 files changed, 18 insertions(+), 22 deletions(-) diff --git a/flow/project.py b/flow/project.py index 1ec2bc22e..f84b330b9 100644 --- a/flow/project.py +++ b/flow/project.py @@ -37,16 +37,6 @@ from jinja2 import TemplateNotFound as Jinja2TemplateNotFound from signac.contrib.filterparse import parse_filter_arg -try: - # If ipywidgets is installed, use "auto" tqdm to improve notebook support. - # Otherwise, use only text-based progress bars. This workaround can be - # removed after https://github.com/tqdm/tqdm/pull/1218. - import ipywidgets # noqa: F401 -except ImportError: - from tqdm import tqdm -else: - from tqdm.auto import tqdm - from .aggregates import ( _AggregatesCursor, _AggregateStore, @@ -82,6 +72,7 @@ add_cwd_to_environment_pythonpath, roundrobin, switch_to_directory, + tqdm, ) from .util.translate import abbreviate, shorten diff --git a/flow/render_status.py b/flow/render_status.py index fa4e582b8..657808d0f 100644 --- a/flow/render_status.py +++ b/flow/render_status.py @@ -2,18 +2,9 @@ # All rights reserved. # This software is licensed under the BSD 3-Clause License. """Status rendering logic.""" -try: - # If ipywidgets is installed, use "auto" tqdm to improve notebook support. - # Otherwise, use only text-based progress bars. This workaround can be - # removed after https://github.com/tqdm/tqdm/pull/1218. - import ipywidgets # noqa: F401 -except ImportError: - from tqdm import tqdm -else: - from tqdm.auto import tqdm - from .scheduling.base import JobStatus from .util import mistune +from .util.misc import tqdm def _render_status( diff --git a/flow/util/misc.py b/flow/util/misc.py index 0190d4c83..12b295e7f 100644 --- a/flow/util/misc.py +++ b/flow/util/misc.py @@ -14,6 +14,16 @@ from tqdm.contrib import tmap from tqdm.contrib.concurrent import process_map, thread_map +try: + # If ipywidgets is installed, use "auto" tqdm to improve notebook support. + # Otherwise, use only text-based progress bars. This workaround can be + # removed after https://github.com/tqdm/tqdm/pull/1218. + import ipywidgets # noqa: F401 +except ImportError: + from tqdm import tqdm +else: + from tqdm.auto import tqdm + def _positive_int(value): """Parse a command line argument as a positive integer. @@ -348,7 +358,10 @@ def _get_parallel_executor(parallelization="none"): """ if parallelization == "thread": - parallel_executor = thread_map + + def parallel_executor(func, iterable, **kwargs): + return thread_map(func, iterable, tqdm_class=tqdm, **kwargs) + elif parallelization == "process": def parallel_executor(func, iterable, **kwargs): @@ -365,6 +378,7 @@ def parallel_executor(func, iterable, **kwargs): # regardless of whether it is a local function. partial(_run_cloudpickled_func, cloudpickle.dumps(func)), map(cloudpickle.dumps, iterable), + tqdm_class=tqdm, **kwargs, ) @@ -374,6 +388,6 @@ def parallel_executor(func, iterable, **kwargs): if "chunksize" in kwargs: # Chunk size only applies to thread/process parallel executors del kwargs["chunksize"] - return list(tmap(func, iterable, **kwargs)) + return list(tmap(func, iterable, tqdm_class=tqdm, **kwargs)) return parallel_executor From af2629cca803e970aa1154a60abdd3dc75662198 Mon Sep 17 00:00:00 2001 From: Bradley Dice Date: Sun, 27 Feb 2022 12:24:09 -0600 Subject: [PATCH 4/4] Bump tqdm requirement to 4.60.0 for https://github.com/tqdm/tqdm/pull/1148. --- .circleci/ci-oldest-reqs.txt | 2 +- changelog.txt | 5 +++++ requirements.txt | 2 +- setup.py | 2 +- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/.circleci/ci-oldest-reqs.txt b/.circleci/ci-oldest-reqs.txt index 3e79fb8eb..5a2caf640 100644 --- a/.circleci/ci-oldest-reqs.txt +++ b/.circleci/ci-oldest-reqs.txt @@ -1,5 +1,5 @@ cloudpickle==1.1.1 deprecation==2.0.0 jinja2==2.10 -tqdm==4.48.1 +tqdm==4.60.0 jsonschema==3.0.0 diff --git a/changelog.txt b/changelog.txt index e15f98213..9627fbdb7 100644 --- a/changelog.txt +++ b/changelog.txt @@ -11,6 +11,11 @@ Version 0.19 [0.19.0] -- 2022-xx-xx ---------------------- +Changed ++++++++ + +- Drop support for `tqdm `__ versions older than `4.60.0` (#614). + Fixed +++++ diff --git a/requirements.txt b/requirements.txt index c55e63b53..b0adb707d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,5 +2,5 @@ signac>=1.3.0 jinja2>=2.10 cloudpickle>=1.1.1 deprecation>=2.0.0 -tqdm>=4.48.1 +tqdm>=4.60.0 jsonschema>=3.0.0 diff --git a/setup.py b/setup.py index d3bbc41c6..bfb8543b4 100644 --- a/setup.py +++ b/setup.py @@ -15,7 +15,7 @@ # Deprecation management "deprecation>=2.0.0", # Progress bars - "tqdm>=4.48.1", + "tqdm>=4.60.0", # For schema validation "jsonschema>=3.0.0", ]