From 16eb00d94c1070fe153a07bc04ef6b1ccc11121e Mon Sep 17 00:00:00 2001 From: Rick Chen Date: Thu, 15 Aug 2024 21:25:36 -0700 Subject: [PATCH] fix lint --- .flake8 | 5 ----- README.md | 2 +- cased/.vscode/settings.json | 2 +- cased/cli.py | 3 ++- cased/commands/deploy.py | 29 +++++++++++------------------ cased/commands/login.py | 19 ++++++++++--------- cased/commands/resources.py | 19 +++++++++++-------- cased/utils/api.py | 5 +++-- cased/utils/auth.py | 2 +- cased/utils/progress.py | 7 ++++--- requirements.txt | 2 +- setup.py | 2 +- 12 files changed, 46 insertions(+), 51 deletions(-) delete mode 100644 .flake8 diff --git a/.flake8 b/.flake8 deleted file mode 100644 index bbeec9d..0000000 --- a/.flake8 +++ /dev/null @@ -1,5 +0,0 @@ -[flake8] -max-line-length = 88 -extend-ignore = E203, E266, E501, W503 -max-complexity = 18 -select = B,C,E,F,W,T4,B9 diff --git a/README.md b/README.md index bd82643..f3ca9ee 100644 --- a/README.md +++ b/README.md @@ -59,4 +59,4 @@ cased COMMAND --help ## Contact -For any questions or support, please contact cli@cased.com \ No newline at end of file +For any questions or support, please contact cli@cased.com diff --git a/cased/.vscode/settings.json b/cased/.vscode/settings.json index 0c652b9..f67a951 100644 --- a/cased/.vscode/settings.json +++ b/cased/.vscode/settings.json @@ -14,4 +14,4 @@ "[html][django-html][handlebars][hbs][mustache][jinja][jinja-html][nj][njk][nunjucks][twig]": { "editor.defaultFormatter": "monosans.djlint" } -} \ No newline at end of file +} diff --git a/cased/cli.py b/cased/cli.py index 20c928c..ccba2e8 100644 --- a/cased/cli.py +++ b/cased/cli.py @@ -1,7 +1,8 @@ import click + from cased.commands.deploy import deploy from cased.commands.login import login, logout -from cased.commands.resources import deployments, branches +from cased.commands.resources import branches, deployments @click.group() diff --git a/cased/commands/deploy.py b/cased/commands/deploy.py index b874fe0..11fe7fa 100644 --- a/cased/commands/deploy.py +++ b/cased/commands/deploy.py @@ -1,35 +1,31 @@ -import time import click -from rich.console import Console -from rich.progress import Progress import questionary +from rich.console import Console +from cased.utils.api import deploy_branch, get_branches from cased.utils.auth import get_token -from cased.utils.api import get_branches, deploy_branch from cased.utils.progress import run_process_with_status_bar console = Console() + def _build_questionary_choices(): - data = run_process_with_status_bar( - get_branches, "Fetching branches...", timeout=10 - ) + data = run_process_with_status_bar(get_branches, "Fetching branches...", timeout=10) branches = data.get("pull_requests", []) deployable_branches = [ - branch for branch in branches if branch["deployable"] == True + branch for branch in branches if branch["deployable"] is True ] # Prepare choices for questionary choices = [ - f"{b['branch_name']} -> [{', '.join([target["name"] for target in b.get("targets", [])])}]" for b in deployable_branches + f"{b['branch_name']} -> [{', '.join([target.get('name') for target in b.get('targets', [])])}]" # noqa: E501 + for b in deployable_branches ] if not choices: console.print("[red]No deployable branches available.[/red]") return - selected = questionary.select( - "Select a branch to deploy:", choices=choices - ).ask() + selected = questionary.select("Select a branch to deploy:", choices=choices).ask() branch = selected.split(" -> ")[0] @@ -38,20 +34,17 @@ def _build_questionary_choices(): (b for b in deployable_branches if b["branch_name"] == branch), None ) if not selected_branch: - console.print(f"[red]Error: Branch '{branch}' is not deployable.[/red]") + console.print(f"[red]Error: Branch {branch} is not deployable.[/red]") return available_targets = selected_branch["targets"] if not available_targets: - console.print( - f"[red]Error: No targets available for branch '{branch}'.[/red]" - ) + console.print(f"[red]Error: No targets available for branch {branch}.[/red]") return target = questionary.select( "Select a target environment:", choices=available_targets ).ask() - return branch, target @@ -71,7 +64,7 @@ def deploy(branch, target): Examples: cased deploy cased deploy --branch feature-branch-1 --target dev - """ + """ # noqa: E501 token = get_token() if not token: console.print("[red]Please log in first using 'cased login'[/red]") diff --git a/cased/commands/login.py b/cased/commands/login.py index 0a5ff51..1e89116 100644 --- a/cased/commands/login.py +++ b/cased/commands/login.py @@ -1,14 +1,15 @@ +import json +import os +import random +import stat +import tempfile import time +from datetime import datetime, timedelta + import click from rich.console import Console from rich.panel import Panel from rich.progress import Progress -import os -import json -from datetime import datetime, timedelta -import random -import tempfile -import stat from cased.utils.auth import CONFIG_DIR, TOKEN_FILE @@ -44,7 +45,7 @@ def create_temp_token_file(token_data): # Schedule file for deletion after 24 hours deletion_time = datetime.now() + timedelta(hours=24) - deletion_command = f"(sleep {(deletion_time - datetime.now()).total_seconds()} && rm -f {temp_file.name}) &" + deletion_command = f"(sleep {(deletion_time - datetime.now()).total_seconds()} && rm -f {temp_file.name}) &" # noqa: E501 os.system(deletion_command) return temp_file.name @@ -86,7 +87,7 @@ def login(): console.print( Panel( - f"[green]Login successful![/green]\nSession token stored securely.\nSession expires in {hours} hours {minutes} minutes.", + f"[green]Login successful![/green]\nSession token stored securely.\nSession expires in {hours} hours {minutes} minutes.", # noqa: E501 title="Login Status", ) ) @@ -120,7 +121,7 @@ def logout(): else: console.print( Panel( - "[yellow]No active session found.[/yellow]\nYou are already logged out.", + "[yellow]No active session found.[/yellow]\nYou are already logged out.", # noqa: E501 title="Logout Status", ) ) diff --git a/cased/commands/resources.py b/cased/commands/resources.py index cd8202c..f02a315 100644 --- a/cased/commands/resources.py +++ b/cased/commands/resources.py @@ -1,12 +1,11 @@ import click +from dateutil import parser from rich.console import Console from rich.table import Table from rich.text import Text -from dateutil import parser - +from cased.utils.api import get_branches, get_deployments from cased.utils.auth import get_token -from cased.utils.api import get_branches, get_targets, get_deployments from cased.utils.progress import run_process_with_status_bar console = Console() @@ -53,7 +52,11 @@ def deployments(limit): status = deployment.get("status", "Unknown") deployment_id = deployment.get("id") view_url = f"https://cased.com/deployments/{deployment_id}" - deployer_full_name = f"{deployment.get("deployer").get("first_name")} {deployment.get("deployer").get("last_name")}" if deployment.get("deployer") else "Unknown" + deployer_full_name = ( + f"{deployment.get('deployer').get('first_name')} {deployment.get('deployer').get('last_name')}" # noqa: E501 + if deployment.get("deployer") + else "Unknown" + ) deployments_data.append( { @@ -116,7 +119,7 @@ def branches(limit): table.add_column("Deployable", style="blue") table.add_column("Mergeable", style="blue") table.add_column("Checks", style="cyan") - + data = run_process_with_status_bar(get_branches, "Fetching branches...", timeout=10) branches = data.get("pull_requests", []) # Generate fake data @@ -133,9 +136,9 @@ def branches(limit): str(branch.get("mergeable")), ", ".join( [ - f"approved: {branch.get("approved")}", - f"up-to-date: {branch.get("up_to_date")}", - f"checks-passed: {branch.get("checks_passing")}", + f"approved: {branch.get('approved')}", + f"up-to-date: {branch.get('up_to_date')}", + f"checks-passed: {branch.get('checks_passing')}", ] ), ) diff --git a/cased/utils/api.py b/cased/utils/api.py index 580ac50..c63aaa8 100644 --- a/cased/utils/api.py +++ b/cased/utils/api.py @@ -1,7 +1,8 @@ -import requests -import click import os +import click +import requests + API_BASE_URL = os.environ.get( "CASED_API_BASE_URL", default="https://app.cased.com/api/v1" ) diff --git a/cased/utils/auth.py b/cased/utils/auth.py index 81fd63e..f5a9584 100644 --- a/cased/utils/auth.py +++ b/cased/utils/auth.py @@ -1,5 +1,5 @@ -import os import json +import os from datetime import datetime # Configuration diff --git a/cased/utils/progress.py b/cased/utils/progress.py index fbb9967..5b27ebb 100644 --- a/cased/utils/progress.py +++ b/cased/utils/progress.py @@ -1,8 +1,9 @@ import time +from concurrent.futures import ThreadPoolExecutor, TimeoutError +from typing import Any, Callable + from rich.console import Console from rich.progress import Progress -from concurrent.futures import ThreadPoolExecutor, TimeoutError -from typing import Callable, Any def run_process_with_status_bar( @@ -42,7 +43,7 @@ def update_progress(progress, task): except TimeoutError: progress.update(task, description="[bold red]Timeout!") console.print( - f"\n[bold red]Process timed out after {timeout} seconds. Please try again later." + f"\n[bold red]Process timed out after {timeout} seconds. Please try again later." # noqa: E501 ) except Exception as e: progress.update(task, description="[bold red]Error!") diff --git a/requirements.txt b/requirements.txt index a80cd84..9cad651 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ click==8.1.3 rich==13.3.5 questionary==1.10.0 -python-dateutil==2.9.0 \ No newline at end of file +python-dateutil==2.9.0 diff --git a/setup.py b/setup.py index a7925f0..8d477ff 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,4 @@ -from setuptools import setup, find_packages +from setuptools import find_packages, setup with open("README.md", "r", encoding="utf-8") as fh: long_description = fh.read()