Skip to content

Commit

Permalink
linting
Browse files Browse the repository at this point in the history
  • Loading branch information
solarw committed Jan 19, 2024
1 parent e33c257 commit 65d0407
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 93 deletions.
38 changes: 0 additions & 38 deletions propel_client/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
# ------------------------------------------------------------------------------
"""CLI implementation."""
import concurrent.futures
from contextlib import contextmanager
import json
import os
import time
Expand All @@ -27,7 +26,6 @@
from functools import wraps
from pathlib import Path
from sys import stdin
from traceback import print_exc, print_tb
from typing import Any, Callable, Dict, Optional

import click # type: ignore
Expand Down Expand Up @@ -614,42 +612,6 @@ def agents_variables_remove(
print_json(agent)


@click.command(name="variables-add")
@click.pass_obj
@click.argument("name_or_id", type=str, required=True)
@click.argument("variables", type=str, required=False)
def agents_variables_add(obj: ClickAPPObject, name_or_id: str, variables: str) -> None:
"""
Add variables to agent.
:param name_or_id: str
:param variables: str
:param obj: ClickAPPObject
"""
variables_list = variables.split(",") or [] if variables else []
agent = obj.propel_client.agents_variables_add(name_or_id, variables_list)
print_json(agent)


@click.command(name="variables-remove")
@click.pass_obj
@click.argument("name_or_id", type=str, required=True)
@click.argument("variables", type=str, required=False)
def agents_variables_remove(
obj: ClickAPPObject, name_or_id: str, variables: str
) -> None:
"""
Remove variables from agent.
:param name_or_id: str
:param variables: str
:param obj: ClickAPPObject
"""
variables_list = variables.split(",") or [] if variables else []
agent = obj.propel_client.agents_variables_remove(name_or_id, variables_list)
print_json(agent)


@click.command(name="delete")
@click.pass_obj
@click.argument("name_or_id", type=str, required=True)
Expand Down
64 changes: 10 additions & 54 deletions propel_client/propel.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

import requests
from requests import Response
from requests.adapters import HTTPAdapter, Retry
from requests.adapters import Retry

from propel_client import constants
from propel_client.cred_storage import CredentialStorage
Expand Down Expand Up @@ -57,12 +57,10 @@ def __init__(


class LogRetry(Retry):
"""
Adding extra logs before making a retry request
"""
"""Adding extra logs before making a retry request."""

def __init__(self, *args, **kwargs):
print("RETRY", args, kwargs)
"""Init log retry."""
super().__init__(*args, **kwargs)


Expand Down Expand Up @@ -261,7 +259,9 @@ def _http_get(self, *args, **kwargs) -> Response:
try:
return self._http_session.get(*args, **kwargs, timeout=self._timeout)
except Exception as e:
print(f"Failed to perform get request: {args}: attempt {i+1} exception {e}")
print(
f"Failed to perform get request: {args}: attempt {i+1} exception {e}"
)
time.sleep(self._backoff_factor * (2**i))

def _http_post(self, *args, **kwargs) -> Response:
Expand All @@ -270,13 +270,14 @@ def _http_post(self, *args, **kwargs) -> Response:
try:
return self._http_session.post(*args, **kwargs, timeout=self._timeout)
except Exception as e:
print(f"Failed to perform post request: {args}: attempt {i+1} exception {e}")
if i < self._retries -1:
print(
f"Failed to perform post request: {args}: attempt {i+1} exception {e}"
)
if i < self._retries - 1:
time.sleep(self._backoff_factor * (2**i))
else:
raise


def agents_restart(self, agent_name_or_id: Union[int, str]) -> Dict:
"""
Restart agent by name or id.
Expand Down Expand Up @@ -348,51 +349,6 @@ def agents_variables_remove(
self._check_response(response)
return response.json()

def agents_variables_add(
self, agent_name_or_id: Union[int, str], variables: List[str]
) -> Dict:
"""
Add variables to agent.
:param agent_name_or_id: str or int
:param variables: list of str
:return: dict
"""
url = (
self._get_url(self.API_AGENTS_LIST) + f"/{agent_name_or_id}/variables_add/"
)
response = requests.post(
url,
json={"variables": variables},
**self._get_credentials_params(),
allow_redirects=False,
)
self._check_response(response)
return response.json()

def agents_variables_remove(
self, agent_name_or_id: Union[int, str], variables: List[str]
) -> Dict:
"""
Remove variables from agent.
:param agent_name_or_id: str or int
:param variables: list of str
:return: dict
"""
url = (
self._get_url(self.API_AGENTS_LIST)
+ f"/{agent_name_or_id}/variables_remove/"
)

response = requests.post(
url, **self._get_credentials_params(), json={"variables": variables}
)
self._check_response(response)
return response.json()

def agents_delete(self, agent_name_or_id: Union[int, str]) -> Dict:
"""
Delete agent by name or id.
Expand Down
2 changes: 1 addition & 1 deletion scripts/check_copyright.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-
# ------------------------------------------------------------------------------
#
# Copyright 2021-2023 Valory AG
# Copyright 2021-2024 Valory AG
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down

0 comments on commit 65d0407

Please sign in to comment.