Skip to content

Commit 3959f62

Browse files
Merge branch 'main' into refactor_lint_fixes_PLR_PLW_PLC_PYI_TC
2 parents ea1dc55 + d76e480 commit 3959f62

117 files changed

Lines changed: 458 additions & 350 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/conductor/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "1.1.10"
1+
__version__ = "1.1.10"

src/conductor/client/ai/integrations.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,9 @@
22

33
import os
44
from abc import ABC, abstractmethod
5-
5+
from typing import Optional
66

77
class IntegrationConfig(ABC):
8-
def __init__(self):
9-
pass
10-
118
@abstractmethod
129
def to_dict(self) -> dict:
1310
pass
@@ -29,7 +26,7 @@ def to_dict(self) -> dict:
2926

3027
class OpenAIConfig(IntegrationConfig):
3128

32-
def __init__(self, api_key: str = None) -> None:
29+
def __init__(self, api_key: Optional[str] = None) -> None:
3330
if api_key is None:
3431
api_key = os.getenv('OPENAI_API_KEY')
3532
self.api_key = api_key
@@ -55,7 +52,7 @@ def to_dict(self) -> dict:
5552

5653
class PineconeConfig(IntegrationConfig):
5754

58-
def __init__(self, api_key: str = None, endpoint: str = None, environment: str = None, project_name: str = None) -> None:
55+
def __init__(self, api_key: Optional[str] = None, endpoint: Optional[str] = None, environment: Optional[str] = None, project_name: Optional[str] = None) -> None:
5956
if api_key is None:
6057
self.api_key = os.getenv('PINECONE_API_KEY')
6158
else:

src/conductor/client/ai/orchestrator.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ def associate_prompt_template(self, name: str, ai_integration: str, ai_models: L
5050
def test_prompt_template(self, text: str, variables: dict,
5151
ai_integration: str,
5252
text_complete_model: str,
53-
stop_words: Optional[List[str]] = [], max_tokens: Optional[int] = 100,
53+
stop_words: List[str] = None, max_tokens: int = 100,
5454
temperature: int = 0,
5555
top_p: int = 1):
56-
56+
stop_words = stop_words or []
5757
return self.prompt_client.test_prompt(text, variables, ai_integration, text_complete_model, temperature, top_p,
5858
stop_words)
5959

@@ -76,8 +76,8 @@ def add_ai_integration(self, ai_integration_name: str, provider: LLMProvider, mo
7676
if existing_integration_api is None or overwrite:
7777
self.integration_client.save_integration_api(ai_integration_name, model, api_details)
7878

79-
def add_vector_store(self, db_integration_name: str, provider: VectorDB, indices: List[str],config: IntegrationConfig,
80-
description: str = None,overwrite : bool = False):
79+
def add_vector_store(self, db_integration_name: str, provider: VectorDB, indices: List[str], config: IntegrationConfig,
80+
description: Optional[str] = None, overwrite: bool = False):
8181
vector_db = IntegrationUpdate()
8282
vector_db.configuration = config.to_dict()
8383
vector_db.type = provider.value

src/conductor/client/authorization_client.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import annotations
12
from abc import ABC, abstractmethod
23
from typing import Dict, List, Optional
34
from conductor.client.orkes.models.metadata_tag import MetadataTag

src/conductor/client/automator/task_handler.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
from __future__ import annotations
12
import importlib
23
import logging
34
import os
4-
from multiprocessing import Process, freeze_support, Queue, set_start_method, get_context
5+
from multiprocessing import Process, freeze_support, Queue, set_start_method
56
from sys import platform
6-
from typing import List
7+
from typing import List, Optional
78

89
from conductor.client.automator.task_runner import TaskRunner
910
from conductor.client.configuration.configuration import Configuration
@@ -45,12 +46,13 @@ def register_decorated_fn(name: str, poll_interval: int, domain: str, worker_id:
4546
class TaskHandler:
4647
def __init__(
4748
self,
48-
workers: List[WorkerInterface] = [],
49-
configuration: Configuration = None,
50-
metrics_settings: MetricsSettings = None,
49+
workers: Optional[List[WorkerInterface]] = None,
50+
configuration: Optional[Configuration] = None,
51+
metrics_settings: Optional[MetricsSettings] = None,
5152
scan_for_annotated_workers: bool = True,
52-
import_modules: List[str] = None
53+
import_modules: Optional[List[str]] = None
5354
):
55+
workers = workers or []
5456
self.logger_process, self.queue = _setup_logging_queue(configuration)
5557

5658
# imports
@@ -61,8 +63,6 @@ def __init__(
6163
logger.info(f'loading module {module}')
6264
importlib.import_module(module)
6365

64-
if workers is None:
65-
workers = []
6666
elif not isinstance(workers, list):
6767
workers = [workers]
6868
if scan_for_annotated_workers is True:

src/conductor/client/automator/task_runner.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,18 @@ def run(self) -> None:
5858
f'interval {self.worker.get_polling_interval_in_seconds()}')
5959

6060
while True:
61-
try:
62-
self.run_once()
63-
except Exception as e:
64-
pass
61+
self.run_once()
6562

6663
def run_once(self) -> None:
67-
task = self.__poll_task()
68-
if task is not None and task.task_id is not None:
69-
task_result = self.__execute_task(task)
70-
self.__update_task(task_result)
71-
self.__wait_for_polling_interval()
72-
self.worker.clear_task_definition_name_cache()
64+
try:
65+
task = self.__poll_task()
66+
if task is not None and task.task_id is not None:
67+
task_result = self.__execute_task(task)
68+
self.__update_task(task_result)
69+
self.__wait_for_polling_interval()
70+
self.worker.clear_task_definition_name_cache()
71+
except Exception as e:
72+
pass
7373

7474
def __poll_task(self) -> Task:
7575
task_definition_name = self.worker.get_task_definition_name()
@@ -229,14 +229,13 @@ def __set_worker_properties(self) -> None:
229229
if polling_interval:
230230
try:
231231
self.worker.poll_interval = float(polling_interval)
232-
except Exception as e:
232+
except Exception:
233233
logger.error(f'error reading and parsing the polling interval value {polling_interval}')
234234
self.worker.poll_interval = self.worker.get_polling_interval_in_seconds()
235235

236236
if polling_interval:
237237
try:
238238
self.worker.poll_interval = float(polling_interval)
239-
polling_interval_initialized = True
240239
except Exception as e:
241240
logger.error("Exception in reading polling interval from environment variable: {0}.".format(str(e)))
242241

src/conductor/client/automator/utils.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import annotations
12
import dataclasses
23
import datetime
34
import inspect
@@ -43,7 +44,7 @@ def convert_from_dict(cls: type, data: dict) -> object:
4344
if data is None:
4445
return data
4546

46-
if type(data) == cls:
47+
if isinstance(data, cls):
4748
return data
4849

4950
if dataclasses.is_dataclass(cls):
@@ -53,7 +54,7 @@ def convert_from_dict(cls: type, data: dict) -> object:
5354
if not ((str(typ).startswith('dict[') or
5455
str(typ).startswith('typing.Dict[') or
5556
str(typ).startswith('requests.structures.CaseInsensitiveDict[') or
56-
typ == dict or str(typ).startswith('OrderedDict['))):
57+
typ is dict or str(typ).startswith('OrderedDict['))):
5758
data = {}
5859

5960
members = inspect.signature(cls.__init__).parameters
@@ -71,17 +72,15 @@ def convert_from_dict(cls: type, data: dict) -> object:
7172
else:
7273
kwargs[member] = members[member].default
7374
elif str(typ).startswith('typing.List[') or str(typ).startswith('typing.Set[') or str(typ).startswith('list['):
74-
values = []
7575
generic_type = object
7676
if len(generic_types) > 0:
7777
generic_type = generic_types[0]
78-
for val in data[member]:
79-
values.append(get_value(generic_type, val))
78+
values = [get_value(generic_type, item) for item in data[member]]
8079
kwargs[member] = values
8180
elif (str(typ).startswith('dict[') or
8281
str(typ).startswith('typing.Dict[') or
8382
str(typ).startswith('requests.structures.CaseInsensitiveDict[') or
84-
typ == dict or str(typ).startswith('OrderedDict[')):
83+
typ is dict or str(typ).startswith('OrderedDict[')):
8584

8685
values = {}
8786
generic_type = object
@@ -91,7 +90,7 @@ def convert_from_dict(cls: type, data: dict) -> object:
9190
v = data[member][k]
9291
values[k] = get_value(generic_type, v)
9392
kwargs[member] = values
94-
elif typ == inspect.Parameter.empty:
93+
elif typ is inspect.Parameter.empty:
9594
if inspect.Parameter.VAR_KEYWORD == members[member].kind:
9695
if type(data) in dict_types:
9796
kwargs.update(data)
@@ -113,7 +112,7 @@ def get_value(typ: type, val: object) -> object:
113112
values = [get_value(type(item), item) for item in val]
114113
return values
115114
elif str(typ).startswith('dict[') or str(typ).startswith(
116-
'typing.Dict[') or str(typ).startswith('requests.structures.CaseInsensitiveDict[') or typ == dict:
115+
'typing.Dict[') or str(typ).startswith('requests.structures.CaseInsensitiveDict[') or typ is dict:
117116
values = {}
118117
for k in val:
119118
v = val[k]

src/conductor/client/configuration/configuration.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
from __future__ import annotations
12
import logging
23
import os
34
import time
5+
from typing import Optional
46

57
from conductor.client.configuration.settings.authentication_settings import AuthenticationSettings
68

@@ -10,10 +12,10 @@ class Configuration:
1012

1113
def __init__(
1214
self,
13-
base_url: str = None,
15+
base_url: Optional[str] = None,
1416
debug: bool = False,
1517
authentication_settings: AuthenticationSettings = None,
16-
server_api_url: str = None,
18+
server_api_url: Optional[str] = None,
1719
auth_token_ttl_min: int = 45
1820
):
1921
if server_api_url is not None:
@@ -138,7 +140,7 @@ def ui_host(self):
138140
"""
139141
return self.__ui_host
140142

141-
def apply_logging_config(self, log_format : str = None, level = None):
143+
def apply_logging_config(self, log_format : Optional[str] = None, level = None):
142144
if log_format is None:
143145
log_format = self.logger_format
144146
if level is None:

src/conductor/client/configuration/settings/metrics_settings.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
from __future__ import annotations
12
import logging
23
import os
4+
from typing import Optional
35
from pathlib import Path
46

57
from conductor.client.configuration.configuration import Configuration
@@ -12,13 +14,13 @@
1214

1315

1416
def get_default_temporary_folder() -> str:
15-
return f'{str(Path.home())}/tmp/'
17+
return f'{Path.home()!s}/tmp/'
1618

1719

1820
class MetricsSettings:
1921
def __init__(
2022
self,
21-
directory: str = None,
23+
directory: Optional[str] = None,
2224
file_name: str = 'metrics.log',
2325
update_interval: float = 0.1):
2426
if directory is None:

src/conductor/client/event/queue/queue_configuration.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
from abc import ABC
2-
from typing import Any, Dict
1+
from abc import ABC, abstractmethod
2+
from typing import Any, ClassVar, Dict
33

44
from conductor.client.event.queue.queue_worker_configuration import QueueWorkerConfiguration
55

66

77
class QueueConfiguration(ABC):
8-
WORKER_CONSUMER_KEY = "consumer"
9-
WORKER_PRODUCER_KEY = "producer"
8+
WORKER_CONSUMER_KEY: ClassVar[str] = "consumer"
9+
WORKER_PRODUCER_KEY: ClassVar[str] = "producer"
1010

1111
def __init__(self, queue_name: str, queue_type: str):
1212
self.queue_name = queue_name
@@ -19,5 +19,6 @@ def add_consumer(self, worker_configuration: QueueWorkerConfiguration) -> None:
1919
def add_producer(self, worker_configuration: QueueWorkerConfiguration) -> None:
2020
self.worker_configuration[self.WORKER_PRODUCER_KEY] = worker_configuration
2121

22+
@abstractmethod
2223
def get_worker_configuration(self) -> Dict[str, Any]:
2324
raise NotImplementedError

0 commit comments

Comments
 (0)