Fix bare 'except:' to placate errors in new flake8 version.

- fixes E722 errors from latest version of flake8
- requires us to not use 'bare except:' and catch BaseException instead
This commit is contained in:
Todd Gamblin
2017-10-23 16:51:11 +02:00
parent b98fc48273
commit 5449884b2e
17 changed files with 27 additions and 27 deletions

View File

@@ -130,7 +130,7 @@ def groupid_to_group(x):
try:
for line in fileinput.input(filename, inplace=True):
print(re.sub(regex, repl, line.rstrip('\n')))
except:
except BaseException:
# clean up the original file on failure.
shutil.move(backup_filename, filename)
raise

View File

@@ -250,7 +250,7 @@ def ioctl_GWINSZ(fd):
try:
rc = struct.unpack('hh', fcntl.ioctl(
fd, termios.TIOCGWINSZ, '1234'))
except:
except BaseException:
return
return rc
rc = ioctl_GWINSZ(0) or ioctl_GWINSZ(1) or ioctl_GWINSZ(2)
@@ -259,7 +259,7 @@ def ioctl_GWINSZ(fd):
fd = os.open(os.ctermid(), os.O_RDONLY)
rc = ioctl_GWINSZ(fd)
os.close(fd)
except:
except BaseException:
pass
if not rc:
rc = (os.environ.get('LINES', 25), os.environ.get('COLUMNS', 80))

View File

@@ -167,7 +167,7 @@ def colify(elts, **options):
r, c = env_size.split('x')
console_rows, console_cols = int(r), int(c)
tty = True
except:
except BaseException:
pass
# Use only one column if not a tty.

View File

@@ -166,7 +166,7 @@ def _file_descriptors_work(*streams):
for stream in streams:
stream.fileno()
return True
except:
except BaseException:
return False
@@ -310,7 +310,7 @@ def __enter__(self):
# need to pass this b/c multiprocessing closes stdin in child.
try:
input_stream = os.fdopen(os.dup(sys.stdin.fileno()))
except:
except BaseException:
input_stream = None # just don't forward input if this fails
self.process = multiprocessing.Process(
@@ -483,7 +483,7 @@ def _writer_daemon(self, stdin):
force_echo = True
if xoff in controls:
force_echo = False
except:
except BaseException:
tty.error("Exception occurred in writer daemon!")
traceback.print_exc()

View File

@@ -567,7 +567,7 @@ def child_process(child_pipe, input_stream):
tty.msg(e.message)
child_pipe.send(None)
except:
except BaseException:
# catch ANYTHING that goes wrong in the child process
exc_type, exc, tb = sys.exc_info()

View File

@@ -34,7 +34,7 @@
from llnl.util.filesystem import mkdirp
from spack.repository import Repo
from spack.spec import Spec
from spack.util.executable import which
from spack.util.executable import which, ProcessError
from spack.util.naming import mod_to_class
from spack.util.naming import simplify_name, valid_fully_qualified_module_name
from spack.url import UndetectableNameError, UndetectableVersionError
@@ -471,14 +471,14 @@ def __call__(self, stage, url):
try:
unzip = which('unzip')
output = unzip('-lq', stage.archive_file, output=str)
except:
except ProcessError:
output = ''
else:
try:
tar = which('tar')
output = tar('--exclude=*/*/*', '-tf',
stage.archive_file, output=str)
except:
except ProcessError:
output = ''
lines = output.split('\n')

View File

@@ -286,7 +286,7 @@ def wrapper(self, *args, ** kwargs):
message='Unexpected exception thrown during install',
text=text
)
except:
except BaseException:
# Anything else is also an error
duration = time.time() - start_time
test_case.set_duration(duration)

View File

@@ -491,7 +491,7 @@ def _read_suppress_error():
self._check_ref_counts()
except:
except BaseException:
# If anything explodes, restore old data, skip write.
self._data = old_data
raise
@@ -544,7 +544,7 @@ def _write(self, type, value, traceback):
with open(temp_file, 'w') as f:
self._write_to_file(f)
os.rename(temp_file, self._index_path)
except:
except BaseException:
# Clean up temp file if something goes wrong.
if os.path.exists(temp_file):
os.remove(temp_file)

View File

@@ -970,7 +970,7 @@ def from_list_url(pkg):
except KeyError:
tty.msg("Can not find version %s in url_list" %
pkg.version)
except:
except BaseException:
tty.msg("Could not determine url from list_url.")

View File

@@ -410,8 +410,8 @@ def __call__(self, *argv, **kwargs):
except SystemExit as e:
self.returncode = e.code
except:
self.error = sys.exc_info()[1]
except BaseException as e:
self.error = e
if fail_on_error:
raise

View File

@@ -98,7 +98,7 @@
comm = MPI.COMM_WORLD
if comm.size > 1:
mpi = True
except:
except ImportError:
pass
@@ -234,7 +234,7 @@ def wait(self):
if include:
try:
functions[subcomm.rank](subcomm_barrier())
except:
except BaseException:
# aborting is the best we can do for MPI tests without
# hanging, since we're using MPI barriers. This will fail
# early and it loses the nice pytest output, but at least it

View File

@@ -82,13 +82,13 @@ def get_module_cmd_from_bash(bashopts=''):
try:
find_exec = re.search(r'.*`(.*(:? bash | sh ).*)`.*', module_func)
exec_line = find_exec.group(1)
except:
except BaseException:
try:
# This will fail with nested parentheses. TODO: expand regex.
find_exec = re.search(r'.*\(([^()]*(:? bash | sh )[^()]*)\).*',
module_func)
exec_line = find_exec.group(1)
except:
except BaseException:
raise ModuleError('get_module_cmd cannot '
'determine the module command from bash')