Apply black 2024 style to Spack (#42317)

This commit is contained in:
Adam J. Stewart 2024-01-27 16:15:35 +01:00 committed by GitHub
parent 1865e228c4
commit 2b51980904
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
26 changed files with 85 additions and 107 deletions

View file

@ -1,4 +1,4 @@
black==23.12.1 black==24.1.0
clingo==5.6.2 clingo==5.6.2
flake8==7.0.0 flake8==7.0.0
isort==5.13.2 isort==5.13.2

View file

@ -146,7 +146,7 @@ def mypy_root_spec() -> str:
def black_root_spec() -> str: def black_root_spec() -> str:
"""Return the root spec used to bootstrap black""" """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: def flake8_root_spec() -> str:

View file

@ -218,7 +218,7 @@ def pset_components(self):
"+inspector": " intel-inspector", "+inspector": " intel-inspector",
"+itac": " intel-itac intel-ta intel-tc" " intel-trace-analyzer intel-trace-collector", "+itac": " intel-itac intel-ta intel-tc" " intel-trace-analyzer intel-trace-collector",
# Trace Analyzer and Collector # Trace Analyzer and Collector
"+vtune": " intel-vtune" "+vtune": " intel-vtune",
# VTune, ..-profiler since 2020, ..-amplifier before # VTune, ..-profiler since 2020, ..-amplifier before
}.items(): }.items():
if variant in self.spec: if variant in self.spec:

View file

@ -35,9 +35,9 @@ def _misc_cache():
#: Spack's cache for small data #: Spack's cache for small data
MISC_CACHE: Union[ MISC_CACHE: Union[spack.util.file_cache.FileCache, llnl.util.lang.Singleton] = (
spack.util.file_cache.FileCache, llnl.util.lang.Singleton llnl.util.lang.Singleton(_misc_cache)
] = llnl.util.lang.Singleton(_misc_cache) )
def fetch_cache_location(): def fetch_cache_location():
@ -91,6 +91,6 @@ def symlink(self, mirror_ref):
#: Spack's local cache for downloaded source archives #: Spack's local cache for downloaded source archives
FETCH_CACHE: Union[ FETCH_CACHE: Union[spack.fetch_strategy.FsCache, llnl.util.lang.Singleton] = (
spack.fetch_strategy.FsCache, llnl.util.lang.Singleton llnl.util.lang.Singleton(_fetch_cache)
] = llnl.util.lang.Singleton(_fetch_cache) )

View file

@ -7,9 +7,7 @@
get_job_name = lambda needs_entry: ( get_job_name = lambda needs_entry: (
needs_entry.get("job") needs_entry.get("job")
if (isinstance(needs_entry, collections.abc.Mapping) and needs_entry.get("artifacts", True)) if (isinstance(needs_entry, collections.abc.Mapping) and needs_entry.get("artifacts", True))
else needs_entry else needs_entry if isinstance(needs_entry, str) else None
if isinstance(needs_entry, str)
else None
) )

View file

@ -292,9 +292,11 @@ def head(n, span_id, title, anchor=None):
out.write("<dd>\n") out.write("<dd>\n")
out.write( out.write(
", ".join( ", ".join(
(
d d
if d not in pkg_names if d not in pkg_names
else '<a class="reference internal" href="#%s">%s</a>' % (d, d) else '<a class="reference internal" href="#%s">%s</a>' % (d, d)
)
for d in deps for d in deps
) )
) )

View file

@ -826,7 +826,6 @@ def __init__(self, spec):
class InsufficientArchitectureInfoError(spack.error.SpackError): class InsufficientArchitectureInfoError(spack.error.SpackError):
"""Raised when details on architecture cannot be collected from the """Raised when details on architecture cannot be collected from the
system""" system"""

View file

@ -697,7 +697,6 @@ def __str__(self):
@fetcher @fetcher
class GitFetchStrategy(VCSFetchStrategy): class GitFetchStrategy(VCSFetchStrategy):
""" """
Fetch strategy that gets source code from a git repository. Fetch strategy that gets source code from a git repository.
Use like this in a package: Use like this in a package:
@ -1089,7 +1088,6 @@ def __str__(self):
@fetcher @fetcher
class SvnFetchStrategy(VCSFetchStrategy): class SvnFetchStrategy(VCSFetchStrategy):
"""Fetch strategy that gets source code from a subversion repository. """Fetch strategy that gets source code from a subversion repository.
Use like this in a package: Use like this in a package:
@ -1184,7 +1182,6 @@ def __str__(self):
@fetcher @fetcher
class HgFetchStrategy(VCSFetchStrategy): class HgFetchStrategy(VCSFetchStrategy):
""" """
Fetch strategy that gets source code from a Mercurial repository. Fetch strategy that gets source code from a Mercurial repository.
Use like this in a package: Use like this in a package:

View file

@ -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 prefix_to_projection[spack.store.STORE.layout.root] = view._root
# This is vestigial code for the *old* location of sbang. # This is vestigial code for the *old* location of sbang.
prefix_to_projection[ prefix_to_projection["#!/bin/bash {0}/bin/sbang".format(spack.paths.spack_root)] = (
"#!/bin/bash {0}/bin/sbang".format(spack.paths.spack_root) sbang.sbang_shebang_line()
] = sbang.sbang_shebang_line() )
spack.relocate.relocate_text(files=[dst], prefixes=prefix_to_projection) spack.relocate.relocate_text(files=[dst], prefixes=prefix_to_projection)

View file

@ -199,9 +199,11 @@ def get_stage_root():
def _mirror_roots(): def _mirror_roots():
mirrors = spack.config.get("mirrors") mirrors = spack.config.get("mirrors")
return [ return [
(
sup.substitute_path_variables(root) sup.substitute_path_variables(root)
if root.endswith(os.sep) if root.endswith(os.sep)
else sup.substitute_path_variables(root) + os.sep else sup.substitute_path_variables(root) + os.sep
)
for root in mirrors.values() for root in mirrors.values()
] ]

View file

@ -98,13 +98,9 @@ def test_url_list(mock_packages):
def test_url_summary(mock_packages): def test_url_summary(mock_packages):
"""Test the URL summary command.""" """Test the URL summary command."""
# test url_summary, the internal function that does the work # test url_summary, the internal function that does the work
( (total_urls, correct_names, correct_versions, name_count_dict, version_count_dict) = (
total_urls, url_summary(None)
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_names <= sum(name_count_dict.values()) <= total_urls
assert 0 < correct_versions <= sum(version_count_dict.values()) <= total_urls assert 0 < correct_versions <= sum(version_count_dict.values()) <= total_urls

View file

@ -103,9 +103,9 @@ def hello_world_with_module_in_root(extension_creator):
@contextlib.contextmanager @contextlib.contextmanager
def _hwwmir(extension_name=None): def _hwwmir(extension_name=None):
with extension_creator( with (
extension_name extension_creator(extension_name) if extension_name else extension_creator()
) if extension_name else extension_creator() as extension: ) as extension:
# Note that the namespace of the extension is derived from the # Note that the namespace of the extension is derived from the
# fixture. # fixture.
extension.add_command( extension.add_command(

View file

@ -422,7 +422,7 @@ def test_xl_version_detection(version_str, expected_version):
("pgi", "19.1"), ("pgi", "19.1"),
("pgi", "19.1a"), ("pgi", "19.1a"),
("intel", "9.0.0"), ("intel", "9.0.0"),
("intel", "0.0.0-foobar") ("intel", "0.0.0-foobar"),
# ('oneapi', '2021.1'), # ('oneapi', '2021.1'),
# ('oneapi', '2021.1-foobar') # ('oneapi', '2021.1-foobar')
], ],

View file

@ -60,13 +60,9 @@ def test_spec_installed_upstream(
upstream_and_downstream_db, mock_custom_repository, config, monkeypatch upstream_and_downstream_db, mock_custom_repository, config, monkeypatch
): ):
"""Test whether Spec.installed_upstream() works.""" """Test whether Spec.installed_upstream() works."""
( (upstream_write_db, upstream_db, upstream_layout, downstream_db, downstream_layout) = (
upstream_write_db, upstream_and_downstream_db
upstream_db, )
upstream_layout,
downstream_db,
downstream_layout,
) = upstream_and_downstream_db
# a known installed spec should say that it's installed # a known installed spec should say that it's installed
with spack.repo.use_repositories(mock_custom_repository): with spack.repo.use_repositories(mock_custom_repository):
@ -90,13 +86,9 @@ def test_spec_installed_upstream(
@pytest.mark.usefixtures("config") @pytest.mark.usefixtures("config")
def test_installed_upstream(upstream_and_downstream_db, tmpdir): def test_installed_upstream(upstream_and_downstream_db, tmpdir):
( (upstream_write_db, upstream_db, upstream_layout, downstream_db, downstream_layout) = (
upstream_write_db, upstream_and_downstream_db
upstream_db, )
upstream_layout,
downstream_db,
downstream_layout,
) = upstream_and_downstream_db
builder = spack.repo.MockRepositoryBuilder(tmpdir.mkdir("mock.repo")) builder = spack.repo.MockRepositoryBuilder(tmpdir.mkdir("mock.repo"))
builder.add_package("x") builder.add_package("x")
@ -132,13 +124,9 @@ def test_installed_upstream(upstream_and_downstream_db, tmpdir):
@pytest.mark.usefixtures("config") @pytest.mark.usefixtures("config")
def test_removed_upstream_dep(upstream_and_downstream_db, tmpdir): def test_removed_upstream_dep(upstream_and_downstream_db, tmpdir):
( (upstream_write_db, upstream_db, upstream_layout, downstream_db, downstream_layout) = (
upstream_write_db, upstream_and_downstream_db
upstream_db, )
upstream_layout,
downstream_db,
downstream_layout,
) = upstream_and_downstream_db
builder = spack.repo.MockRepositoryBuilder(tmpdir.mkdir("mock.repo")) builder = spack.repo.MockRepositoryBuilder(tmpdir.mkdir("mock.repo"))
builder.add_package("z") 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 DB. When a package is recorded as installed in both, the results should
refer to the downstream DB. refer to the downstream DB.
""" """
( (upstream_write_db, upstream_db, upstream_layout, downstream_db, downstream_layout) = (
upstream_write_db, upstream_and_downstream_db
upstream_db, )
upstream_layout,
downstream_db,
downstream_layout,
) = upstream_and_downstream_db
builder = spack.repo.MockRepositoryBuilder(tmpdir.mkdir("mock.repo")) builder = spack.repo.MockRepositoryBuilder(tmpdir.mkdir("mock.repo"))
builder.add_package("x") builder.add_package("x")

View file

@ -444,12 +444,9 @@ def test_composite_stage_with_noexpand_resource(
@pytest.mark.disable_clean_stage_check @pytest.mark.disable_clean_stage_check
def test_composite_stage_with_expand_resource(self, composite_stage_with_expanding_resource): def test_composite_stage_with_expand_resource(self, composite_stage_with_expanding_resource):
( (composite_stage, root_stage, resource_stage, mock_resource) = (
composite_stage, composite_stage_with_expanding_resource
root_stage, )
resource_stage,
mock_resource,
) = composite_stage_with_expanding_resource
composite_stage.create() composite_stage.create()
composite_stage.fetch() composite_stage.fetch()
@ -474,12 +471,9 @@ def test_composite_stage_with_expand_resource_default_placement(
directory. directory.
""" """
( (composite_stage, root_stage, resource_stage, mock_resource) = (
composite_stage, composite_stage_with_expanding_resource
root_stage, )
resource_stage,
mock_resource,
) = composite_stage_with_expanding_resource
resource_stage.resource.placement = None resource_stage.resource.placement = None

View file

@ -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 # 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. # that as we don't know the umask of the user running the test.
expected_mode = ( expected_mode = lambda name: (
lambda name: 0o755 if Path(*name.split("/")).lstat().st_mode & 0o100 else 0o644 0o755 if Path(*name.split("/")).lstat().st_mode & 0o100 else 0o644
) )
# Verify the tarball contents # Verify the tarball contents

View file

@ -144,9 +144,11 @@ def test_run_ctest(self):
f"-DCMAKE_CXX_COMPILER={os.environ['CXX']}", f"-DCMAKE_CXX_COMPILER={os.environ['CXX']}",
self.define( self.define(
"Kokkos_ROOT", "Kokkos_ROOT",
(
self.spec["kokkos"].prefix self.spec["kokkos"].prefix
if "~trilinos" in self.spec if "~trilinos" in self.spec
else self.spec["trilinos"].prefix, else self.spec["trilinos"].prefix
),
), ),
] ]
cmake = which(self.spec["cmake"].prefix.bin.cmake) cmake = which(self.spec["cmake"].prefix.bin.cmake)

View file

@ -9,7 +9,6 @@
class Bricks(CMakePackage): class Bricks(CMakePackage):
"""Bricks is a data layout and code generation framework, """Bricks is a data layout and code generation framework,
enabling performance-portable stencil computations across enabling performance-portable stencil computations across
a multitude of architectures.""" a multitude of architectures."""

View file

@ -169,9 +169,11 @@ def cmake_args(self):
] ]
elif mkl_provider == "intel-mkl": elif mkl_provider == "intel-mkl":
args += [ args += [
(
self.define("DLAF_WITH_MKL", True) self.define("DLAF_WITH_MKL", True)
if spec.version <= Version("0.3") if spec.version <= Version("0.3")
else self.define("DLAF_WITH_MKL_LEGACY", True), else self.define("DLAF_WITH_MKL_LEGACY", True)
),
self.define("MKL_LAPACK_TARGET", f"mkl::mkl_intel_32bit_{mkl_threads}_dyn"), self.define("MKL_LAPACK_TARGET", f"mkl::mkl_intel_32bit_{mkl_threads}_dyn"),
] ]

View file

@ -9,7 +9,6 @@
class Elbencho(MakefilePackage): class Elbencho(MakefilePackage):
""" """
Elbencho storage benchmark Elbencho storage benchmark
""" """

View file

@ -967,9 +967,9 @@ def cmake_args(self):
"openmp", "openmp",
] ]
runtimes.sort( runtimes.sort(
key=lambda x: runtimes_order.index(x) key=lambda x: (
if x in runtimes_order runtimes_order.index(x) if x in runtimes_order else len(runtimes_order)
else len(runtimes_order) )
) )
cmake_args.extend( cmake_args.extend(
[ [

View file

@ -7,7 +7,6 @@
class Mpip(AutotoolsPackage): class Mpip(AutotoolsPackage):
"""mpiP: Lightweight, Scalable MPI Profiling""" """mpiP: Lightweight, Scalable MPI Profiling"""
homepage = "https://software.llnl.gov/mpiP/" homepage = "https://software.llnl.gov/mpiP/"

View file

@ -134,6 +134,7 @@ def write_makefile_inc(self):
makefile_conf.extend( makefile_conf.extend(
[ [
"IMETIS = -I%s" % self.spec["parmetis"].prefix.include, "IMETIS = -I%s" % self.spec["parmetis"].prefix.include,
(
( (
"LMETIS = -L%s -l%s -L%s -l%s" "LMETIS = -L%s -l%s -L%s -l%s"
% ( % (
@ -144,7 +145,8 @@ def write_makefile_inc(self):
) )
) )
if not shared if not shared
else "LMETIS =", else "LMETIS ="
),
] ]
) )
@ -153,9 +155,11 @@ def write_makefile_inc(self):
makefile_conf.extend( makefile_conf.extend(
[ [
"IMETIS = -I%s" % self.spec["metis"].prefix.include, "IMETIS = -I%s" % self.spec["metis"].prefix.include,
(
("LMETIS = -L%s -l%s" % (self.spec["metis"].prefix.lib, "metis")) ("LMETIS = -L%s -l%s" % (self.spec["metis"].prefix.lib, "metis"))
if not shared if not shared
else "LMETIS =", else "LMETIS ="
),
] ]
) )

View file

@ -58,7 +58,7 @@ class Npb(MakefilePackage):
# ~4X size increase going from one class to the next # ~4X size increase going from one class to the next
"D", "D",
"E", "E",
"F" # large test problems "F", # large test problems
# ~16X size increase from each of the previous classes # ~16X size increase from each of the previous classes
) )

View file

@ -10,7 +10,6 @@
class Openvdb(CMakePackage): class Openvdb(CMakePackage):
"""OpenVDB - a sparse volume data format.""" """OpenVDB - a sparse volume data format."""
homepage = "https://github.com/AcademySoftwareFoundation/openvdb" homepage = "https://github.com/AcademySoftwareFoundation/openvdb"

View file

@ -649,9 +649,11 @@ def define_enable(suffix, value=None):
options.append( options.append(
define( define(
"Trilinos_CXX11_FLAGS", "Trilinos_CXX11_FLAGS",
(
self.compiler.cxx14_flag self.compiler.cxx14_flag
if spec.variants["cxxstd"].value == "14" if spec.variants["cxxstd"].value == "14"
else self.compiler.cxx11_flag, else self.compiler.cxx11_flag
),
) )
) )