Uppercase global constants in spec.py (#39573)

* Uppercase global constants in spec.py

Co-authored-by: Bernhard Kaindl <bernhardkaindl7@gmail.com>
This commit is contained in:
Massimiliano Culpo 2023-08-23 23:26:30 +02:00 committed by GitHub
parent 9e5ca525f7
commit 806b8aa966
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 38 additions and 38 deletions

View File

@ -342,9 +342,9 @@ def iter_groups(specs, indent, all_headers):
print() print()
header = "%s{%s} / %s{%s}" % ( header = "%s{%s} / %s{%s}" % (
spack.spec.architecture_color, spack.spec.ARCHITECTURE_COLOR,
architecture if architecture else "no arch", architecture if architecture else "no arch",
spack.spec.compiler_color, spack.spec.COMPILER_COLOR,
f"{compiler.display_str}" if compiler else "no compiler", f"{compiler.display_str}" if compiler else "no compiler",
) )

View File

@ -185,7 +185,7 @@ def compiler_list(args):
os_str = os os_str = os
if target: if target:
os_str += "-%s" % 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="-") tty.hline(colorize(cname), char="-")
colify(reversed(sorted(c.spec.display_str for c in compilers))) colify(reversed(sorted(c.spec.display_str for c in compilers)))

View File

@ -64,11 +64,11 @@ def section_title(s):
def version(s): def version(s):
return spack.spec.version_color + s + plain_format return spack.spec.VERSION_COLOR + s + plain_format
def variant(s): def variant(s):
return spack.spec.enabled_variant_color + s + plain_format return spack.spec.ENABLED_VARIANT_COLOR + s + plain_format
class VariantFormatter: class VariantFormatter:

View File

@ -137,7 +137,7 @@ def solve(parser, args):
# these are the same options as `spack spec` # these are the same options as `spack spec`
install_status_fn = spack.spec.Spec.install_status install_status_fn = spack.spec.Spec.install_status
fmt = spack.spec.display_format fmt = spack.spec.DISPLAY_FORMAT
if args.namespaces: if args.namespaces:
fmt = "{namespace}." + fmt fmt = "{namespace}." + fmt

View File

@ -77,7 +77,7 @@ def setup_parser(subparser):
def spec(parser, args): def spec(parser, args):
install_status_fn = spack.spec.Spec.install_status install_status_fn = spack.spec.Spec.install_status
fmt = spack.spec.display_format fmt = spack.spec.DISPLAY_FORMAT
if args.namespaces: if args.namespaces:
fmt = "{namespace}." + fmt fmt = "{namespace}." + fmt

View File

@ -760,7 +760,7 @@ def _execute_variant(pkg):
when_spec = make_when_spec(when) when_spec = make_when_spec(when)
when_specs = [when_spec] when_specs = [when_spec]
if not re.match(spack.spec.identifier_re, name): if not re.match(spack.spec.IDENTIFIER_RE, name):
directive = "variant" directive = "variant"
msg = "Invalid variant name in {0}: '{1}'" msg = "Invalid variant name in {0}: '{1}'"
raise DirectiveError(directive, msg.format(pkg.name, name)) raise DirectiveError(directive, msg.format(pkg.name, name))

View File

@ -2058,7 +2058,7 @@ def matching_spec(self, spec):
# If multiple root specs match, it is assumed that the abstract # If multiple root specs match, it is assumed that the abstract
# spec will most-succinctly summarize the difference between them # spec will most-succinctly summarize the difference between them
# (and the user can enter one of these to disambiguate) # (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() color = clr.get_color_when()
match_strings = [ match_strings = [
f"Root spec {abstract.format(color=color)}\n {concrete.format(fmt_str, color=color)}" 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): def _tree_to_display(spec):
return spec.tree( return spec.tree(
recurse_dependencies=True, recurse_dependencies=True,
format=spack.spec.display_format, format=spack.spec.DISPLAY_FORMAT,
status_fn=spack.spec.Spec.install_status, status_fn=spack.spec.Spec.install_status,
hashlen=7, hashlen=7,
hashes=True, hashes=True,

View File

@ -590,9 +590,9 @@ def print_status(self, *specs, **kwargs):
print() print()
header = "%s{%s} / %s{%s}" % ( header = "%s{%s} / %s{%s}" % (
spack.spec.architecture_color, spack.spec.ARCHITECTURE_COLOR,
architecture, architecture,
spack.spec.compiler_color, spack.spec.COMPILER_COLOR,
compiler, compiler,
) )
tty.hline(colorize(header), char="-") tty.hline(colorize(header), char="-")

View File

@ -118,44 +118,44 @@
#: Valid pattern for an identifier in Spack #: Valid pattern for an identifier in Spack
identifier_re = r"\w[\w-]*" IDENTIFIER_RE = r"\w[\w-]*"
compiler_color = "@g" #: color for highlighting compilers COMPILER_COLOR = "@g" #: color for highlighting compilers
version_color = "@c" #: color for highlighting versions VERSION_COLOR = "@c" #: color for highlighting versions
architecture_color = "@m" #: color for highlighting architectures ARCHITECTURE_COLOR = "@m" #: color for highlighting architectures
enabled_variant_color = "@B" #: color for highlighting enabled variants ENABLED_VARIANT_COLOR = "@B" #: color for highlighting enabled variants
disabled_variant_color = "r" #: color for highlighting disabled varaints DISABLED_VARIANT_COLOR = "r" #: color for highlighting disabled varaints
dependency_color = "@." #: color for highlighting dependencies DEPENDENCY_COLOR = "@." #: color for highlighting dependencies
hash_color = "@K" #: color for highlighting package hashes HASH_COLOR = "@K" #: color for highlighting package hashes
#: This map determines the coloring of specs when using color output. #: This map determines the coloring of specs when using color output.
#: We make the fields different colors to enhance readability. #: We make the fields different colors to enhance readability.
#: See llnl.util.tty.color for descriptions of the color codes. #: See llnl.util.tty.color for descriptions of the color codes.
color_formats = { COLOR_FORMATS = {
"%": compiler_color, "%": COMPILER_COLOR,
"@": version_color, "@": VERSION_COLOR,
"=": architecture_color, "=": ARCHITECTURE_COLOR,
"+": enabled_variant_color, "+": ENABLED_VARIANT_COLOR,
"~": disabled_variant_color, "~": DISABLED_VARIANT_COLOR,
"^": dependency_color, "^": DEPENDENCY_COLOR,
"#": hash_color, "#": HASH_COLOR,
} }
#: Regex used for splitting by spec field separators. #: Regex used for splitting by spec field separators.
#: These need to be escaped to avoid metacharacters in #: These need to be escaped to avoid metacharacters in
#: ``color_formats.keys()``. #: ``COLOR_FORMATS.keys()``.
_separators = "[\\%s]" % "\\".join(color_formats.keys()) _SEPARATORS = "[\\%s]" % "\\".join(COLOR_FORMATS.keys())
#: Default format for Spec.format(). This format can be round-tripped, so that: #: Default format for Spec.format(). This format can be round-tripped, so that:
#: Spec(Spec("string").format()) == Spec("string)" #: Spec(Spec("string").format()) == Spec("string)"
default_format = ( DEFAULT_FORMAT = (
"{name}{@versions}" "{name}{@versions}"
"{%compiler.name}{@compiler.versions}{compiler_flags}" "{%compiler.name}{@compiler.versions}{compiler_flags}"
"{variants}{arch=architecture}{/abstract_hash}" "{variants}{arch=architecture}{/abstract_hash}"
) )
#: Display format, which eliminates extra `@=` in the output, for readability. #: Display format, which eliminates extra `@=` in the output, for readability.
display_format = ( DISPLAY_FORMAT = (
"{name}{@version}" "{name}{@version}"
"{%compiler.name}{@compiler.version}{compiler_flags}" "{%compiler.name}{@compiler.version}{compiler_flags}"
"{variants}{arch=architecture}{/abstract_hash}" "{variants}{arch=architecture}{/abstract_hash}"
@ -187,7 +187,7 @@ class InstallStatus(enum.Enum):
def colorize_spec(spec): def colorize_spec(spec):
"""Returns a spec colorized according to the colors specified in """Returns a spec colorized according to the colors specified in
color_formats.""" COLOR_FORMATS."""
class insert_color: class insert_color:
def __init__(self): def __init__(self):
@ -200,9 +200,9 @@ def __call__(self, match):
return clr.cescape(sep) return clr.cescape(sep)
self.last = 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 @lang.lazy_lexicographic_ordering
@ -4245,7 +4245,7 @@ def deps():
def colorized(self): def colorized(self):
return colorize_spec(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 r"""Prints out particular pieces of a spec, depending on what is
in the format string. in the format string.
@ -4324,7 +4324,7 @@ def format(self, format_string=default_format, **kwargs):
def write(s, c=None): def write(s, c=None):
f = clr.cescape(s) f = clr.cescape(s)
if c is not None: if c is not None:
f = color_formats[c] + f + "@." f = COLOR_FORMATS[c] + f + "@."
clr.cwrite(f, stream=out, color=color) clr.cwrite(f, stream=out, color=color)
def write_attribute(spec, attribute, color): def write_attribute(spec, attribute, color):
@ -4523,7 +4523,7 @@ def tree(self, **kwargs):
status_fn = kwargs.pop("status_fn", False) status_fn = kwargs.pop("status_fn", False)
cover = kwargs.pop("cover", "nodes") cover = kwargs.pop("cover", "nodes")
indent = kwargs.pop("indent", 0) indent = kwargs.pop("indent", 0)
fmt = kwargs.pop("format", default_format) fmt = kwargs.pop("format", DEFAULT_FORMAT)
prefix = kwargs.pop("prefix", None) prefix = kwargs.pop("prefix", None)
show_types = kwargs.pop("show_types", False) show_types = kwargs.pop("show_types", False)
deptypes = kwargs.pop("deptypes", "all") deptypes = kwargs.pop("deptypes", "all")