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:
parent
b98fc48273
commit
5449884b2e
17 changed files with 27 additions and 27 deletions
|
@ -130,7 +130,7 @@ def groupid_to_group(x):
|
||||||
try:
|
try:
|
||||||
for line in fileinput.input(filename, inplace=True):
|
for line in fileinput.input(filename, inplace=True):
|
||||||
print(re.sub(regex, repl, line.rstrip('\n')))
|
print(re.sub(regex, repl, line.rstrip('\n')))
|
||||||
except:
|
except BaseException:
|
||||||
# clean up the original file on failure.
|
# clean up the original file on failure.
|
||||||
shutil.move(backup_filename, filename)
|
shutil.move(backup_filename, filename)
|
||||||
raise
|
raise
|
||||||
|
|
|
@ -250,7 +250,7 @@ def ioctl_GWINSZ(fd):
|
||||||
try:
|
try:
|
||||||
rc = struct.unpack('hh', fcntl.ioctl(
|
rc = struct.unpack('hh', fcntl.ioctl(
|
||||||
fd, termios.TIOCGWINSZ, '1234'))
|
fd, termios.TIOCGWINSZ, '1234'))
|
||||||
except:
|
except BaseException:
|
||||||
return
|
return
|
||||||
return rc
|
return rc
|
||||||
rc = ioctl_GWINSZ(0) or ioctl_GWINSZ(1) or ioctl_GWINSZ(2)
|
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)
|
fd = os.open(os.ctermid(), os.O_RDONLY)
|
||||||
rc = ioctl_GWINSZ(fd)
|
rc = ioctl_GWINSZ(fd)
|
||||||
os.close(fd)
|
os.close(fd)
|
||||||
except:
|
except BaseException:
|
||||||
pass
|
pass
|
||||||
if not rc:
|
if not rc:
|
||||||
rc = (os.environ.get('LINES', 25), os.environ.get('COLUMNS', 80))
|
rc = (os.environ.get('LINES', 25), os.environ.get('COLUMNS', 80))
|
||||||
|
|
|
@ -167,7 +167,7 @@ def colify(elts, **options):
|
||||||
r, c = env_size.split('x')
|
r, c = env_size.split('x')
|
||||||
console_rows, console_cols = int(r), int(c)
|
console_rows, console_cols = int(r), int(c)
|
||||||
tty = True
|
tty = True
|
||||||
except:
|
except BaseException:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# Use only one column if not a tty.
|
# Use only one column if not a tty.
|
||||||
|
|
|
@ -166,7 +166,7 @@ def _file_descriptors_work(*streams):
|
||||||
for stream in streams:
|
for stream in streams:
|
||||||
stream.fileno()
|
stream.fileno()
|
||||||
return True
|
return True
|
||||||
except:
|
except BaseException:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
@ -310,7 +310,7 @@ def __enter__(self):
|
||||||
# need to pass this b/c multiprocessing closes stdin in child.
|
# need to pass this b/c multiprocessing closes stdin in child.
|
||||||
try:
|
try:
|
||||||
input_stream = os.fdopen(os.dup(sys.stdin.fileno()))
|
input_stream = os.fdopen(os.dup(sys.stdin.fileno()))
|
||||||
except:
|
except BaseException:
|
||||||
input_stream = None # just don't forward input if this fails
|
input_stream = None # just don't forward input if this fails
|
||||||
|
|
||||||
self.process = multiprocessing.Process(
|
self.process = multiprocessing.Process(
|
||||||
|
@ -483,7 +483,7 @@ def _writer_daemon(self, stdin):
|
||||||
force_echo = True
|
force_echo = True
|
||||||
if xoff in controls:
|
if xoff in controls:
|
||||||
force_echo = False
|
force_echo = False
|
||||||
except:
|
except BaseException:
|
||||||
tty.error("Exception occurred in writer daemon!")
|
tty.error("Exception occurred in writer daemon!")
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
|
||||||
|
|
|
@ -567,7 +567,7 @@ def child_process(child_pipe, input_stream):
|
||||||
tty.msg(e.message)
|
tty.msg(e.message)
|
||||||
child_pipe.send(None)
|
child_pipe.send(None)
|
||||||
|
|
||||||
except:
|
except BaseException:
|
||||||
# catch ANYTHING that goes wrong in the child process
|
# catch ANYTHING that goes wrong in the child process
|
||||||
exc_type, exc, tb = sys.exc_info()
|
exc_type, exc, tb = sys.exc_info()
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@
|
||||||
from llnl.util.filesystem import mkdirp
|
from llnl.util.filesystem import mkdirp
|
||||||
from spack.repository import Repo
|
from spack.repository import Repo
|
||||||
from spack.spec import Spec
|
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 mod_to_class
|
||||||
from spack.util.naming import simplify_name, valid_fully_qualified_module_name
|
from spack.util.naming import simplify_name, valid_fully_qualified_module_name
|
||||||
from spack.url import UndetectableNameError, UndetectableVersionError
|
from spack.url import UndetectableNameError, UndetectableVersionError
|
||||||
|
@ -471,14 +471,14 @@ def __call__(self, stage, url):
|
||||||
try:
|
try:
|
||||||
unzip = which('unzip')
|
unzip = which('unzip')
|
||||||
output = unzip('-lq', stage.archive_file, output=str)
|
output = unzip('-lq', stage.archive_file, output=str)
|
||||||
except:
|
except ProcessError:
|
||||||
output = ''
|
output = ''
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
tar = which('tar')
|
tar = which('tar')
|
||||||
output = tar('--exclude=*/*/*', '-tf',
|
output = tar('--exclude=*/*/*', '-tf',
|
||||||
stage.archive_file, output=str)
|
stage.archive_file, output=str)
|
||||||
except:
|
except ProcessError:
|
||||||
output = ''
|
output = ''
|
||||||
lines = output.split('\n')
|
lines = output.split('\n')
|
||||||
|
|
||||||
|
|
|
@ -286,7 +286,7 @@ def wrapper(self, *args, ** kwargs):
|
||||||
message='Unexpected exception thrown during install',
|
message='Unexpected exception thrown during install',
|
||||||
text=text
|
text=text
|
||||||
)
|
)
|
||||||
except:
|
except BaseException:
|
||||||
# Anything else is also an error
|
# Anything else is also an error
|
||||||
duration = time.time() - start_time
|
duration = time.time() - start_time
|
||||||
test_case.set_duration(duration)
|
test_case.set_duration(duration)
|
||||||
|
|
|
@ -491,7 +491,7 @@ def _read_suppress_error():
|
||||||
|
|
||||||
self._check_ref_counts()
|
self._check_ref_counts()
|
||||||
|
|
||||||
except:
|
except BaseException:
|
||||||
# If anything explodes, restore old data, skip write.
|
# If anything explodes, restore old data, skip write.
|
||||||
self._data = old_data
|
self._data = old_data
|
||||||
raise
|
raise
|
||||||
|
@ -544,7 +544,7 @@ def _write(self, type, value, traceback):
|
||||||
with open(temp_file, 'w') as f:
|
with open(temp_file, 'w') as f:
|
||||||
self._write_to_file(f)
|
self._write_to_file(f)
|
||||||
os.rename(temp_file, self._index_path)
|
os.rename(temp_file, self._index_path)
|
||||||
except:
|
except BaseException:
|
||||||
# Clean up temp file if something goes wrong.
|
# Clean up temp file if something goes wrong.
|
||||||
if os.path.exists(temp_file):
|
if os.path.exists(temp_file):
|
||||||
os.remove(temp_file)
|
os.remove(temp_file)
|
||||||
|
|
|
@ -970,7 +970,7 @@ def from_list_url(pkg):
|
||||||
except KeyError:
|
except KeyError:
|
||||||
tty.msg("Can not find version %s in url_list" %
|
tty.msg("Can not find version %s in url_list" %
|
||||||
pkg.version)
|
pkg.version)
|
||||||
except:
|
except BaseException:
|
||||||
tty.msg("Could not determine url from list_url.")
|
tty.msg("Could not determine url from list_url.")
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -410,8 +410,8 @@ def __call__(self, *argv, **kwargs):
|
||||||
except SystemExit as e:
|
except SystemExit as e:
|
||||||
self.returncode = e.code
|
self.returncode = e.code
|
||||||
|
|
||||||
except:
|
except BaseException as e:
|
||||||
self.error = sys.exc_info()[1]
|
self.error = e
|
||||||
if fail_on_error:
|
if fail_on_error:
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
|
|
@ -98,7 +98,7 @@
|
||||||
comm = MPI.COMM_WORLD
|
comm = MPI.COMM_WORLD
|
||||||
if comm.size > 1:
|
if comm.size > 1:
|
||||||
mpi = True
|
mpi = True
|
||||||
except:
|
except ImportError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@ -234,7 +234,7 @@ def wait(self):
|
||||||
if include:
|
if include:
|
||||||
try:
|
try:
|
||||||
functions[subcomm.rank](subcomm_barrier())
|
functions[subcomm.rank](subcomm_barrier())
|
||||||
except:
|
except BaseException:
|
||||||
# aborting is the best we can do for MPI tests without
|
# aborting is the best we can do for MPI tests without
|
||||||
# hanging, since we're using MPI barriers. This will fail
|
# hanging, since we're using MPI barriers. This will fail
|
||||||
# early and it loses the nice pytest output, but at least it
|
# early and it loses the nice pytest output, but at least it
|
||||||
|
|
|
@ -82,13 +82,13 @@ def get_module_cmd_from_bash(bashopts=''):
|
||||||
try:
|
try:
|
||||||
find_exec = re.search(r'.*`(.*(:? bash | sh ).*)`.*', module_func)
|
find_exec = re.search(r'.*`(.*(:? bash | sh ).*)`.*', module_func)
|
||||||
exec_line = find_exec.group(1)
|
exec_line = find_exec.group(1)
|
||||||
except:
|
except BaseException:
|
||||||
try:
|
try:
|
||||||
# This will fail with nested parentheses. TODO: expand regex.
|
# This will fail with nested parentheses. TODO: expand regex.
|
||||||
find_exec = re.search(r'.*\(([^()]*(:? bash | sh )[^()]*)\).*',
|
find_exec = re.search(r'.*\(([^()]*(:? bash | sh )[^()]*)\).*',
|
||||||
module_func)
|
module_func)
|
||||||
exec_line = find_exec.group(1)
|
exec_line = find_exec.group(1)
|
||||||
except:
|
except BaseException:
|
||||||
raise ModuleError('get_module_cmd cannot '
|
raise ModuleError('get_module_cmd cannot '
|
||||||
'determine the module command from bash')
|
'determine the module command from bash')
|
||||||
|
|
||||||
|
|
|
@ -177,6 +177,6 @@ def install(self, spec, prefix):
|
||||||
shutil.copy2(filepath, tmppath)
|
shutil.copy2(filepath, tmppath)
|
||||||
os.remove(filepath)
|
os.remove(filepath)
|
||||||
os.rename(tmppath, filepath)
|
os.rename(tmppath, filepath)
|
||||||
except:
|
except (IOError, OSError):
|
||||||
pass
|
pass
|
||||||
shutil.rmtree(join_path(prefix, "tmp"))
|
shutil.rmtree(join_path(prefix, "tmp"))
|
||||||
|
|
|
@ -184,7 +184,7 @@ def check_install(self, spec):
|
||||||
try:
|
try:
|
||||||
check = Executable("./check")
|
check = Executable("./check")
|
||||||
output = check(output=str)
|
output = check(output=str)
|
||||||
except:
|
except ProcessError:
|
||||||
output = ""
|
output = ""
|
||||||
success = output == expected
|
success = output == expected
|
||||||
if not success:
|
if not success:
|
||||||
|
|
|
@ -270,7 +270,7 @@ def check_install(self):
|
||||||
try:
|
try:
|
||||||
check = Executable('./check')
|
check = Executable('./check')
|
||||||
output = check(output=str)
|
output = check(output=str)
|
||||||
except:
|
except ProcessError:
|
||||||
output = ""
|
output = ""
|
||||||
success = output == expected
|
success = output == expected
|
||||||
if not success:
|
if not success:
|
||||||
|
|
|
@ -63,7 +63,7 @@ def edit(self, spec, prefix):
|
||||||
for dep in ("blas", "lapack"):
|
for dep in ("blas", "lapack"):
|
||||||
try: # in case the dependency does not provide header flags
|
try: # in case the dependency does not provide header flags
|
||||||
header_flags += " " + spec[dep].headers.cpp_flags
|
header_flags += " " + spec[dep].headers.cpp_flags
|
||||||
except:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
make_inc.filter("CFLAGS +[+]=", "CFLAGS += " + header_flags + " ")
|
make_inc.filter("CFLAGS +[+]=", "CFLAGS += " + header_flags + " ")
|
||||||
|
|
|
@ -285,7 +285,7 @@ def _save_distutil_vars(self, prefix):
|
||||||
Python._DISTUTIL_CACHE_FILENAME)
|
Python._DISTUTIL_CACHE_FILENAME)
|
||||||
with open(output_filename, 'w') as output_file:
|
with open(output_filename, 'w') as output_file:
|
||||||
sjson.dump(self._distutil_vars, output_file)
|
sjson.dump(self._distutil_vars, output_file)
|
||||||
except:
|
except Exception:
|
||||||
tty.warn("Failed to save metadata for distutils. This might "
|
tty.warn("Failed to save metadata for distutils. This might "
|
||||||
"cause the extensions that are installed with "
|
"cause the extensions that are installed with "
|
||||||
"distutils to call compilers directly avoiding "
|
"distutils to call compilers directly avoiding "
|
||||||
|
@ -308,7 +308,7 @@ def _load_distutil_vars(self):
|
||||||
if os.path.isfile(input_filename):
|
if os.path.isfile(input_filename):
|
||||||
with open(input_filename) as input_file:
|
with open(input_filename) as input_file:
|
||||||
self._distutil_vars = sjson.load(input_file)
|
self._distutil_vars = sjson.load(input_file)
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if not self._distutil_vars:
|
if not self._distutil_vars:
|
||||||
|
|
Loading…
Reference in a new issue