diff --git a/.pylintrc b/.pylintrc index e0357a8..3b21008 100644 --- a/.pylintrc +++ b/.pylintrc @@ -436,6 +436,8 @@ disable=raw-checker-failed, too-many-branches, inconsistent-return-statements, broad-exception-caught, + logging-fstring-interpolation, + logging-not-lazy, # Enable the message, report, category or checker with the given id(s). You can # either give multiple identifier separated by comma (,) or put this option diff --git a/aura/api_command.py b/aura/api_command.py index a162d4b..7c8e8cb 100644 --- a/aura/api_command.py +++ b/aura/api_command.py @@ -41,6 +41,7 @@ def api_command_decorator(func): help="Print verbose output", ) @wraps(func) + # pylint: disable=unused-argument def wrapper(output: str, include: bool, raw: bool, verbose: bool, *args, **kwargs): ctx = click.get_current_context() config: CLIConfig = ctx.obj diff --git a/aura/api_repository.py b/aura/api_repository.py index 96f4f21..a1d6ee4 100644 --- a/aura/api_repository.py +++ b/aura/api_repository.py @@ -1,8 +1,8 @@ """This module defines methods for making HTTP request to the Aura API""" import os import json -import click import time +import click from requests.auth import HTTPBasicAuth import requests @@ -89,9 +89,9 @@ def _authenticate(): ) try: response.raise_for_status() - except Exception as e: + except Exception as exception: logger.warning("Authentication request was not succesful.") - raise e + raise exception logger.debug("Authentication request successful. Using new auth token.") @@ -168,8 +168,8 @@ def make_api_call_and_wait_for_instance_status( if status == desired_status: return res - else: - time.sleep(30) + + time.sleep(30) raise InstanceOperationTimeoutError(instance_id, desired_status) @@ -199,7 +199,7 @@ def make_api_call_and_wait_for_snapshot_completed( if status == "Completed": return res - else: - time.sleep(30) + + time.sleep(30) raise SnapshotOperationTimeoutError(snapshot_id, "Completed") diff --git a/aura/aura.py b/aura/aura.py index 6ec8689..17c7c2d 100644 --- a/aura/aura.py +++ b/aura/aura.py @@ -1,6 +1,5 @@ from functools import wraps import click -import sys from aura.config_repository import CLIConfig from aura.instances import instances from aura.credentials import credentials @@ -20,7 +19,8 @@ ) @click.pass_context @click.option("--verbose", "-v", is_flag=True, default=False, help="Print verbose output") -def cli(ctx, verbose): +# pylint: disable=unused-argument +def cli(ctx, verbose: bool): ctx.obj = CLIConfig() diff --git a/aura/config/__init__.py b/aura/config/__init__.py index ce433e2..68857fc 100644 --- a/aura/config/__init__.py +++ b/aura/config/__init__.py @@ -1,19 +1,13 @@ import click -from .set import set_option +from .set import set_option, VALID_OPTIONS_HELP_TEXT from .unset import unset_option from .get import get_option from .list import list_options -HELP_TEXT = """ +HELP_TEXT = f""" Manage configurations and set default values -Valid config options:\n - • default_tenant\tSet a default tenant\n - • output\t\tSet a default output format\n - • auth_url\t\tChange the auth url\n - • base_url\t\tChange the api base url\n - • save_logs\t\tFlag if CLI logs are saved to a file\n - • log_file_path\tPath to file where logs are saved to +{VALID_OPTIONS_HELP_TEXT} Example usage:\n aura config set default_tenant \n diff --git a/aura/config/get.py b/aura/config/get.py index 1726664..18a7279 100644 --- a/aura/config/get.py +++ b/aura/config/get.py @@ -22,11 +22,12 @@ @click.command(name="get", help=HELP_TEXT) @click.option("--verbose", "-v", is_flag=True, default=False, help="Print verbose output") @pass_config +# pylint: disable=unused-argument def get_option(config: CLIConfig, name: str, verbose: bool): """ Print a config option """ - logger = get_logger("auracli") + logger = get_logger() try: if name not in VALID_OPTIONS: diff --git a/aura/config/list.py b/aura/config/list.py index 77625e7..c641a18 100644 --- a/aura/config/list.py +++ b/aura/config/list.py @@ -16,11 +16,12 @@ @click.command(name="list", help=HELP_TEXT) @click.option("--verbose", "-v", is_flag=True, default=False, help="Print verbose output") @pass_config +# pylint: disable=unused-argument def list_options(config: CLIConfig, verbose: bool): """ List all configured config options """ - logger = get_logger("auracli") + logger = get_logger() try: values = config.list_options() @@ -28,7 +29,7 @@ def list_options(config: CLIConfig, verbose: bool): handle_error(exception) if values is None or len(values) == 0: - logger.info(f"No config options set.") + logger.info("No config options set.") if not config.env["verbose"]: print("No config options set.") else: diff --git a/aura/config/set.py b/aura/config/set.py index c135253..35e1308 100644 --- a/aura/config/set.py +++ b/aura/config/set.py @@ -9,9 +9,7 @@ ) from aura.logger import get_logger -HELP_TEXT = """ -Set a config option to a new value - +VALID_OPTIONS_HELP_TEXT = """ Valid config options:\n • default_tenant\tSet a default tenant\n • output\t\tSet a default output format\n @@ -19,6 +17,12 @@ • base_url\t\tChange the api base url\n • save_logs\t\tFlag if CLI logs are saved to a file\n • log_file_path\tPath to file where logs are saved to +""" + +HELP_TEXT = f""" +Set a config option to a new value + +{VALID_OPTIONS_HELP_TEXT} Example usage:\n @@ -32,11 +36,12 @@ @click.argument("value") @click.option("--verbose", "-v", is_flag=True, default=False, help="Print verbose output") @pass_config +# pylint: disable=unused-argument def set_option(config: CLIConfig, name: str, value: str, verbose: bool): """ Set a config option to specified value """ - logger = get_logger("auracli") + logger = get_logger() try: if name not in VALID_OPTIONS: diff --git a/aura/config/unset.py b/aura/config/unset.py index 543724a..1fa790b 100644 --- a/aura/config/unset.py +++ b/aura/config/unset.py @@ -22,11 +22,12 @@ @click.option("--verbose", "-v", is_flag=True, default=False, help="Print verbose output") @click.command(name="unset", help=HELP_TEXT) @pass_config +# pylint: disable=unused-argument def unset_option(config: CLIConfig, name: str, verbose: bool): """ Delete a config value """ - logger = get_logger("auracli") + logger = get_logger() try: if name not in VALID_OPTIONS: diff --git a/aura/config_repository.py b/aura/config_repository.py index 6feee97..0b65851 100644 --- a/aura/config_repository.py +++ b/aura/config_repository.py @@ -9,7 +9,7 @@ UnsupportedConfigFileVersion, handle_error, ) -from aura.logger import get_logger, setup_logger +from aura.logger import setup_logger from aura.token_repository import delete_token_file from aura.version import __version__ @@ -98,8 +98,8 @@ def load_config(self) -> dict: try: self.validate_config(config) - except Exception as e: - handle_error(e) + except Exception as exception: + handle_error(exception) return config diff --git a/aura/credentials/add.py b/aura/credentials/add.py index 85a3721..08a38bf 100644 --- a/aura/credentials/add.py +++ b/aura/credentials/add.py @@ -12,13 +12,14 @@ @click.option("--verbose", "-v", is_flag=True, default=False, help="Print verbose output") @click.command(name="add", help="Add new OAuth client credentials") @pass_config +# pylint: disable=unused-argument def add_credentials( config: CLIConfig, name: str, client_id: str, client_secret: str, use: bool, verbose: bool ): """ Add a new set of credentials """ - logger = get_logger("auracli") + logger = get_logger() if not name: name = click.prompt("Credentials Name") diff --git a/aura/credentials/current.py b/aura/credentials/current.py index 3b41fce..eabe881 100644 --- a/aura/credentials/current.py +++ b/aura/credentials/current.py @@ -8,11 +8,12 @@ @click.option("--verbose", "-v", is_flag=True, default=False, help="Print verbose output") @click.command(name="current", help="Print the currently selected credentials") @pass_config +# pylint: disable=unused-argument def current_credentials(config: CLIConfig, verbose: bool): """ Print the credentials currently in use """ - logger = get_logger("auracli") + logger = get_logger() try: name, creds = config.current_credentials() diff --git a/aura/credentials/delete.py b/aura/credentials/delete.py index 2bd8e91..75a3598 100644 --- a/aura/credentials/delete.py +++ b/aura/credentials/delete.py @@ -9,11 +9,12 @@ @click.option("--verbose", "-v", is_flag=True, default=False, help="Print verbose output") @click.command(name="delete", help="Delete OAuth client credentials") @pass_config +# pylint: disable=unused-argument def delete_credentials(config: CLIConfig, name: str, verbose: bool): """ Deletes the specified credentials """ - logger = get_logger("auracli") + logger = get_logger() try: config.delete_credentials(name) diff --git a/aura/credentials/list.py b/aura/credentials/list.py index 29211c5..e5b41e9 100644 --- a/aura/credentials/list.py +++ b/aura/credentials/list.py @@ -9,11 +9,12 @@ @click.command(name="list", help="List all configured OAuth client credentials") @click.option("--verbose", "-v", is_flag=True, default=False, help="Print verbose output") @pass_config +# pylint: disable=unused-argument def list_credentials(config: CLIConfig, verbose: bool): """ List all configured credentials """ - logger = get_logger("auracli") + logger = get_logger() try: credentials = config.list_credentials() diff --git a/aura/credentials/use.py b/aura/credentials/use.py index 220fe67..7ff0d58 100644 --- a/aura/credentials/use.py +++ b/aura/credentials/use.py @@ -9,11 +9,12 @@ @click.option("--verbose", "-v", is_flag=True, default=False, help="Print verbose output") @click.command(name="use", help="Select which OAuth client credentials to use for authentication") @pass_config +# pylint: disable=unused-argument def use_credentials(config: CLIConfig, name: str, verbose: bool): """ Use the speccified credentials """ - logger = get_logger("auracli") + logger = get_logger() try: config.use_credentials(name) diff --git a/aura/instances/create.py b/aura/instances/create.py index cb76c83..95e8d82 100644 --- a/aura/instances/create.py +++ b/aura/instances/create.py @@ -62,5 +62,5 @@ def create_instance( return make_api_call_and_wait_for_instance_status( "POST", path, "running", data=json.dumps(data) ) - else: - return make_api_call("POST", path, data=json.dumps(data)) + + return make_api_call("POST", path, data=json.dumps(data)) diff --git a/aura/instances/overwrite.py b/aura/instances/overwrite.py index 8a18d25..dd046ff 100644 --- a/aura/instances/overwrite.py +++ b/aura/instances/overwrite.py @@ -39,5 +39,5 @@ def overwrite_instance( return make_api_call_and_wait_for_instance_status( "POST", path, "running", data=json.dumps(data) ) - else: - return make_api_call("POST", path, data=json.dumps(data)) + + return make_api_call("POST", path, data=json.dumps(data)) diff --git a/aura/instances/pause.py b/aura/instances/pause.py index 3e7d635..98c5eb2 100644 --- a/aura/instances/pause.py +++ b/aura/instances/pause.py @@ -26,5 +26,5 @@ def pause_instance(instance_id: str, name: str, wait: bool): if wait: return make_api_call_and_wait_for_instance_status("POST", path, "paused") - else: - return make_api_call("POST", path) + + return make_api_call("POST", path) diff --git a/aura/instances/resume.py b/aura/instances/resume.py index 7e5bd7b..34ce534 100644 --- a/aura/instances/resume.py +++ b/aura/instances/resume.py @@ -26,5 +26,5 @@ def resume_instance(instance_id: str, name: str, wait: bool): if wait: return make_api_call_and_wait_for_instance_status("POST", path, "running") - else: - return make_api_call("POST", path) + + return make_api_call("POST", path) diff --git a/aura/instances/update.py b/aura/instances/update.py index 2609d77..544f255 100644 --- a/aura/instances/update.py +++ b/aura/instances/update.py @@ -38,5 +38,5 @@ def update_instance(instance_id: str, memory: str, new_name: str, name: str, wai return make_api_call_and_wait_for_instance_status( "PATCH", path, "running", data=json.dumps(data) ) - else: - return make_api_call("PATCH", path, data=json.dumps(data)) + + return make_api_call("PATCH", path, data=json.dumps(data)) diff --git a/aura/logger.py b/aura/logger.py index 70855b9..84657bb 100644 --- a/aura/logger.py +++ b/aura/logger.py @@ -28,5 +28,5 @@ def setup_logger(is_verbose, save_logs, log_file_path): return logger -def get_logger(verbose=False): +def get_logger(): return logging.getLogger("auracli") diff --git a/aura/snapshots/create.py b/aura/snapshots/create.py index 3c34706..ade9d2b 100644 --- a/aura/snapshots/create.py +++ b/aura/snapshots/create.py @@ -26,5 +26,5 @@ def create_snapshot(instance_id: str, instance_name: str, wait: bool): if wait: return make_api_call_and_wait_for_snapshot_completed("POST", path, instance_id) - else: - return make_api_call("POST", path) + + return make_api_call("POST", path) diff --git a/aura/snapshots/restore.py b/aura/snapshots/restore.py index 914f17d..120a34a 100644 --- a/aura/snapshots/restore.py +++ b/aura/snapshots/restore.py @@ -27,5 +27,5 @@ def restore_snapshot(instance_id: str, instance_name: str, snapshot_id: str, wai if wait: return make_api_call_and_wait_for_instance_status("POST", path, "running") - else: - return make_api_call("POST", path) + + return make_api_call("POST", path)