Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI: normalize use of colors #5547

Merged
merged 1 commit into from
May 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions aiida/cmdline/commands/cmd_computer.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ def computer_test(user, print_traceback, computer):
with transport:
num_tests += 1

echo.echo('[OK]', fg='green')
echo.echo('[OK]', fg=echo.COLORS['success'])

scheduler.set_transport(transport)

Expand All @@ -501,24 +501,24 @@ def computer_test(user, print_traceback, computer):
if not success:
num_failures += 1
if message:
echo.echo('[Failed]: ', fg='red', nl=False)
echo.echo('[Failed]: ', fg=echo.COLORS['error'], nl=False)
echo.echo(message)
else:
echo.echo('[Failed]', fg='red')
echo.echo('[Failed]', fg=echo.COLORS['error'])
else:
if message:
echo.echo('[OK]: ', fg='green', nl=False)
echo.echo('[OK]: ', fg=echo.COLORS['success'], nl=False)
echo.echo(message)
else:
echo.echo('[OK]', fg='green')
echo.echo('[OK]', fg=echo.COLORS['success'])

if num_failures:
echo.echo_warning(f'{num_failures} out of {num_tests} tests failed')
else:
echo.echo_success(f'all {num_tests} tests succeeded')

except Exception: # pylint:disable=broad-except
echo.echo('[FAILED]: ', fg='red', nl=False)
echo.echo('[FAILED]: ', fg=echo.COLORS['error'], nl=False)
message = 'Error while trying to connect to the computer'

if print_traceback:
Expand Down
6 changes: 3 additions & 3 deletions aiida/cmdline/commands/cmd_daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def start(foreground, number):
currenv = get_env_with_venv_bin()
subprocess.check_output(command, env=currenv, stderr=subprocess.STDOUT) # pylint: disable=unexpected-keyword-arg
except subprocess.CalledProcessError as exception:
echo.echo('FAILED', fg='red', bold=True)
echo.echo('FAILED', fg=echo.COLORS['error'], bold=True)
echo.echo_critical(str(exception))

# We add a small timeout to give the pid-file a chance to be created
Expand Down Expand Up @@ -110,7 +110,7 @@ def status(all_profiles):
for profile in profiles:
client = get_daemon_client(profile.name)
delete_stale_pid_file(client)
echo.echo('Profile: ', fg='red', bold=True, nl=False)
echo.echo('Profile: ', fg=echo.COLORS['report'], bold=True, nl=False)
echo.echo(f'{profile.name}', bold=True)
result = get_daemon_status(client)
echo.echo(result)
Expand Down Expand Up @@ -188,7 +188,7 @@ def stop(no_wait, all_profiles):

client = get_daemon_client(profile.name)

echo.echo('Profile: ', fg='red', bold=True, nl=False)
echo.echo('Profile: ', fg=echo.COLORS['report'], bold=True, nl=False)
echo.echo(f'{profile.name}', bold=True)

if not client.is_daemon_running:
Expand Down
2 changes: 1 addition & 1 deletion aiida/cmdline/commands/cmd_data/cmd_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def remote_ls(ls_long, path, datum):
)
echo.echo(pre_line, nl=False)
if metadata['isdir']:
echo.echo(metadata['name'], fg='blue')
echo.echo(metadata['name'], fg=echo.COLORS['info'])
else:
echo.echo(metadata['name'])

Expand Down
2 changes: 1 addition & 1 deletion aiida/cmdline/params/options/interactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def foo(label):
click.echo(f'Labeling with label: {label}')
"""

PROMPT_COLOR = 'yellow'
PROMPT_COLOR = echo.COLORS['warning']
CHARACTER_PROMPT_HELP = '?'
CHARACTER_IGNORE_DEFAULT = '!'

Expand Down
8 changes: 4 additions & 4 deletions aiida/cmdline/utils/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ def print_process_info(process):
if not docstring:
docstring = ['No description available']

echo.echo('Description:\n', fg='red', bold=True)
echo.echo('Description:\n', fg=echo.COLORS['report'], bold=True)
for line in docstring:
echo.echo(f' {line.lstrip()}')
echo.echo('')
Expand Down Expand Up @@ -450,23 +450,23 @@ def build_entries(ports):
max_width_type = max([len(entry[2]) for entry in inputs + outputs]) + 2

if process_spec.inputs:
echo.echo('Inputs:', fg='red', bold=True)
echo.echo('Inputs:', fg=echo.COLORS['report'], bold=True)
for entry in inputs:
if entry[1] == 'required':
echo.echo(template.format(*entry, width_name=max_width_name, width_type=max_width_type), bold=True)
else:
echo.echo(template.format(*entry, width_name=max_width_name, width_type=max_width_type))

if process_spec.outputs:
echo.echo('Outputs:', fg='red', bold=True)
echo.echo('Outputs:', fg=echo.COLORS['report'], bold=True)
for entry in outputs:
if entry[1] == 'required':
echo.echo(template.format(*entry, width_name=max_width_name, width_type=max_width_type), bold=True)
else:
echo.echo(template.format(*entry, width_name=max_width_name, width_type=max_width_type))

if process_spec.exit_codes:
echo.echo('Exit codes:', fg='red', bold=True)
echo.echo('Exit codes:', fg=echo.COLORS['report'], bold=True)
for exit_code in sorted(process_spec.exit_codes.values(), key=lambda exit_code: exit_code.status):
message = exit_code.message
echo.echo('{:>{width_name}d}: {}'.format(exit_code.status, message, width_name=max_width_name))
Expand Down
8 changes: 4 additions & 4 deletions aiida/cmdline/utils/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@ def print_client_response_status(response):
return 1

if response['status'] == 'active':
echo.echo('RUNNING', fg='green', bold=True)
echo.echo('RUNNING', fg=echo.COLORS['success'], bold=True)
return 0
if response['status'] == 'ok':
echo.echo('OK', fg='green', bold=True)
echo.echo('OK', fg=echo.COLORS['success'], bold=True)
return 0
if response['status'] == DaemonClient.DAEMON_ERROR_NOT_RUNNING:
echo.echo('FAILED', fg='red', bold=True)
echo.echo('FAILED', fg=echo.COLORS['error'], bold=True)
echo.echo('Try to run `verdi daemon start-circus --foreground` to potentially see the exception')
return 2
if response['status'] == DaemonClient.DAEMON_ERROR_TIMEOUT:
echo.echo('TIMEOUT', fg='red', bold=True)
echo.echo('TIMEOUT', fg=echo.COLORS['error'], bold=True)
return 3
# Unknown status, I will consider it as failed
echo.echo_critical(response['status'])
Expand Down
6 changes: 5 additions & 1 deletion aiida/cmdline/utils/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,8 @@ def list_repository_contents(node, path, color):

for entry in node.base.repository.list_objects(path):
bold = bool(entry.file_type == FileType.DIRECTORY)
echo.echo(entry.name, bold=bold, fg='blue' if color and entry.file_type == FileType.DIRECTORY else None)
echo.echo(
entry.name,
bold=bold,
fg=echo.COLORS['report'] if color and entry.file_type == FileType.DIRECTORY else None
)