Skip to content

Commit

Permalink
tech-debt: drop more legacy code
Browse files Browse the repository at this point in the history
  • Loading branch information
casperdcl committed Mar 3, 2023
1 parent c0a893b commit 687f5e4
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 45 deletions.
20 changes: 2 additions & 18 deletions tqdm/contrib/concurrent.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,12 @@
Thin wrappers around `concurrent.futures`.
"""
from contextlib import contextmanager
from operator import length_hint
from os import cpu_count

from ..auto import tqdm as tqdm_auto
from ..std import TqdmWarning

try:
from operator import length_hint
except ImportError:
def length_hint(it, default=0):
"""Returns `len(it)`, falling back to `default`"""
try:
return len(it)
except TypeError:
return default
try:
from os import cpu_count
except ImportError:
try:
from multiprocessing import cpu_count
except ImportError:
def cpu_count():
return 4

__author__ = {"github.com/": ["casperdcl"]}
__all__ = ['thread_map', 'process_map']

Expand Down
14 changes: 3 additions & 11 deletions tqdm/std.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,21 +509,16 @@ def format_meter(n, total, elapsed, ncols=None, prefix='', ascii=False, unit='it
if bar_format:
format_dict.update(percentage=percentage)

# auto-remove colon for empty `desc`
# auto-remove colon for empty `{desc}`
if not prefix:
bar_format = bar_format.replace("{desc}: ", '')
else:
bar_format = "{l_bar}{bar}{r_bar}"

full_bar = FormatReplace()
try:
nobar = bar_format.format(bar=full_bar, **format_dict)
except UnicodeEncodeError:
bar_format = str(bar_format)
nobar = bar_format.format(bar=full_bar, **format_dict)
nobar = bar_format.format(bar=full_bar, **format_dict)
if not full_bar.format_called:
# no {bar}, we can just format and return
return nobar
return nobar # no `{bar}`; nothing else to do

# Formatting progress bar space available for bar's display
full_bar = Bar(frac,
Expand Down Expand Up @@ -1111,9 +1106,6 @@ def __bool__(self):
raise TypeError('bool() undefined when iterable == total == None')
return bool(self.iterable)

def __nonzero__(self):
return self.__bool__()

def __len__(self):
return (
self.total if self.iterable is None
Expand Down
9 changes: 2 additions & 7 deletions tqdm/tk.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,10 @@
"""
import re
import sys
import tkinter
import tkinter.ttk as ttk
from warnings import warn

try:
import tkinter
import tkinter.ttk as ttk
except ImportError:
import Tkinter as tkinter
import ttk as ttk

from .std import TqdmExperimentalWarning, TqdmWarning
from .std import tqdm as std_tqdm

Expand Down
13 changes: 4 additions & 9 deletions tqdm/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
import re
import sys
from functools import wraps
# TODO consider using wcswidth third-party package for 0-width characters
from unicodedata import east_asian_width
from warnings import warn
from weakref import proxy

_range, _unich, _unicode, _basestring = range, chr, str, str

CUR_OS = sys.platform
IS_WIN = any(CUR_OS.startswith(i) for i in ['win32', 'cygwin'])
IS_NIX = any(CUR_OS.startswith(i) for i in ['aix', 'linux', 'darwin'])
Expand Down Expand Up @@ -301,14 +302,8 @@ def _term_move_up(): # pragma: no cover
return '' if (os.name == 'nt') and (colorama is None) else '\x1b[A'


try:
# TODO consider using wcswidth third-party package for 0-width characters
from unicodedata import east_asian_width
except ImportError:
_text_width = len
else:
def _text_width(s):
return sum(2 if east_asian_width(ch) in 'FW' else 1 for ch in str(s))
def _text_width(s):
return sum(2 if east_asian_width(ch) in 'FW' else 1 for ch in str(s))


def disp_len(data):
Expand Down

0 comments on commit 687f5e4

Please sign in to comment.