Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: tqdm.auto requires ipywidgets for notebook support. #614

Merged
merged 6 commits into from Mar 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .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
16 changes: 16 additions & 0 deletions changelog.txt
Expand Up @@ -5,6 +5,22 @@ Changelog
The **signac-flow** package follows `semantic versioning <https://semver.org/>`_.
The numbers in brackets denote the related GitHub issue and/or pull request.

Version 0.19
============

[0.19.0] -- 2022-xx-xx
----------------------

Changed
+++++++

- Drop support for `tqdm <https://github.com/tqdm/tqdm>`__ versions older than `4.60.0` (#614).

Fixed
+++++

- Progress bars shown in notebooks fall back to text-based output if ipywidgets is not available (#602, #614).

Version 0.18
============

Expand Down
2 changes: 1 addition & 1 deletion flow/project.py
Expand Up @@ -36,7 +36,6 @@
import signac
from jinja2 import TemplateNotFound as Jinja2TemplateNotFound
from signac.contrib.filterparse import parse_filter_arg
from tqdm.auto import tqdm

from .aggregates import (
_AggregatesCursor,
Expand Down Expand Up @@ -73,6 +72,7 @@
add_cwd_to_environment_pythonpath,
roundrobin,
switch_to_directory,
tqdm,
)
from .util.translate import abbreviate, shorten

Expand Down
3 changes: 1 addition & 2 deletions flow/render_status.py
Expand Up @@ -2,10 +2,9 @@
# All rights reserved.
# This software is licensed under the BSD 3-Clause License.
"""Status rendering logic."""
from tqdm.auto import tqdm

from .scheduling.base import JobStatus
from .util import mistune
from .util.misc import tqdm


def _render_status(
Expand Down
18 changes: 16 additions & 2 deletions flow/util/misc.py
Expand Up @@ -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.
Expand Down Expand Up @@ -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):
Expand All @@ -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,
)

Expand All @@ -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
2 changes: 1 addition & 1 deletion requirements.txt
Expand Up @@ -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
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -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",
]
Expand Down