Skip to content

Commit

Permalink
Merge branch 'release/4.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
wolph committed Jan 5, 2022
2 parents 005d8a1 + e84e267 commit fcbf77b
Show file tree
Hide file tree
Showing 13 changed files with 147 additions and 203 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
timeout-minutes: 10
strategy:
matrix:
python-version: [3.6, 3.7, 3.8, 3.9]
python-version: ['3.7', '3.8', '3.9', '3.10']

steps:
- uses: actions/checkout@v2
Expand Down
11 changes: 4 additions & 7 deletions examples.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
from __future__ import with_statement

import functools
import random
import sys
Expand Down Expand Up @@ -187,7 +181,10 @@ def granular_progress_example():
progressbar.GranularBar(markers=" ⡀⡄⡆⡇⣇⣧⣷⣿", left='', right='|'),
progressbar.GranularBar(markers=" .oO", left='', right=''),
]
for i in progressbar.progressbar(range(100), widgets=widgets):
for i in progressbar.progressbar(list(range(100)), widgets=widgets):
time.sleep(0.03)

for i in progressbar.progressbar(iter(range(100)), widgets=widgets):
time.sleep(0.03)


Expand Down
2 changes: 1 addition & 1 deletion progressbar/__about__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
long running operations.
'''.strip().split())
__email__ = '[email protected]'
__version__ = '3.55.0'
__version__ = '4.0.0'
__license__ = 'BSD'
__copyright__ = 'Copyright 2015 Rick van Hattem (Wolph)'
__url__ = 'https://github.com/WoLpH/python-progressbar'
80 changes: 34 additions & 46 deletions progressbar/__init__.py
Original file line number Diff line number Diff line change
@@ -1,52 +1,40 @@
from datetime import date

from .utils import (
len_color,
streams
)
from .shortcuts import progressbar

from .widgets import (
Timer,
ETA,
AdaptiveETA,
AbsoluteETA,
DataSize,
FileTransferSpeed,
AdaptiveTransferSpeed,
AnimatedMarker,
Counter,
Percentage,
FormatLabel,
SimpleProgress,
Bar,
ReverseBar,
BouncingBar,
RotatingMarker,
VariableMixin,
MultiRangeBar,
MultiProgressBar,
GranularBar,
FormatLabelBar,
PercentageLabelBar,
Variable,
DynamicMessage,
FormatCustomText,
CurrentTime
)

from .bar import (
ProgressBar,
DataTransferBar,
NullBar,
)
from .__about__ import __author__
from .__about__ import __version__
from .bar import DataTransferBar
from .bar import NullBar
from .bar import ProgressBar
from .base import UnknownLength


from .__about__ import (
__author__,
__version__,
)
from .shortcuts import progressbar
from .utils import len_color
from .utils import streams
from .widgets import AbsoluteETA
from .widgets import AdaptiveETA
from .widgets import AdaptiveTransferSpeed
from .widgets import AnimatedMarker
from .widgets import Bar
from .widgets import BouncingBar
from .widgets import Counter
from .widgets import CurrentTime
from .widgets import DataSize
from .widgets import DynamicMessage
from .widgets import ETA
from .widgets import FileTransferSpeed
from .widgets import FormatCustomText
from .widgets import FormatLabel
from .widgets import FormatLabelBar
from .widgets import GranularBar
from .widgets import MultiProgressBar
from .widgets import MultiRangeBar
from .widgets import Percentage
from .widgets import PercentageLabelBar
from .widgets import ReverseBar
from .widgets import RotatingMarker
from .widgets import SimpleProgress
from .widgets import Timer
from .widgets import Variable
from .widgets import VariableMixin

__date__ = str(date.today())
__all__ = [
Expand Down
43 changes: 21 additions & 22 deletions progressbar/bar.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,29 @@
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from __future__ import with_statement
from __future__ import annotations

import sys
import logging
import math
import os
import sys
import time
import timeit
import logging
import warnings
from datetime import datetime
from copy import deepcopy
from datetime import datetime

from python_utils import types

try: # pragma: no cover
from collections import abc
except ImportError: # pragma: no cover
import collections as abc

from python_utils import converters

import six

from . import widgets
from . import widgets as widgets_module # Avoid name collision
from . import base
from . import utils


logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -58,8 +55,10 @@ class ProgressBarBase(abc.Iterable, ProgressBarMixinBase):

class DefaultFdMixin(ProgressBarMixinBase):

def __init__(self, fd=sys.stderr, is_terminal=None, line_breaks=None,
enable_colors=None, **kwargs):
def __init__(self, fd: types.IO = sys.stderr,
is_terminal: bool | None = None,
line_breaks: bool | None = None,
enable_colors: bool | None = None, **kwargs):
if fd is sys.stdout:
fd = utils.streams.original_stdout

Expand All @@ -76,8 +75,8 @@ def __init__(self, fd=sys.stderr, is_terminal=None, line_breaks=None,
# Check if it should overwrite the current line (suitable for
# iteractive terminals) or write line breaks (suitable for log files)
if line_breaks is None:
line_breaks = utils.env_flag('PROGRESSBAR_LINE_BREAKS', not
self.is_terminal)
line_breaks = utils.env_flag('PROGRESSBAR_LINE_BREAKS',
not self.is_terminal)
self.line_breaks = line_breaks

# Check if ANSI escape characters are enabled (suitable for iteractive
Expand Down Expand Up @@ -122,7 +121,7 @@ def finish(self, *args, **kwargs): # pragma: no cover

class ResizableMixin(ProgressBarMixinBase):

def __init__(self, term_width=None, **kwargs):
def __init__(self, term_width: int | None = None, **kwargs):
ProgressBarMixinBase.__init__(self, **kwargs)

self.signal_set = False
Expand Down Expand Up @@ -156,7 +155,8 @@ def finish(self): # pragma: no cover

class StdRedirectMixin(DefaultFdMixin):

def __init__(self, redirect_stderr=False, redirect_stdout=False, **kwargs):
def __init__(self, redirect_stderr: bool = False,
redirect_stdout: bool = False, **kwargs):
DefaultFdMixin.__init__(self, **kwargs)
self.redirect_stderr = redirect_stderr
self.redirect_stdout = redirect_stdout
Expand All @@ -179,7 +179,7 @@ def start(self, *args, **kwargs):
utils.streams.start_capturing(self)
DefaultFdMixin.start(self, *args, **kwargs)

def update(self, value=None):
def update(self, value: float = None):
if not self.line_breaks and utils.streams.needs_clear():
self.fd.write('\r' + ' ' * self.term_width + '\r')

Expand All @@ -197,7 +197,6 @@ def finish(self, end='\n'):


class ProgressBar(StdRedirectMixin, ResizableMixin, ProgressBarBase):

'''The ProgressBar class which updates and prints the bar.
Args:
Expand Down Expand Up @@ -488,8 +487,8 @@ def data(self):
# The seconds since the bar started
total_seconds_elapsed=total_seconds_elapsed,
# The seconds since the bar started modulo 60
seconds_elapsed=(elapsed.seconds % 60) +
(elapsed.microseconds / 1000000.),
seconds_elapsed=(elapsed.seconds % 60)
+ (elapsed.microseconds / 1000000.),
# The minutes since the bar started modulo 60
minutes_elapsed=(elapsed.seconds / 60) % 60,
# The hours since the bar started modulo 24
Expand Down Expand Up @@ -585,7 +584,7 @@ def _format_widgets(self):
elif isinstance(widget, widgets.AutoWidthWidgetBase):
result.append(widget)
expanding.insert(0, index)
elif isinstance(widget, six.string_types):
elif isinstance(widget, str):
result.append(widget)
width -= self.custom_len(widget)
else:
Expand Down Expand Up @@ -795,6 +794,7 @@ class DataTransferBar(ProgressBar):
This assumes that the values its given are numbers of bytes.
'''

def default_widgets(self):
if self.max_value:
return [
Expand All @@ -813,7 +813,6 @@ def default_widgets(self):


class NullBar(ProgressBar):

'''
Progress bar that does absolutely nothing. Useful for single verbosity
flags
Expand Down
7 changes: 2 additions & 5 deletions progressbar/base.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
# -*- mode: python; coding: utf-8 -*-
from __future__ import absolute_import
import six


class FalseMeta(type):
def __bool__(self): # pragma: no cover
Expand All @@ -13,9 +10,9 @@ def __cmp__(self, other): # pragma: no cover
__nonzero__ = __bool__


class UnknownLength(six.with_metaclass(FalseMeta, object)):
class UnknownLength(metaclass=FalseMeta):
pass


class Undefined(six.with_metaclass(FalseMeta, object)):
class Undefined(metaclass=FalseMeta):
pass
Loading

0 comments on commit fcbf77b

Please sign in to comment.