From 0bb1eb32f2c002b4b9deb44815192b4299432fa8 Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Mon, 23 Oct 2017 14:20:39 +0200 Subject: 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. --- lib/spack/llnl/util/tty/colify.py | 2 +- lib/spack/spack/cmd/mirror.py | 2 +- lib/spack/spack/fetch_strategy.py | 4 ++-- lib/spack/spack/main.py | 4 ++-- lib/spack/spack/package.py | 4 ++-- lib/spack/spack/patch.py | 3 ++- lib/spack/spack/test/database.py | 7 +++++++ var/spack/repos/builtin/packages/openfoam-com/package.py | 4 ++-- 8 files changed, 19 insertions(+), 11 deletions(-) diff --git a/lib/spack/llnl/util/tty/colify.py b/lib/spack/llnl/util/tty/colify.py index 66e9f7abfb..b04775b4f1 100644 --- a/lib/spack/llnl/util/tty/colify.py +++ b/lib/spack/llnl/util/tty/colify.py @@ -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 diff --git a/lib/spack/spack/cmd/mirror.py b/lib/spack/spack/cmd/mirror.py index 60dd372432..6193c9fa92 100644 --- a/lib/spack/spack/cmd/mirror.py +++ b/lib/spack/spack/cmd/mirror.py @@ -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 diff --git a/lib/spack/spack/fetch_strategy.py b/lib/spack/spack/fetch_strategy.py index dc405f63d8..4ab76c8d2a 100644 --- a/lib/spack/spack/fetch_strategy.py +++ b/lib/spack/spack/fetch_strategy.py @@ -449,7 +449,7 @@ class VCSFetchStrategy(FetchStrategy): # 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.") diff --git a/lib/spack/spack/main.py b/lib/spack/spack/main.py index 142d23d42a..775873df23 100644 --- a/lib/spack/spack/main.py +++ b/lib/spack/spack/main.py @@ -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): diff --git a/lib/spack/spack/package.py b/lib/spack/spack/package.py index c4b8d53fa5..89b3ac9b19 100644 --- a/lib/spack/spack/package.py +++ b/lib/spack/spack/package.py @@ -1878,7 +1878,7 @@ class PackageBase(with_metaclass(PackageMeta, object)): """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) diff --git a/lib/spack/spack/patch.py b/lib/spack/spack/patch.py index 028f98f3a1..fed577771f 100644 --- a/lib/spack/spack/patch.py +++ b/lib/spack/spack/patch.py @@ -187,7 +187,8 @@ class UrlPatch(Patch): # 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)) diff --git a/lib/spack/spack/test/database.py b/lib/spack/spack/test/database.py index 98cc4a214a..a1b2213f18 100644 --- a/lib/spack/spack/test/database.py +++ b/lib/spack/spack/test/database.py @@ -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 diff --git a/var/spack/repos/builtin/packages/openfoam-com/package.py b/var/spack/repos/builtin/packages/openfoam-com/package.py index e32d7a6c10..074fcbc455 100644 --- a/var/spack/repos/builtin/packages/openfoam-com/package.py +++ b/var/spack/repos/builtin/packages/openfoam-com/package.py @@ -673,9 +673,9 @@ class OpenfoamArch(object): 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': -- cgit v1.2.3-60-g2f50