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:
|
||||
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
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
|
@ -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')
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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.")
|
||||
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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')
|
||||
|
||||
|
|
|
@ -177,6 +177,6 @@ def install(self, spec, prefix):
|
|||
shutil.copy2(filepath, tmppath)
|
||||
os.remove(filepath)
|
||||
os.rename(tmppath, filepath)
|
||||
except:
|
||||
except (IOError, OSError):
|
||||
pass
|
||||
shutil.rmtree(join_path(prefix, "tmp"))
|
||||
|
|
|
@ -184,7 +184,7 @@ def check_install(self, spec):
|
|||
try:
|
||||
check = Executable("./check")
|
||||
output = check(output=str)
|
||||
except:
|
||||
except ProcessError:
|
||||
output = ""
|
||||
success = output == expected
|
||||
if not success:
|
||||
|
|
|
@ -270,7 +270,7 @@ def check_install(self):
|
|||
try:
|
||||
check = Executable('./check')
|
||||
output = check(output=str)
|
||||
except:
|
||||
except ProcessError:
|
||||
output = ""
|
||||
success = output == expected
|
||||
if not success:
|
||||
|
|
|
@ -63,7 +63,7 @@ def edit(self, spec, prefix):
|
|||
for dep in ("blas", "lapack"):
|
||||
try: # in case the dependency does not provide header flags
|
||||
header_flags += " " + spec[dep].headers.cpp_flags
|
||||
except:
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
make_inc.filter("CFLAGS +[+]=", "CFLAGS += " + header_flags + " ")
|
||||
|
|
|
@ -285,7 +285,7 @@ def _save_distutil_vars(self, prefix):
|
|||
Python._DISTUTIL_CACHE_FILENAME)
|
||||
with open(output_filename, 'w') as output_file:
|
||||
sjson.dump(self._distutil_vars, output_file)
|
||||
except:
|
||||
except Exception:
|
||||
tty.warn("Failed to save metadata for distutils. This might "
|
||||
"cause the extensions that are installed with "
|
||||
"distutils to call compilers directly avoiding "
|
||||
|
@ -308,7 +308,7 @@ def _load_distutil_vars(self):
|
|||
if os.path.isfile(input_filename):
|
||||
with open(input_filename) as input_file:
|
||||
self._distutil_vars = sjson.load(input_file)
|
||||
except:
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
if not self._distutil_vars:
|
||||
|
|
Loading…
Reference in a new issue