Skip to content
Snippets Groups Projects
Commit 29afcd9c authored by Martin Lang's avatar Martin Lang
Browse files

Move pretty_print_spec to separate module in util

parent 206a4f9d
No related branches found
No related tags found
1 merge request!123Resolve "split the main file into one per cmd"
Pipeline #403853 passed
......@@ -4,10 +4,9 @@ import os
from pathlib import Path
from typing import List, Union
from rich import print as rprint
from mpsd_software_manager import config_vars
from mpsd_software_manager.utils.microarch import get_native_microarchitecture
from mpsd_software_manager.utils.pretty_print_spec import pretty_print_spec
from mpsd_software_manager.utils.run import run
......@@ -247,44 +246,3 @@ def list_installed_packages(
for package in package_list:
pretty_print_spec(package)
return package_list
# TODO Martin: this could maybe be moved to utils
def pretty_print_spec(spec: str) -> None:
"""
Print the specs with colours using rich.
- packages in white (everything until first %)
- compiler in green (everything between % and first+)
- variants in cyan (everything that starts with +)
- build_system in yellow (everything that starts with build_system=)
- architecture in purple (everything that starts with arch=)
"""
# Note that this implementation necessitates the definition of
# flags in the order in which we ask spack to format the output
# also for flags that need the same colour because they are
# interchangeable (like `+` and `~`) we need to define them together
colour_map = {
"%": "green",
"+": "cyan",
"~": "cyan",
"build_system=": "yellow",
"libs=": "blue",
"arch=": "purple",
}
prev_colour = ""
for flag in colour_map.keys():
# If the flag is in the spec string,
# replace it with: previous closing colour, new colour, flag
if flag in spec:
if (
colour_map[flag] not in prev_colour
): # avoid duplicates for eg when having both ~ and +
spec = spec.replace(flag, f"{prev_colour}[{colour_map[flag]}]{flag}", 1)
prev_colour = f"[/{colour_map[flag]}]" # for next iter
# Add the final closing tag to the spec string
spec += prev_colour
rprint(spec)
"""Coloured output of spack spec."""
from rich import print as rprint
def pretty_print_spec(spec: str) -> None:
"""
Print the specs with colours using rich.
- packages in white (everything until first %)
- compiler in green (everything between % and first+)
- variants in cyan (everything that starts with +)
- build_system in yellow (everything that starts with build_system=)
- architecture in purple (everything that starts with arch=)
"""
# Note that this implementation necessitates the definition of
# flags in the order in which we ask spack to format the output
# also for flags that need the same colour because they are
# interchangeable (like `+` and `~`) we need to define them together
colour_map = {
"%": "green",
"+": "cyan",
"~": "cyan",
"build_system=": "yellow",
"libs=": "blue",
"arch=": "purple",
}
prev_colour = ""
for flag in colour_map.keys():
# If the flag is in the spec string,
# replace it with: previous closing colour, new colour, flag
if flag in spec:
if (
colour_map[flag] not in prev_colour
): # avoid duplicates for eg when having both ~ and +
spec = spec.replace(flag, f"{prev_colour}[{colour_map[flag]}]{flag}", 1)
prev_colour = f"[/{colour_map[flag]}]" # for next iter
# Add the final closing tag to the spec string
spec += prev_colour
rprint(spec)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment