Skip to content

Commit

Permalink
fix some codacy issues
Browse files Browse the repository at this point in the history
  • Loading branch information
casperdcl committed Feb 17, 2021
1 parent ce08722 commit 16ef703
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 19 deletions.
4 changes: 2 additions & 2 deletions .meta/mksnap.py
Expand Up @@ -5,7 +5,7 @@
import sys
from io import open as io_open
from os import path
from subprocess import check_output
from subprocess import check_output # nosec

sys.path.insert(1, path.dirname(path.dirname(__file__)))
import tqdm # NOQA
Expand Down Expand Up @@ -65,7 +65,7 @@
command: bin/tqdm
completer: completion.sh
""".format(version=tqdm.__version__, commit=check_output([
'git', 'describe', '--always']).decode('U8').strip())
'git', 'describe', '--always']).decode('U8').strip()) # nosec
fname = path.join(path.dirname(src_dir), 'snapcraft.yaml')

if __name__ == "__main__":
Expand Down
6 changes: 3 additions & 3 deletions examples/7zx.py
Expand Up @@ -25,7 +25,7 @@
import os
import pty
import re
import subprocess
import subprocess # nosec

from argopt import argopt

Expand All @@ -51,7 +51,7 @@ def main():
# Get compressed sizes
zips = {}
for fn in args.zipfiles:
info = subprocess.check_output(["7z", "l", fn]).strip()
info = subprocess.check_output(["7z", "l", fn]).strip() # nosec
finfo = RE_SCN.findall(info) # size|compressed|name

# builtin test: last line should be total sizes
Expand Down Expand Up @@ -81,7 +81,7 @@ def main():
cmd7zx + [fn],
bufsize=1,
stdout=md, # subprocess.PIPE,
stderr=subprocess.STDOUT)
stderr=subprocess.STDOUT) # nosec
os.close(sd)
with io.open(md, mode="rU", buffering=1) as m:
with tqdm(total=sum(fcomp.values()), disable=len(zips) < 2,
Expand Down
2 changes: 1 addition & 1 deletion examples/parallel_bars.py
Expand Up @@ -16,7 +16,7 @@


def progresser(n, auto_position=True, write_safe=False, blocking=True, progress=False):
interval = random() * 0.002 / (NUM_SUBITERS - n + 2)
interval = random() * 0.002 / (NUM_SUBITERS - n + 2) # nosec
total = 5000
text = "#{0}, est. {1:<04.2}s".format(n, interval * total)
for _ in trange(total, desc=text, disable=not progress,
Expand Down
6 changes: 3 additions & 3 deletions examples/tqdm_wget.py
Expand Up @@ -100,12 +100,12 @@ 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( # nosec
eg_link, filename=eg_out, reporthook=t.update_to, data=None)
t.total = t.n

# Even simpler progress by wrapping the output file's `write()`
response = urllib.urlopen(eg_link)
response = urllib.urlopen(eg_link) # nosec
with tqdm.wrapattr(open(eg_out, "wb"), "write",
miniters=1, desc=eg_file,
total=getattr(response, 'length', None)) as fout:
Expand Down
8 changes: 4 additions & 4 deletions tests/tests_main.py
@@ -1,6 +1,6 @@
"""Test CLI usage."""
import logging
import subprocess
import subprocess # nosec
import sys
from functools import wraps
from os import linesep
Expand Down Expand Up @@ -34,11 +34,11 @@ def norm(bytestr):
@mark.slow
def test_pipes():
"""Test command line pipes"""
ls_out = subprocess.check_output(['ls'])
ls = subprocess.Popen(['ls'], stdout=subprocess.PIPE)
ls_out = subprocess.check_output(['ls']) # nosec
ls = subprocess.Popen(['ls'], stdout=subprocess.PIPE) # nosec
res = subprocess.Popen(
[sys.executable, '-c', 'from tqdm.cli import main; main()'],
stdin=ls.stdout, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdin=ls.stdout, stdout=subprocess.PIPE, stderr=subprocess.PIPE) # nosec
out, err = res.communicate()
assert ls.poll() == 0

Expand Down
2 changes: 1 addition & 1 deletion tqdm/auto.py
Expand Up @@ -30,7 +30,7 @@
from .std import tqdm as std_tqdm

if notebook_tqdm != std_tqdm:
class tqdm(notebook_tqdm, asyncio_tqdm):
class tqdm(notebook_tqdm, asyncio_tqdm): # pylint: disable=inconsistent-mro
pass
else:
tqdm = asyncio_tqdm
Expand Down
2 changes: 1 addition & 1 deletion tqdm/cli.py
Expand Up @@ -263,7 +263,7 @@ def cp(src, dst):
stdout_write = stdout.write
fp_write = getattr(fp, 'buffer', fp).write

class stdout(object):
class stdout(object): # pylint: disable=function-redefined
@staticmethod
def write(x):
with tqdm.external_write_mode(file=fp):
Expand Down
8 changes: 4 additions & 4 deletions tqdm/utils.py
Expand Up @@ -3,7 +3,6 @@
"""
import os
import re
import subprocess
import sys
from functools import wraps
from warnings import warn
Expand Down Expand Up @@ -254,7 +253,7 @@ def _screen_shape_windows(fp): # pragma: no cover
(_bufx, _bufy, _curx, _cury, _wattr, left, top, right, bottom,
_maxx, _maxy) = struct.unpack("hhhhHhhhhhh", csbi.raw)
return right - left, bottom - top # +1
except Exception:
except Exception: # nosec
pass
return None, None

Expand All @@ -263,9 +262,10 @@ def _screen_shape_tput(*_): # pragma: no cover
"""cygwin xterm (windows)"""
try:
import shlex
return [int(subprocess.check_call(shlex.split('tput ' + i))) - 1
from subprocess import check_call # nosec
return [int(check_call(shlex.split('tput ' + i))) - 1
for i in ('cols', 'lines')]
except Exception:
except Exception: # nosec
pass
return None, None

Expand Down

0 comments on commit 16ef703

Please sign in to comment.