From 2b51980904933f8275e9a60f164a0bc6b2eda070 Mon Sep 17 00:00:00 2001 From: "Adam J. Stewart" Date: Sat, 27 Jan 2024 16:15:35 +0100 Subject: [PATCH] Apply black 2024 style to Spack (#42317) --- .github/workflows/style/requirements.txt | 2 +- lib/spack/spack/bootstrap/environment.py | 2 +- lib/spack/spack/build_systems/intel.py | 2 +- lib/spack/spack/caches.py | 12 +++--- lib/spack/spack/ci_needs_workaround.py | 4 +- lib/spack/spack/cmd/list.py | 8 ++-- lib/spack/spack/concretize.py | 1 - lib/spack/spack/fetch_strategy.py | 3 -- lib/spack/spack/filesystem_view.py | 6 +-- lib/spack/spack/stage.py | 8 ++-- lib/spack/spack/test/cmd/url.py | 10 ++--- lib/spack/spack/test/cmd_extensions.py | 6 +-- lib/spack/spack/test/compilers/detection.py | 2 +- lib/spack/spack/test/database.py | 40 ++++++------------- lib/spack/spack/test/stage.py | 18 +++------ lib/spack/spack/test/util/archive.py | 4 +- .../repos/builtin/packages/arborx/package.py | 8 ++-- .../repos/builtin/packages/bricks/package.py | 1 - .../builtin/packages/dla-future/package.py | 8 ++-- .../builtin/packages/elbencho/package.py | 1 - .../repos/builtin/packages/llvm/package.py | 6 +-- .../repos/builtin/packages/mpip/package.py | 1 - .../repos/builtin/packages/mumps/package.py | 28 +++++++------ .../repos/builtin/packages/npb/package.py | 2 +- .../repos/builtin/packages/openvdb/package.py | 1 - .../builtin/packages/trilinos/package.py | 8 ++-- 26 files changed, 85 insertions(+), 107 deletions(-) diff --git a/.github/workflows/style/requirements.txt b/.github/workflows/style/requirements.txt index d662c32fb0..a7a7ad9ac2 100644 --- a/.github/workflows/style/requirements.txt +++ b/.github/workflows/style/requirements.txt @@ -1,4 +1,4 @@ -black==23.12.1 +black==24.1.0 clingo==5.6.2 flake8==7.0.0 isort==5.13.2 diff --git a/lib/spack/spack/bootstrap/environment.py b/lib/spack/spack/bootstrap/environment.py index 1f8fbe8097..f1af8990e8 100644 --- a/lib/spack/spack/bootstrap/environment.py +++ b/lib/spack/spack/bootstrap/environment.py @@ -146,7 +146,7 @@ def mypy_root_spec() -> str: def black_root_spec() -> str: """Return the root spec used to bootstrap black""" - return _root_spec("py-black@:23.1.0") + return _root_spec("py-black@:24.1.0") def flake8_root_spec() -> str: diff --git a/lib/spack/spack/build_systems/intel.py b/lib/spack/spack/build_systems/intel.py index 0dfe4ede26..1a6e0b7acb 100644 --- a/lib/spack/spack/build_systems/intel.py +++ b/lib/spack/spack/build_systems/intel.py @@ -218,7 +218,7 @@ def pset_components(self): "+inspector": " intel-inspector", "+itac": " intel-itac intel-ta intel-tc" " intel-trace-analyzer intel-trace-collector", # Trace Analyzer and Collector - "+vtune": " intel-vtune" + "+vtune": " intel-vtune", # VTune, ..-profiler since 2020, ..-amplifier before }.items(): if variant in self.spec: diff --git a/lib/spack/spack/caches.py b/lib/spack/spack/caches.py index 81a16ea5d8..19c736748e 100644 --- a/lib/spack/spack/caches.py +++ b/lib/spack/spack/caches.py @@ -35,9 +35,9 @@ def _misc_cache(): #: Spack's cache for small data -MISC_CACHE: Union[ - spack.util.file_cache.FileCache, llnl.util.lang.Singleton -] = llnl.util.lang.Singleton(_misc_cache) +MISC_CACHE: Union[spack.util.file_cache.FileCache, llnl.util.lang.Singleton] = ( + llnl.util.lang.Singleton(_misc_cache) +) def fetch_cache_location(): @@ -91,6 +91,6 @@ def symlink(self, mirror_ref): #: Spack's local cache for downloaded source archives -FETCH_CACHE: Union[ - spack.fetch_strategy.FsCache, llnl.util.lang.Singleton -] = llnl.util.lang.Singleton(_fetch_cache) +FETCH_CACHE: Union[spack.fetch_strategy.FsCache, llnl.util.lang.Singleton] = ( + llnl.util.lang.Singleton(_fetch_cache) +) diff --git a/lib/spack/spack/ci_needs_workaround.py b/lib/spack/spack/ci_needs_workaround.py index e026b5c4fd..b89de48f8f 100644 --- a/lib/spack/spack/ci_needs_workaround.py +++ b/lib/spack/spack/ci_needs_workaround.py @@ -7,9 +7,7 @@ get_job_name = lambda needs_entry: ( needs_entry.get("job") if (isinstance(needs_entry, collections.abc.Mapping) and needs_entry.get("artifacts", True)) - else needs_entry - if isinstance(needs_entry, str) - else None + else needs_entry if isinstance(needs_entry, str) else None ) diff --git a/lib/spack/spack/cmd/list.py b/lib/spack/spack/cmd/list.py index eb34e38841..d20621d324 100644 --- a/lib/spack/spack/cmd/list.py +++ b/lib/spack/spack/cmd/list.py @@ -292,9 +292,11 @@ def head(n, span_id, title, anchor=None): out.write("
\n") out.write( ", ".join( - d - if d not in pkg_names - else '%s' % (d, d) + ( + d + if d not in pkg_names + else '%s' % (d, d) + ) for d in deps ) ) diff --git a/lib/spack/spack/concretize.py b/lib/spack/spack/concretize.py index bfa3c133b7..86e1eb9735 100644 --- a/lib/spack/spack/concretize.py +++ b/lib/spack/spack/concretize.py @@ -826,7 +826,6 @@ def __init__(self, spec): class InsufficientArchitectureInfoError(spack.error.SpackError): - """Raised when details on architecture cannot be collected from the system""" diff --git a/lib/spack/spack/fetch_strategy.py b/lib/spack/spack/fetch_strategy.py index 93df10c98f..9393a7c78b 100644 --- a/lib/spack/spack/fetch_strategy.py +++ b/lib/spack/spack/fetch_strategy.py @@ -697,7 +697,6 @@ def __str__(self): @fetcher class GitFetchStrategy(VCSFetchStrategy): - """ Fetch strategy that gets source code from a git repository. Use like this in a package: @@ -1089,7 +1088,6 @@ def __str__(self): @fetcher class SvnFetchStrategy(VCSFetchStrategy): - """Fetch strategy that gets source code from a subversion repository. Use like this in a package: @@ -1184,7 +1182,6 @@ def __str__(self): @fetcher class HgFetchStrategy(VCSFetchStrategy): - """ Fetch strategy that gets source code from a Mercurial repository. Use like this in a package: diff --git a/lib/spack/spack/filesystem_view.py b/lib/spack/spack/filesystem_view.py index 6d9e85b9c4..f2868320c9 100644 --- a/lib/spack/spack/filesystem_view.py +++ b/lib/spack/spack/filesystem_view.py @@ -91,9 +91,9 @@ def view_copy(src: str, dst: str, view, spec: Optional[spack.spec.Spec] = None): prefix_to_projection[spack.store.STORE.layout.root] = view._root # This is vestigial code for the *old* location of sbang. - prefix_to_projection[ - "#!/bin/bash {0}/bin/sbang".format(spack.paths.spack_root) - ] = sbang.sbang_shebang_line() + prefix_to_projection["#!/bin/bash {0}/bin/sbang".format(spack.paths.spack_root)] = ( + sbang.sbang_shebang_line() + ) spack.relocate.relocate_text(files=[dst], prefixes=prefix_to_projection) diff --git a/lib/spack/spack/stage.py b/lib/spack/spack/stage.py index 88ad0549cc..b756255bd6 100644 --- a/lib/spack/spack/stage.py +++ b/lib/spack/spack/stage.py @@ -199,9 +199,11 @@ def get_stage_root(): def _mirror_roots(): mirrors = spack.config.get("mirrors") return [ - sup.substitute_path_variables(root) - if root.endswith(os.sep) - else sup.substitute_path_variables(root) + os.sep + ( + sup.substitute_path_variables(root) + if root.endswith(os.sep) + else sup.substitute_path_variables(root) + os.sep + ) for root in mirrors.values() ] diff --git a/lib/spack/spack/test/cmd/url.py b/lib/spack/spack/test/cmd/url.py index 4d970ddd97..cea7b34a94 100644 --- a/lib/spack/spack/test/cmd/url.py +++ b/lib/spack/spack/test/cmd/url.py @@ -98,13 +98,9 @@ def test_url_list(mock_packages): def test_url_summary(mock_packages): """Test the URL summary command.""" # test url_summary, the internal function that does the work - ( - total_urls, - correct_names, - correct_versions, - name_count_dict, - version_count_dict, - ) = url_summary(None) + (total_urls, correct_names, correct_versions, name_count_dict, version_count_dict) = ( + url_summary(None) + ) assert 0 < correct_names <= sum(name_count_dict.values()) <= total_urls assert 0 < correct_versions <= sum(version_count_dict.values()) <= total_urls diff --git a/lib/spack/spack/test/cmd_extensions.py b/lib/spack/spack/test/cmd_extensions.py index 8af8972859..6a4fcc0fad 100644 --- a/lib/spack/spack/test/cmd_extensions.py +++ b/lib/spack/spack/test/cmd_extensions.py @@ -103,9 +103,9 @@ def hello_world_with_module_in_root(extension_creator): @contextlib.contextmanager def _hwwmir(extension_name=None): - with extension_creator( - extension_name - ) if extension_name else extension_creator() as extension: + with ( + extension_creator(extension_name) if extension_name else extension_creator() + ) as extension: # Note that the namespace of the extension is derived from the # fixture. extension.add_command( diff --git a/lib/spack/spack/test/compilers/detection.py b/lib/spack/spack/test/compilers/detection.py index a30d1b8906..07b5269fb7 100644 --- a/lib/spack/spack/test/compilers/detection.py +++ b/lib/spack/spack/test/compilers/detection.py @@ -422,7 +422,7 @@ def test_xl_version_detection(version_str, expected_version): ("pgi", "19.1"), ("pgi", "19.1a"), ("intel", "9.0.0"), - ("intel", "0.0.0-foobar") + ("intel", "0.0.0-foobar"), # ('oneapi', '2021.1'), # ('oneapi', '2021.1-foobar') ], diff --git a/lib/spack/spack/test/database.py b/lib/spack/spack/test/database.py index 299e908a76..e02f549532 100644 --- a/lib/spack/spack/test/database.py +++ b/lib/spack/spack/test/database.py @@ -60,13 +60,9 @@ def test_spec_installed_upstream( upstream_and_downstream_db, mock_custom_repository, config, monkeypatch ): """Test whether Spec.installed_upstream() works.""" - ( - upstream_write_db, - upstream_db, - upstream_layout, - downstream_db, - downstream_layout, - ) = upstream_and_downstream_db + (upstream_write_db, upstream_db, upstream_layout, downstream_db, downstream_layout) = ( + upstream_and_downstream_db + ) # a known installed spec should say that it's installed with spack.repo.use_repositories(mock_custom_repository): @@ -90,13 +86,9 @@ def test_spec_installed_upstream( @pytest.mark.usefixtures("config") def test_installed_upstream(upstream_and_downstream_db, tmpdir): - ( - upstream_write_db, - upstream_db, - upstream_layout, - downstream_db, - downstream_layout, - ) = upstream_and_downstream_db + (upstream_write_db, upstream_db, upstream_layout, downstream_db, downstream_layout) = ( + upstream_and_downstream_db + ) builder = spack.repo.MockRepositoryBuilder(tmpdir.mkdir("mock.repo")) builder.add_package("x") @@ -132,13 +124,9 @@ def test_installed_upstream(upstream_and_downstream_db, tmpdir): @pytest.mark.usefixtures("config") def test_removed_upstream_dep(upstream_and_downstream_db, tmpdir): - ( - upstream_write_db, - upstream_db, - upstream_layout, - downstream_db, - downstream_layout, - ) = upstream_and_downstream_db + (upstream_write_db, upstream_db, upstream_layout, downstream_db, downstream_layout) = ( + upstream_and_downstream_db + ) builder = spack.repo.MockRepositoryBuilder(tmpdir.mkdir("mock.repo")) builder.add_package("z") @@ -168,13 +156,9 @@ def test_add_to_upstream_after_downstream(upstream_and_downstream_db, tmpdir): DB. When a package is recorded as installed in both, the results should refer to the downstream DB. """ - ( - upstream_write_db, - upstream_db, - upstream_layout, - downstream_db, - downstream_layout, - ) = upstream_and_downstream_db + (upstream_write_db, upstream_db, upstream_layout, downstream_db, downstream_layout) = ( + upstream_and_downstream_db + ) builder = spack.repo.MockRepositoryBuilder(tmpdir.mkdir("mock.repo")) builder.add_package("x") diff --git a/lib/spack/spack/test/stage.py b/lib/spack/spack/test/stage.py index f6bd267090..024d195daa 100644 --- a/lib/spack/spack/test/stage.py +++ b/lib/spack/spack/test/stage.py @@ -444,12 +444,9 @@ def test_composite_stage_with_noexpand_resource( @pytest.mark.disable_clean_stage_check def test_composite_stage_with_expand_resource(self, composite_stage_with_expanding_resource): - ( - composite_stage, - root_stage, - resource_stage, - mock_resource, - ) = composite_stage_with_expanding_resource + (composite_stage, root_stage, resource_stage, mock_resource) = ( + composite_stage_with_expanding_resource + ) composite_stage.create() composite_stage.fetch() @@ -474,12 +471,9 @@ def test_composite_stage_with_expand_resource_default_placement( directory. """ - ( - composite_stage, - root_stage, - resource_stage, - mock_resource, - ) = composite_stage_with_expanding_resource + (composite_stage, root_stage, resource_stage, mock_resource) = ( + composite_stage_with_expanding_resource + ) resource_stage.resource.placement = None diff --git a/lib/spack/spack/test/util/archive.py b/lib/spack/spack/test/util/archive.py index 9688f25924..191de25143 100644 --- a/lib/spack/spack/test/util/archive.py +++ b/lib/spack/spack/test/util/archive.py @@ -50,8 +50,8 @@ def test_gzip_compressed_tarball_is_reproducible(tmpdir): # Expected mode for non-dirs is 644 if not executable, 755 if executable. Better to compute # that as we don't know the umask of the user running the test. - expected_mode = ( - lambda name: 0o755 if Path(*name.split("/")).lstat().st_mode & 0o100 else 0o644 + expected_mode = lambda name: ( + 0o755 if Path(*name.split("/")).lstat().st_mode & 0o100 else 0o644 ) # Verify the tarball contents diff --git a/var/spack/repos/builtin/packages/arborx/package.py b/var/spack/repos/builtin/packages/arborx/package.py index 1414a22d7a..f65b6e92b0 100644 --- a/var/spack/repos/builtin/packages/arborx/package.py +++ b/var/spack/repos/builtin/packages/arborx/package.py @@ -144,9 +144,11 @@ def test_run_ctest(self): f"-DCMAKE_CXX_COMPILER={os.environ['CXX']}", self.define( "Kokkos_ROOT", - self.spec["kokkos"].prefix - if "~trilinos" in self.spec - else self.spec["trilinos"].prefix, + ( + self.spec["kokkos"].prefix + if "~trilinos" in self.spec + else self.spec["trilinos"].prefix + ), ), ] cmake = which(self.spec["cmake"].prefix.bin.cmake) diff --git a/var/spack/repos/builtin/packages/bricks/package.py b/var/spack/repos/builtin/packages/bricks/package.py index af1bfa1c04..037802de68 100644 --- a/var/spack/repos/builtin/packages/bricks/package.py +++ b/var/spack/repos/builtin/packages/bricks/package.py @@ -9,7 +9,6 @@ class Bricks(CMakePackage): - """Bricks is a data layout and code generation framework, enabling performance-portable stencil computations across a multitude of architectures.""" diff --git a/var/spack/repos/builtin/packages/dla-future/package.py b/var/spack/repos/builtin/packages/dla-future/package.py index 29007433df..399e462ebb 100644 --- a/var/spack/repos/builtin/packages/dla-future/package.py +++ b/var/spack/repos/builtin/packages/dla-future/package.py @@ -169,9 +169,11 @@ def cmake_args(self): ] elif mkl_provider == "intel-mkl": args += [ - self.define("DLAF_WITH_MKL", True) - if spec.version <= Version("0.3") - else self.define("DLAF_WITH_MKL_LEGACY", True), + ( + self.define("DLAF_WITH_MKL", True) + if spec.version <= Version("0.3") + else self.define("DLAF_WITH_MKL_LEGACY", True) + ), self.define("MKL_LAPACK_TARGET", f"mkl::mkl_intel_32bit_{mkl_threads}_dyn"), ] diff --git a/var/spack/repos/builtin/packages/elbencho/package.py b/var/spack/repos/builtin/packages/elbencho/package.py index bcc0b6fc53..4088b11d28 100644 --- a/var/spack/repos/builtin/packages/elbencho/package.py +++ b/var/spack/repos/builtin/packages/elbencho/package.py @@ -9,7 +9,6 @@ class Elbencho(MakefilePackage): - """ Elbencho storage benchmark """ diff --git a/var/spack/repos/builtin/packages/llvm/package.py b/var/spack/repos/builtin/packages/llvm/package.py index 266922926b..de03939e6d 100644 --- a/var/spack/repos/builtin/packages/llvm/package.py +++ b/var/spack/repos/builtin/packages/llvm/package.py @@ -967,9 +967,9 @@ def cmake_args(self): "openmp", ] runtimes.sort( - key=lambda x: runtimes_order.index(x) - if x in runtimes_order - else len(runtimes_order) + key=lambda x: ( + runtimes_order.index(x) if x in runtimes_order else len(runtimes_order) + ) ) cmake_args.extend( [ diff --git a/var/spack/repos/builtin/packages/mpip/package.py b/var/spack/repos/builtin/packages/mpip/package.py index 1655c48360..c7628f07d6 100644 --- a/var/spack/repos/builtin/packages/mpip/package.py +++ b/var/spack/repos/builtin/packages/mpip/package.py @@ -7,7 +7,6 @@ class Mpip(AutotoolsPackage): - """mpiP: Lightweight, Scalable MPI Profiling""" homepage = "https://software.llnl.gov/mpiP/" diff --git a/var/spack/repos/builtin/packages/mumps/package.py b/var/spack/repos/builtin/packages/mumps/package.py index df81143a25..c048ce55eb 100644 --- a/var/spack/repos/builtin/packages/mumps/package.py +++ b/var/spack/repos/builtin/packages/mumps/package.py @@ -135,16 +135,18 @@ def write_makefile_inc(self): [ "IMETIS = -I%s" % self.spec["parmetis"].prefix.include, ( - "LMETIS = -L%s -l%s -L%s -l%s" - % ( - self.spec["parmetis"].prefix.lib, - "parmetis", - self.spec["metis"].prefix.lib, - "metis", + ( + "LMETIS = -L%s -l%s -L%s -l%s" + % ( + self.spec["parmetis"].prefix.lib, + "parmetis", + self.spec["metis"].prefix.lib, + "metis", + ) ) - ) - if not shared - else "LMETIS =", + if not shared + else "LMETIS =" + ), ] ) @@ -153,9 +155,11 @@ def write_makefile_inc(self): makefile_conf.extend( [ "IMETIS = -I%s" % self.spec["metis"].prefix.include, - ("LMETIS = -L%s -l%s" % (self.spec["metis"].prefix.lib, "metis")) - if not shared - else "LMETIS =", + ( + ("LMETIS = -L%s -l%s" % (self.spec["metis"].prefix.lib, "metis")) + if not shared + else "LMETIS =" + ), ] ) diff --git a/var/spack/repos/builtin/packages/npb/package.py b/var/spack/repos/builtin/packages/npb/package.py index 63275fd3c9..e14f99bbab 100644 --- a/var/spack/repos/builtin/packages/npb/package.py +++ b/var/spack/repos/builtin/packages/npb/package.py @@ -58,7 +58,7 @@ class Npb(MakefilePackage): # ~4X size increase going from one class to the next "D", "E", - "F" # large test problems + "F", # large test problems # ~16X size increase from each of the previous classes ) diff --git a/var/spack/repos/builtin/packages/openvdb/package.py b/var/spack/repos/builtin/packages/openvdb/package.py index 2b8f952ffb..293839704f 100644 --- a/var/spack/repos/builtin/packages/openvdb/package.py +++ b/var/spack/repos/builtin/packages/openvdb/package.py @@ -10,7 +10,6 @@ class Openvdb(CMakePackage): - """OpenVDB - a sparse volume data format.""" homepage = "https://github.com/AcademySoftwareFoundation/openvdb" diff --git a/var/spack/repos/builtin/packages/trilinos/package.py b/var/spack/repos/builtin/packages/trilinos/package.py index b271e4c5ab..da44b38411 100644 --- a/var/spack/repos/builtin/packages/trilinos/package.py +++ b/var/spack/repos/builtin/packages/trilinos/package.py @@ -649,9 +649,11 @@ def define_enable(suffix, value=None): options.append( define( "Trilinos_CXX11_FLAGS", - self.compiler.cxx14_flag - if spec.variants["cxxstd"].value == "14" - else self.compiler.cxx11_flag, + ( + self.compiler.cxx14_flag + if spec.variants["cxxstd"].value == "14" + else self.compiler.cxx11_flag + ), ) )