-
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bump version, merge pull request #43 from devel
- Loading branch information
Showing
2 changed files
with
14 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,33 +18,15 @@ | |
from io import StringIO | ||
string_types = (str,) | ||
|
||
from tqdm import tqdm | ||
from tqdm.utils import _screen_shape_wrapper | ||
try: | ||
from tqdm import tqdm | ||
try: | ||
from threading import RLock | ||
except ImportError: | ||
pass | ||
else: | ||
tqdm.set_lock(RLock()) | ||
tqdm = partial(tqdm, lock_args=(False,)) | ||
from threading import RLock | ||
except ImportError: | ||
class tqdm(object): | ||
def __init__(self, iterable=None, **kwargs): | ||
log.info('install `tqdm` (https://github.com/tqdm/tqdm)' | ||
' for a realtime progressbar') | ||
self.iterable = iterable | ||
self.n = 0 | ||
|
||
def __iter__(self): | ||
for i in self.iterable: | ||
self.n += 1 | ||
sys.stderr.write("%d/%d\r" % (self.n, len(self.iterable))) | ||
sys.stderr.flush() | ||
yield i | ||
|
||
@classmethod | ||
def write(cls, msg, end='\n'): | ||
sys.stderr.write(msg + end) | ||
pass | ||
else: | ||
tqdm.set_lock(RLock()) | ||
tqdm = partial(tqdm, lock_args=(False,)) | ||
|
||
__author__ = "Casper da Costa-Luis <[email protected]>" | ||
__date__ = "2016-2020" | ||
|
@@ -54,17 +36,17 @@ def write(cls, msg, end='\n'): | |
__copyright__ = ' '.join(("Copyright (c)", __date__, __author__, __licence__)) | ||
__license__ = __licence__ # weird foreign language | ||
|
||
TERM_WIDTH = _screen_shape_wrapper()(sys.stdout)[0] | ||
if not TERM_WIDTH: | ||
# non interactive pipe | ||
TERM_WIDTH = 256 | ||
|
||
|
||
class TqdmStream(object): | ||
@classmethod | ||
def write(cls, msg): | ||
tqdm.write(msg, end='') | ||
|
||
# is this required? | ||
# @classmethod | ||
# def flush(_): | ||
# pass | ||
|
||
|
||
def check_output(*a, **k): | ||
log.debug(' '.join(a[0][3:])) | ||
|
@@ -114,95 +96,6 @@ def fext(fn): | |
return res[-1] if len(res) > 1 else '' | ||
|
||
|
||
def _environ_cols_windows(fp): # pragma: no cover | ||
try: | ||
from ctypes import windll, create_string_buffer | ||
import struct | ||
from sys import stdin, stdout | ||
|
||
io_handle = -12 # assume stderr | ||
if fp == stdin: | ||
io_handle = -10 | ||
elif fp == stdout: | ||
io_handle = -11 | ||
|
||
h = windll.kernel32.GetStdHandle(io_handle) | ||
csbi = create_string_buffer(22) | ||
res = windll.kernel32.GetConsoleScreenBufferInfo(h, csbi) | ||
if res: | ||
(_bufx, _bufy, _curx, _cury, _wattr, left, _top, right, _bottom, | ||
_maxx, _maxy) = struct.unpack("hhhhHhhhhhh", csbi.raw) | ||
# nlines = bottom - top + 1 | ||
return right - left # +1 | ||
except: | ||
pass | ||
return None | ||
|
||
|
||
def _environ_cols_tput(*args): # pragma: no cover | ||
"""cygwin xterm (windows)""" | ||
try: | ||
import shlex | ||
cols = int(subprocess.check_call(shlex.split('tput cols'))) | ||
# rows = int(subprocess.check_call(shlex.split('tput lines'))) | ||
return cols | ||
except: | ||
pass | ||
return None | ||
|
||
|
||
def _environ_cols_linux(fp): # pragma: no cover | ||
|
||
# import os | ||
# if fp is None: | ||
# try: | ||
# fp = os.open(os.ctermid(), os.O_RDONLY) | ||
# except: | ||
# pass | ||
try: | ||
from termios import TIOCGWINSZ | ||
from fcntl import ioctl | ||
from array import array | ||
except ImportError: | ||
return None | ||
else: | ||
try: | ||
return array('h', ioctl(fp, TIOCGWINSZ, '\0' * 8))[1] | ||
except: | ||
try: | ||
from os.environ import get | ||
except ImportError: | ||
return None | ||
else: | ||
return int(get('COLUMNS', 1)) - 1 | ||
|
||
|
||
def _environ_cols_wrapper(): # pragma: no cover | ||
""" | ||
Return a function which gets width and height of console | ||
(linux,osx,windows,cygwin). | ||
Based on https://raw.githubusercontent.com/tqdm/tqdm/master/tqdm/_utils.py | ||
""" | ||
import platform | ||
current_os = platform.system() | ||
_environ_cols = None | ||
if current_os in ['Windows', 'cli']: | ||
_environ_cols = _environ_cols_windows | ||
if _environ_cols is None: | ||
_environ_cols = _environ_cols_tput | ||
if any(current_os.startswith(i) for i in | ||
['CYGWIN', 'MSYS', 'Linux', 'Darwin', 'SunOS', 'FreeBSD']): | ||
_environ_cols = _environ_cols_linux | ||
return _environ_cols | ||
|
||
|
||
TERM_WIDTH = _environ_cols_wrapper()(sys.stdout) | ||
if not TERM_WIDTH: | ||
# non interactive pipe | ||
TERM_WIDTH = 256 | ||
|
||
|
||
def int_cast_or_len(i): | ||
""" | ||
>>> int_cast_or_len(range(10)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters