From 806b8aa9664e7e933af5449da3477899c6769e42 Mon Sep 17 00:00:00 2001 From: Massimiliano Culpo Date: Wed, 23 Aug 2023 23:26:30 +0200 Subject: Uppercase global constants in spec.py (#39573) * Uppercase global constants in spec.py Co-authored-by: Bernhard Kaindl --- lib/spack/spack/cmd/__init__.py | 4 +-- lib/spack/spack/cmd/compiler.py | 2 +- lib/spack/spack/cmd/info.py | 4 +-- lib/spack/spack/cmd/solve.py | 2 +- lib/spack/spack/cmd/spec.py | 2 +- lib/spack/spack/directives.py | 2 +- lib/spack/spack/environment/environment.py | 4 +-- lib/spack/spack/filesystem_view.py | 4 +-- lib/spack/spack/spec.py | 52 +++++++++++++++--------------- 9 files changed, 38 insertions(+), 38 deletions(-) diff --git a/lib/spack/spack/cmd/__init__.py b/lib/spack/spack/cmd/__init__.py index 982286fe89..fd5e81fe7a 100644 --- a/lib/spack/spack/cmd/__init__.py +++ b/lib/spack/spack/cmd/__init__.py @@ -342,9 +342,9 @@ def iter_groups(specs, indent, all_headers): print() header = "%s{%s} / %s{%s}" % ( - spack.spec.architecture_color, + spack.spec.ARCHITECTURE_COLOR, architecture if architecture else "no arch", - spack.spec.compiler_color, + spack.spec.COMPILER_COLOR, f"{compiler.display_str}" if compiler else "no compiler", ) diff --git a/lib/spack/spack/cmd/compiler.py b/lib/spack/spack/cmd/compiler.py index 38695e239a..07006afc2c 100644 --- a/lib/spack/spack/cmd/compiler.py +++ b/lib/spack/spack/cmd/compiler.py @@ -185,7 +185,7 @@ def compiler_list(args): os_str = os if target: os_str += "-%s" % target - cname = "%s{%s} %s" % (spack.spec.compiler_color, name, os_str) + cname = "%s{%s} %s" % (spack.spec.COMPILER_COLOR, name, os_str) tty.hline(colorize(cname), char="-") colify(reversed(sorted(c.spec.display_str for c in compilers))) diff --git a/lib/spack/spack/cmd/info.py b/lib/spack/spack/cmd/info.py index 642e7ab741..a4d40d1048 100644 --- a/lib/spack/spack/cmd/info.py +++ b/lib/spack/spack/cmd/info.py @@ -64,11 +64,11 @@ def section_title(s): def version(s): - return spack.spec.version_color + s + plain_format + return spack.spec.VERSION_COLOR + s + plain_format def variant(s): - return spack.spec.enabled_variant_color + s + plain_format + return spack.spec.ENABLED_VARIANT_COLOR + s + plain_format class VariantFormatter: diff --git a/lib/spack/spack/cmd/solve.py b/lib/spack/spack/cmd/solve.py index 9a13dec108..e27687dc21 100644 --- a/lib/spack/spack/cmd/solve.py +++ b/lib/spack/spack/cmd/solve.py @@ -137,7 +137,7 @@ def solve(parser, args): # these are the same options as `spack spec` install_status_fn = spack.spec.Spec.install_status - fmt = spack.spec.display_format + fmt = spack.spec.DISPLAY_FORMAT if args.namespaces: fmt = "{namespace}." + fmt diff --git a/lib/spack/spack/cmd/spec.py b/lib/spack/spack/cmd/spec.py index 05a1a67da6..0abd63ff6a 100644 --- a/lib/spack/spack/cmd/spec.py +++ b/lib/spack/spack/cmd/spec.py @@ -77,7 +77,7 @@ for further documentation regarding the spec syntax, see: def spec(parser, args): install_status_fn = spack.spec.Spec.install_status - fmt = spack.spec.display_format + fmt = spack.spec.DISPLAY_FORMAT if args.namespaces: fmt = "{namespace}." + fmt diff --git a/lib/spack/spack/directives.py b/lib/spack/spack/directives.py index acb2af1a62..d6d7d81298 100644 --- a/lib/spack/spack/directives.py +++ b/lib/spack/spack/directives.py @@ -760,7 +760,7 @@ def variant( when_spec = make_when_spec(when) when_specs = [when_spec] - if not re.match(spack.spec.identifier_re, name): + if not re.match(spack.spec.IDENTIFIER_RE, name): directive = "variant" msg = "Invalid variant name in {0}: '{1}'" raise DirectiveError(directive, msg.format(pkg.name, name)) diff --git a/lib/spack/spack/environment/environment.py b/lib/spack/spack/environment/environment.py index bd2a633980..ea4ac49a3a 100644 --- a/lib/spack/spack/environment/environment.py +++ b/lib/spack/spack/environment/environment.py @@ -2058,7 +2058,7 @@ class Environment: # If multiple root specs match, it is assumed that the abstract # spec will most-succinctly summarize the difference between them # (and the user can enter one of these to disambiguate) - fmt_str = "{hash:7} " + spack.spec.default_format + fmt_str = "{hash:7} " + spack.spec.DEFAULT_FORMAT color = clr.get_color_when() match_strings = [ f"Root spec {abstract.format(color=color)}\n {concrete.format(fmt_str, color=color)}" @@ -2366,7 +2366,7 @@ def display_specs(concretized_specs): def _tree_to_display(spec): return spec.tree( recurse_dependencies=True, - format=spack.spec.display_format, + format=spack.spec.DISPLAY_FORMAT, status_fn=spack.spec.Spec.install_status, hashlen=7, hashes=True, diff --git a/lib/spack/spack/filesystem_view.py b/lib/spack/spack/filesystem_view.py index 4397eedfba..f0e79afd7d 100644 --- a/lib/spack/spack/filesystem_view.py +++ b/lib/spack/spack/filesystem_view.py @@ -590,9 +590,9 @@ class YamlFilesystemView(FilesystemView): print() header = "%s{%s} / %s{%s}" % ( - spack.spec.architecture_color, + spack.spec.ARCHITECTURE_COLOR, architecture, - spack.spec.compiler_color, + spack.spec.COMPILER_COLOR, compiler, ) tty.hline(colorize(header), char="-") diff --git a/lib/spack/spack/spec.py b/lib/spack/spack/spec.py index 60841ed8e2..648cf55fae 100644 --- a/lib/spack/spack/spec.py +++ b/lib/spack/spack/spec.py @@ -118,44 +118,44 @@ __all__ = [ #: Valid pattern for an identifier in Spack -identifier_re = r"\w[\w-]*" +IDENTIFIER_RE = r"\w[\w-]*" -compiler_color = "@g" #: color for highlighting compilers -version_color = "@c" #: color for highlighting versions -architecture_color = "@m" #: color for highlighting architectures -enabled_variant_color = "@B" #: color for highlighting enabled variants -disabled_variant_color = "r" #: color for highlighting disabled varaints -dependency_color = "@." #: color for highlighting dependencies -hash_color = "@K" #: color for highlighting package hashes +COMPILER_COLOR = "@g" #: color for highlighting compilers +VERSION_COLOR = "@c" #: color for highlighting versions +ARCHITECTURE_COLOR = "@m" #: color for highlighting architectures +ENABLED_VARIANT_COLOR = "@B" #: color for highlighting enabled variants +DISABLED_VARIANT_COLOR = "r" #: color for highlighting disabled varaints +DEPENDENCY_COLOR = "@." #: color for highlighting dependencies +HASH_COLOR = "@K" #: color for highlighting package hashes #: This map determines the coloring of specs when using color output. #: We make the fields different colors to enhance readability. #: See llnl.util.tty.color for descriptions of the color codes. -color_formats = { - "%": compiler_color, - "@": version_color, - "=": architecture_color, - "+": enabled_variant_color, - "~": disabled_variant_color, - "^": dependency_color, - "#": hash_color, +COLOR_FORMATS = { + "%": COMPILER_COLOR, + "@": VERSION_COLOR, + "=": ARCHITECTURE_COLOR, + "+": ENABLED_VARIANT_COLOR, + "~": DISABLED_VARIANT_COLOR, + "^": DEPENDENCY_COLOR, + "#": HASH_COLOR, } #: Regex used for splitting by spec field separators. #: These need to be escaped to avoid metacharacters in -#: ``color_formats.keys()``. -_separators = "[\\%s]" % "\\".join(color_formats.keys()) +#: ``COLOR_FORMATS.keys()``. +_SEPARATORS = "[\\%s]" % "\\".join(COLOR_FORMATS.keys()) #: Default format for Spec.format(). This format can be round-tripped, so that: #: Spec(Spec("string").format()) == Spec("string)" -default_format = ( +DEFAULT_FORMAT = ( "{name}{@versions}" "{%compiler.name}{@compiler.versions}{compiler_flags}" "{variants}{arch=architecture}{/abstract_hash}" ) #: Display format, which eliminates extra `@=` in the output, for readability. -display_format = ( +DISPLAY_FORMAT = ( "{name}{@version}" "{%compiler.name}{@compiler.version}{compiler_flags}" "{variants}{arch=architecture}{/abstract_hash}" @@ -187,7 +187,7 @@ class InstallStatus(enum.Enum): def colorize_spec(spec): """Returns a spec colorized according to the colors specified in - color_formats.""" + COLOR_FORMATS.""" class insert_color: def __init__(self): @@ -200,9 +200,9 @@ def colorize_spec(spec): return clr.cescape(sep) self.last = sep - return "%s%s" % (color_formats[sep], clr.cescape(sep)) + return "%s%s" % (COLOR_FORMATS[sep], clr.cescape(sep)) - return clr.colorize(re.sub(_separators, insert_color(), str(spec)) + "@.") + return clr.colorize(re.sub(_SEPARATORS, insert_color(), str(spec)) + "@.") @lang.lazy_lexicographic_ordering @@ -4245,7 +4245,7 @@ class Spec: def colorized(self): return colorize_spec(self) - def format(self, format_string=default_format, **kwargs): + def format(self, format_string=DEFAULT_FORMAT, **kwargs): r"""Prints out particular pieces of a spec, depending on what is in the format string. @@ -4324,7 +4324,7 @@ class Spec: def write(s, c=None): f = clr.cescape(s) if c is not None: - f = color_formats[c] + f + "@." + f = COLOR_FORMATS[c] + f + "@." clr.cwrite(f, stream=out, color=color) def write_attribute(spec, attribute, color): @@ -4523,7 +4523,7 @@ class Spec: status_fn = kwargs.pop("status_fn", False) cover = kwargs.pop("cover", "nodes") indent = kwargs.pop("indent", 0) - fmt = kwargs.pop("format", default_format) + fmt = kwargs.pop("format", DEFAULT_FORMAT) prefix = kwargs.pop("prefix", None) show_types = kwargs.pop("show_types", False) deptypes = kwargs.pop("deptypes", "all") -- cgit v1.2.3-70-g09d2