Skip to content

Commit

Permalink
.gitattributes, .style.yapf
Browse files Browse the repository at this point in the history
  • Loading branch information
casperdcl committed Aug 28, 2017
1 parent 170bf4a commit 69326b7
Show file tree
Hide file tree
Showing 13 changed files with 141 additions and 129 deletions.
12 changes: 12 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[attr]py-file eol=lf
*.py py-file

.git* export-ignore
.mailmap export-ignore
images/ export-ignore
benchmarks/ export-ignore
MANIFEST.in export-ignore
.travis.yml export-ignore
codecov.yml export-ignore
asv.conf.json export-ignore
.style.yapf export-ignore
10 changes: 10 additions & 0 deletions .style.yapf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[style]
allow_multiline_dictionary_keys=True
allow_multiline_lambdas=True
coalesce_brackets=True
column_limit=80
each_dict_entry_on_separate_line=False
i18n_comment=NOQA
indent_dictionary_value=True
space_between_ending_comma_and_closing_bracket=False
split_before_named_assigns=False
3 changes: 1 addition & 2 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ include logo.png
# include images/logo.gif
include Makefile
include README.rst
include RELEASE
include tox.ini

# Test suite
recursive-include tqdm/tests *.py

# Examples/Documentation
recursive-include examples *
recursive-include examples *.py
34 changes: 16 additions & 18 deletions examples/7zx.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
__version__ = "0.2.0"
__license__ = __licence__


RE_SCN = re.compile("([0-9]+)\s+([0-9]+)\s+(.*)$", flags=re.M)


Expand All @@ -55,7 +54,7 @@ def main():
totals = map(int, finfo[-1][:2])
# log.debug(totals)
for s in range(2):
assert(sum(map(int, (inf[s] for inf in finfo[:-1]))) == totals[s])
assert (sum(map(int, (inf[s] for inf in finfo[:-1]))) == totals[s])
fcomp = dict((n, int(c if args['--compressed'] else u))
for (u, c, n) in finfo[:-1])
# log.debug(fcomp)
Expand All @@ -71,10 +70,11 @@ def main():
unit="B", unit_scale=True) as tall:
for fn, fcomp in zips.items():
md, sd = pty.openpty()
ex = subprocess.Popen(cmd7zx + [fn],
bufsize=1,
stdout=md, # subprocess.PIPE,
stderr=subprocess.STDOUT)
ex = subprocess.Popen(
cmd7zx + [fn],
bufsize=1,
stdout=md, # subprocess.PIPE,
stderr=subprocess.STDOUT)
os.close(sd)
with io.open(md, mode="rU", buffering=1) as m:
with tqdm(total=sum(fcomp.values()), disable=len(zips) < 2,
Expand All @@ -91,26 +91,24 @@ def main():
t.update(s)
tall.update(s)
elif l:
if not any(l.startswith(i) for i in
("7-Zip ",
"p7zip Version ",
"Everything is Ok",
"Folders: ",
"Files: ",
"Size: ",
"Compressed: ")):
if not any(
l.startswith(i)
for i in ("7-Zip ", "p7zip Version ",
"Everything is Ok", "Folders: ",
"Files: ", "Size: ",
"Compressed: ")):
if l.startswith("Processing archive: "):
if not args['--silent']:
t.write(t.format_interval(
t.start_t - tall.start_t) + ' ' +
l.lstrip("Processing archive: "))
t.write(
t.format_interval(
t.start_t - tall.start_t) + ' '
+ l.lstrip("Processing archive: "))
else:
t.write(l)
ex.wait()


main.__doc__ = __doc__


if __name__ == "__main__":
main()
1 change: 1 addition & 0 deletions examples/include_no_requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
try:
from tqdm import tqdm
except ImportError:

def tqdm(*args, **kwargs):
if args:
return args[0]
Expand Down
1 change: 0 additions & 1 deletion examples/pandas_progress_apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
# can also groupby:
# df.groupby(0).progress_apply(lambda x: x**2)


# -- Source code for `tqdm_pandas` (really simple!)
# def tqdm_pandas(t):
# from pandas.core.frame import DataFrame
Expand Down
3 changes: 1 addition & 2 deletions examples/simple_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,4 @@
for s in stmts:
print(s.replace('import tqdm\n', ''))
print(timeit(stmt='try:\n\t_range = xrange'
'\nexcept:\n\t_range = range\n' + s, number=1),
'seconds')
'\nexcept:\n\t_range = range\n' + s, number=1), 'seconds')
6 changes: 4 additions & 2 deletions examples/tqdm_wget.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def update_to(b=1, bsize=1, tsize=None):
t.total = tsize
t.update((b - last_b[0]) * bsize)
last_b[0] = b

return update_to


Expand All @@ -65,6 +66,7 @@ class TqdmUpTo(tqdm):
Inspired by [twine#242](https://github.com/pypa/twine/pull/242),
[here](https://github.com/pypa/twine/commit/42e55e06).
"""

def update_to(self, b=1, bsize=1, tsize=None):
"""
b : int, optional
Expand All @@ -90,5 +92,5 @@ def update_to(self, b=1, bsize=1, tsize=None):
# reporthook=my_hook(t), data=None)
with TqdmUpTo(unit='B', unit_scale=True, unit_divisor=1024, miniters=1,
desc=eg_file) as t: # all optional kwargs
urllib.urlretrieve(eg_link, filename=eg_out,
reporthook=t.update_to, data=None)
urllib.urlretrieve(eg_link, filename=eg_out, reporthook=t.update_to,
data=None)
51 changes: 25 additions & 26 deletions tqdm/_tqdm.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,13 @@ def print_status(s):
len_s = len(s)
fp_write('\r' + s + (' ' * max(last_len[0] - len_s, 0)))
last_len[0] = len_s

return print_status

@staticmethod
def format_meter(n, total, elapsed, ncols=None, prefix='',
ascii=False, unit='it', unit_scale=False, rate=None,
bar_format=None, postfix=None, unit_divisor=1000):
def format_meter(n, total, elapsed, ncols=None, prefix='', ascii=False,
unit='it', unit_scale=False, rate=None, bar_format=None,
postfix=None, unit_divisor=1000):
"""
Return a string-based progress bar given some parameters
Expand Down Expand Up @@ -300,8 +301,8 @@ def format_meter(n, total, elapsed, ncols=None, prefix='',
l_bar = (prefix if prefix else '') + \
'{0:3.0f}%|'.format(percentage)
r_bar = '| {0}/{1} [{2}<{3}, {4}{5}]'.format(
n_fmt, total_fmt, elapsed_str, remaining_str, rate_fmt,
', ' + postfix if postfix else '')
n_fmt, total_fmt, elapsed_str, remaining_str, rate_fmt,
', ' + postfix if postfix else '')

if ncols == 0:
return l_bar[:-1] + r_bar[1:]
Expand Down Expand Up @@ -387,8 +388,8 @@ def __new__(cls, *args, **kwargs):
cls._instances = WeakSet()
cls._instances.add(instance)
# Create the monitoring thread
if cls.monitor_interval and (cls.monitor is None or
not cls.monitor.report()):
if cls.monitor_interval and (cls.monitor is None
or not cls.monitor.report()):
cls.monitor = TMonitor(cls, cls.monitor_interval)
# Return the instance
return instance
Expand Down Expand Up @@ -439,8 +440,8 @@ def write(cls, s, file=None, end="\n"):
# Clear instance if in the target output file
# or if write output + tqdm output are both either
# sys.stdout or sys.stderr (because both are mixed in terminal)
if inst.fp == fp or all(f in (sys.stdout, sys.stderr)
for f in (fp, inst.fp)):
if inst.fp == fp or all(
f in (sys.stdout, sys.stderr) for f in (fp, inst.fp)):
inst.clear()
inst_cleared.append(inst)
# Write the message
Expand Down Expand Up @@ -541,6 +542,7 @@ def wrapper(*args, **kwargs):
# Close bar and return pandas calculation result
t.close()
return result

return inner

# Monkeypatch pandas to provide easy methods
Expand All @@ -562,12 +564,11 @@ def wrapper(*args, **kwargs):
GroupBy.progress_transform = inner_generator('transform')

def __init__(self, iterable=None, desc=None, total=None, leave=True,
file=None, ncols=None, mininterval=0.1,
maxinterval=10.0, miniters=None, ascii=None, disable=False,
unit='it', unit_scale=False, dynamic_ncols=False,
smoothing=0.3, bar_format=None, initial=0, position=None,
postfix=None, unit_divisor=1000,
gui=False, **kwargs):
file=None, ncols=None, mininterval=0.1, maxinterval=10.0,
miniters=None, ascii=None, disable=False, unit='it',
unit_scale=False, dynamic_ncols=False, smoothing=0.3,
bar_format=None, initial=0, position=None, postfix=None,
unit_divisor=1000, gui=False, **kwargs):
"""
Parameters
----------
Expand Down Expand Up @@ -680,9 +681,8 @@ def __init__(self, iterable=None, desc=None, total=None, leave=True,
self._instances.remove(self)
raise (TqdmDeprecationWarning("""\
`nested` is deprecated and automated. Use position instead for manual control.
""", fp_write=getattr(file, 'write', sys.stderr.write))
if "nested" in kwargs else
TqdmKeyError("Unknown argument(s): " + str(kwargs)))
""", fp_write=getattr(file, 'write', sys.stderr.write)) if "nested" in kwargs
else TqdmKeyError("Unknown argument(s): " + str(kwargs)))

# Preprocess the arguments
if total is None and iterable is not None:
Expand Down Expand Up @@ -800,14 +800,13 @@ def __del__(self):
self.close()

def __repr__(self):
return self.format_meter(self.n, self.total,
self._time() - self.start_t,
self.dynamic_ncols(self.fp)
if self.dynamic_ncols else self.ncols,
self.desc, self.ascii, self.unit,
self.unit_scale, 1 / self.avg_time
if self.avg_time else None, self.bar_format,
self.postfix)
return self.format_meter(
self.n, self.total, self._time() - self.start_t,
self.dynamic_ncols(self.fp)
if self.dynamic_ncols else self.ncols, self.desc, self.ascii,
self.unit, self.unit_scale,
1 / self.avg_time if self.avg_time else None,
self.bar_format, self.postfix)

def __lt__(self, other):
return self.pos < other.pos
Expand Down
6 changes: 2 additions & 4 deletions tqdm/tests/tests_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@ def _sh(*cmd, **kwargs):
def test_main():
"""Test command line pipes"""
ls_out = _sh('ls').replace('\r\n', '\n')
ls = subprocess.Popen(('ls'),
stdout=subprocess.PIPE,
ls = subprocess.Popen(('ls'), stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
res = _sh(sys.executable, '-c', 'from tqdm import main; main()',
stdin=ls.stdout,
stderr=subprocess.STDOUT)
stdin=ls.stdout, stderr=subprocess.STDOUT)
ls.wait()

# actual test:
Expand Down
13 changes: 5 additions & 8 deletions tqdm/tests/tests_pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ def test_pandas_groupby_apply():
df = pd.DataFrame(randint(0, 50, (500, 3)))
df.groupby(0).progress_apply(lambda x: None)

dfs = pd.DataFrame(randint(0, 50, (500, 3)),
columns=list('abc'))
dfs = pd.DataFrame(randint(0, 50, (500, 3)), columns=list('abc'))
dfs.groupby(['a']).progress_apply(lambda x: None)

our_file.seek(0)
Expand Down Expand Up @@ -48,8 +47,7 @@ def test_pandas_apply():
df = pd.DataFrame(randint(0, 50, (500, 3)))
df.progress_apply(lambda x: None)

dfs = pd.DataFrame(randint(0, 50, (500, 3)),
columns=list('abc'))
dfs = pd.DataFrame(randint(0, 50, (500, 3)), columns=list('abc'))
dfs.a.progress_apply(lambda x: None)

our_file.seek(0)
Expand All @@ -71,8 +69,7 @@ def test_pandas_map():

with closing(StringIO()) as our_file:
tqdm.pandas(file=our_file, leave=True, ascii=True)
dfs = pd.DataFrame(randint(0, 50, (500, 3)),
columns=list('abc'))
dfs = pd.DataFrame(randint(0, 50, (500, 3)), columns=list('abc'))
dfs.a.progress_map(lambda x: None)

if our_file.getvalue().count('100%') < 1:
Expand All @@ -99,8 +96,8 @@ def test_pandas_leave():
exres = '100%|##########| 101/101'
if exres not in our_file.read():
our_file.seek(0)
raise AssertionError("\nExpected:\n{0}\nIn:{1}\n".format(
exres, our_file.read()))
raise AssertionError(
"\nExpected:\n{0}\nIn:{1}\n".format(exres, our_file.read()))


@with_setup(pretest, posttest)
Expand Down
Loading

0 comments on commit 69326b7

Please sign in to comment.