fix bugs found with stricter flake8 rules

- When you don't use wildcards, flake8 will find places where you used an
  undefined name.

- This commit has all the bugfixes resulting from this static check.
This commit is contained in:
Todd Gamblin 2017-10-23 14:20:39 +02:00
parent 7dd79094b0
commit 0bb1eb32f2
8 changed files with 19 additions and 11 deletions

View File

@ -188,7 +188,7 @@ def colify(elts, **options):
elif method == "uniform":
config = config_uniform_cols(elts, console_cols, padding, cols)
else:
raise ValueError("method must be one of: " + allowed_methods)
raise ValueError("method must be either 'variable' or 'uniform'")
cols = config.cols
rows = (len(elts) + cols - 1) // cols

View File

@ -155,7 +155,7 @@ def _read_specs_from_file(filename):
s.package
specs.append(s)
except SpackError as e:
tty.die("Parse error in %s, line %d:" % (args.file, i + 1),
tty.die("Parse error in %s, line %d:" % (filename, i + 1),
">>> " + string, str(e))
return specs

View File

@ -449,7 +449,7 @@ def __init__(self, name, *rev_types, **kwargs):
# Ensure that there's only one of the rev_types
if sum(k in kwargs for k in rev_types) > 1:
raise FetchStrategyError(
raise ValueError(
"Supply only one of %s to fetch with %s" % (
comma_or(rev_types), name
))
@ -969,7 +969,7 @@ def from_list_url(pkg):
return URLFetchStrategy(url=url_from_list, digest=digest)
except KeyError:
tty.msg("Can not find version %s in url_list" %
self.version)
pkg.version)
except:
tty.msg("Could not determine url from list_url.")

View File

@ -93,8 +93,8 @@ def set_working_dir():
try:
spack.spack_working_dir = os.getcwd()
except OSError:
os.chdir(spack_prefix)
spack.spack_working_dir = spack_prefix
os.chdir(spack.spack_prefix)
spack.spack_working_dir = spack.spack_prefix
def add_all_commands(parser):

View File

@ -1878,7 +1878,7 @@ def fetch_remote_versions(self):
"""Try to find remote versions of this package using the
list_url and any other URLs described in the package file."""
if not self.all_urls:
raise VersionFetchError(self.__class__)
raise spack.util.web.VersionFetchError(self.__class__)
try:
return spack.util.web.find_versions_of_archive(
@ -2022,7 +2022,7 @@ def dump_packages(spec, path):
source_repo = spack.repository.Repo(source_repo_root)
source_pkg_dir = source_repo.dirname_for_package_name(
node.name)
except RepoError:
except spack.repository.RepoError:
tty.warn("Warning: Couldn't copy in provenance for %s" %
node.name)

View File

@ -187,7 +187,8 @@ def apply(self, stage):
# for a compressed archive, Need to check the patch sha256 again
# and the patch is in a directory, not in the same place
if self.archive_sha256:
if not Checker(self.sha256).check(self.path):
checker = Checker(self.sha256)
if not checker.check(self.path):
raise fs.ChecksumError(
"sha256 checksum failed for %s" % self.path,
"Expected %s but got %s" % (self.sha256, checker.sum))

View File

@ -105,6 +105,13 @@ def _check_db_sanity(install_db):
_check_merkleiness()
def _mock_install(spec):
s = spack.spec.Spec(spec)
s.concretize()
pkg = spack.repo.get(s)
pkg.do_install(fake=True)
def _mock_remove(spec):
specs = spack.store.db.query(spec)
assert len(specs) == 1

View File

@ -673,9 +673,9 @@ def __init__(self, spec, **kwargs):
platform += 'ia64'
elif target == 'armv7l':
platform += 'ARM7'
elif target == ppc64:
elif target == 'ppc64':
platform += 'PPC64'
elif target == ppc64le:
elif target == 'ppc64le':
platform += 'PPC64le'
elif platform == 'darwin':
if target == 'x86_64':