Skip to content

Commit

Permalink
Merge pull request #11 from neo4j-labs/fix-pylint
Browse files Browse the repository at this point in the history
Fix pylint issues
  • Loading branch information
danielruminski authored Sep 17, 2023
2 parents c070127 + bad87ad commit 37fe2e2
Show file tree
Hide file tree
Showing 25 changed files with 61 additions and 51 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ jobs:
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Set PYTHONPATH
run: echo "PYTHONPATH=$(pwd)" >> $GITHUB_ENV
- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand Down
2 changes: 2 additions & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions aura/api_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions aura/api_repository.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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.")

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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")
4 changes: 2 additions & 2 deletions aura/aura.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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()


Expand Down
12 changes: 3 additions & 9 deletions aura/config/__init__.py
Original file line number Diff line number Diff line change
@@ -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 <my-tenant-id>\n
Expand Down
3 changes: 2 additions & 1 deletion aura/config/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 3 additions & 2 deletions aura/config/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,20 @@
@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()
except Exception as exception:
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:
Expand Down
13 changes: 9 additions & 4 deletions aura/config/set.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,20 @@
)
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
• 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
"""

HELP_TEXT = f"""
Set a config option to a new value
{VALID_OPTIONS_HELP_TEXT}
Example usage:\n
Expand All @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion aura/config/unset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions aura/config_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__

Expand Down Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion aura/credentials/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
3 changes: 2 additions & 1 deletion aura/credentials/current.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
3 changes: 2 additions & 1 deletion aura/credentials/delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion aura/credentials/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
3 changes: 2 additions & 1 deletion aura/credentials/use.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions aura/instances/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
4 changes: 2 additions & 2 deletions aura/instances/overwrite.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
4 changes: 2 additions & 2 deletions aura/instances/pause.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 2 additions & 2 deletions aura/instances/resume.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 2 additions & 2 deletions aura/instances/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
2 changes: 1 addition & 1 deletion aura/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
4 changes: 2 additions & 2 deletions aura/snapshots/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 2 additions & 2 deletions aura/snapshots/restore.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 0 additions & 2 deletions tests/unit/conftest.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import json

from aura.config_repository import CLIConfig
import pytest
from unittest.mock import MagicMock, patch, Mock
import pprint


def mock_headers():
Expand Down

0 comments on commit 37fe2e2

Please sign in to comment.