From a6ccf4e5cf755eec3b70385625e8db2574cf48f1 Mon Sep 17 00:00:00 2001 From: Alexander Goscinski Date: Fri, 24 May 2024 14:14:47 +0200 Subject: [PATCH] fix pre-commit linter --- src/aiida/cmdline/__init__.py | 4 ---- src/aiida/cmdline/commands/cmd_computer.py | 10 +++++----- src/aiida/cmdline/utils/echo.py | 3 ++- tests/cmdline/commands/test_computer.py | 12 +++--------- 4 files changed, 10 insertions(+), 19 deletions(-) diff --git a/src/aiida/cmdline/__init__.py b/src/aiida/cmdline/__init__.py index 265cb8af2e..931695326f 100644 --- a/src/aiida/cmdline/__init__.py +++ b/src/aiida/cmdline/__init__.py @@ -11,9 +11,6 @@ # AUTO-GENERATED # fmt: off -import logging - -CMDLINE_LOGGER = logging.getLogger('verdi') from .groups import * from .params import * @@ -60,7 +57,6 @@ 'is_verbose', 'only_if_daemon_running', 'with_dbenv', - 'CMDLINE_LOGGER', ) # fmt: on diff --git a/src/aiida/cmdline/commands/cmd_computer.py b/src/aiida/cmdline/commands/cmd_computer.py index 23293c36be..a3db3db611 100644 --- a/src/aiida/cmdline/commands/cmd_computer.py +++ b/src/aiida/cmdline/commands/cmd_computer.py @@ -8,15 +8,14 @@ ########################################################################### """`verdi computer` command.""" +import pathlib import traceback from copy import deepcopy from functools import partial from math import isclose -import pathlib import click -from aiida.cmdline import CMDLINE_LOGGER from aiida.cmdline.commands.cmd_verdi import VerdiCommandGroup, verdi from aiida.cmdline.params import arguments, options from aiida.cmdline.params.options.commands import computer as options_computer @@ -769,7 +768,7 @@ def computer_export_setup(computer, output_file): echo.echo_success(f"Computer<{computer.pk}> {computer.label} setup exported to file '{output_file}'.") except Exception as e: error_traceback = traceback.format_exc() - CMDLINE_LOGGER.debug(error_traceback) + echo.CMDLINE_LOGGER.debug(error_traceback) echo.echo_critical( f'Unexpected error while exporting setup for Computer<{computer.pk}> {computer.label}:\n ({e!s}).' ) @@ -805,7 +804,8 @@ def computer_export_config(computer, user, output_file): ) except Exception as e: error_traceback = traceback.format_exc() - CMDLINE_LOGGER.debug(error_traceback) + echo.CMDLINE_LOGGER.debug(error_traceback) echo.echo_critical( - f'Unexpected error while exporting configuration for Computer<{computer.pk}> {computer.label} and User<{user.pk}> {user.email}: {e!s}.' + f'Unexpected error while exporting configuration for Computer<{computer.pk}> {computer.label}' + f' and User<{user.pk}> {user.email}: {e!s}.' ) diff --git a/src/aiida/cmdline/utils/echo.py b/src/aiida/cmdline/utils/echo.py index a958abd9ae..26e88337da 100644 --- a/src/aiida/cmdline/utils/echo.py +++ b/src/aiida/cmdline/utils/echo.py @@ -11,12 +11,13 @@ import collections import enum import json +import logging import sys from typing import Any, Optional import click -from aiida.cmdline import CMDLINE_LOGGER +CMDLINE_LOGGER = logging.getLogger('verdi') __all__ = ( 'echo_report', diff --git a/tests/cmdline/commands/test_computer.py b/tests/cmdline/commands/test_computer.py index fc70a5fa40..5ea6d2b214 100644 --- a/tests/cmdline/commands/test_computer.py +++ b/tests/cmdline/commands/test_computer.py @@ -524,12 +524,8 @@ def test_computer_export_setup(self, tmp_path): exported_setup_filename = tmp_path / 'computer-setup.yml' result = self.cli_runner(computer_export_setup, [comp.label, exported_setup_filename]) assert 'Success' in result.output, 'Command should have run successfull.' - assert ( - f'{exported_setup_filename}' in result.output - ), 'Filename should be in terminal output but was not found.' - assert os.path.exists( - exported_setup_filename - ), f"'{exported_setup_filename}' was not created during export." + assert f'{exported_setup_filename}' in result.output, 'Filename should be in terminal output but was not found.' + assert os.path.exists(exported_setup_filename), f"'{exported_setup_filename}' was not created during export." # verifying correctness by comparing internal and loaded yml object with open(exported_setup_filename, 'r', encoding='utf-8') as yfhandle: @@ -556,9 +552,7 @@ def test_computer_export_config(self, tmp_path): assert ( f'{exported_config_filename}' in result.output ), 'Filename should be in terminal output but was not found.' - assert os.path.exists( - exported_config_filename - ), f"'{exported_config_filename}' was not created during export." + assert os.path.exists(exported_config_filename), f"'{exported_config_filename}' was not created during export." # verifying correctness by comparing internal and loaded yml object with open(exported_config_filename, 'r', encoding='utf-8') as yfhandle: