Skip to content

Commit

Permalink
Run code formatters.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandervsokol committed Nov 12, 2024
1 parent 579b441 commit 02b455c
Show file tree
Hide file tree
Showing 40 changed files with 134 additions and 141 deletions.
2 changes: 1 addition & 1 deletion cl/runtime/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@
from starlette.responses import JSONResponse
from starlette.staticfiles import StaticFiles
from cl.runtime import Context
from cl.runtime.routers.context_middleware import ContextMiddleware
from cl.runtime.context.process_context import ProcessContext
from cl.runtime.log.exceptions.user_error import UserError
from cl.runtime.log.log_entry import LogEntry
from cl.runtime.log.log_entry_level_enum import LogEntryLevelEnum
from cl.runtime.log.user_log_entry import UserLogEntry
from cl.runtime.routers.app import app_router
from cl.runtime.routers.auth import auth_router
from cl.runtime.routers.context_middleware import ContextMiddleware
from cl.runtime.routers.entity import entity_router
from cl.runtime.routers.health import health_router
from cl.runtime.routers.schema import schema_router
Expand Down
3 changes: 2 additions & 1 deletion cl/runtime/context/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
import logging
from contextvars import ContextVar
from dataclasses import dataclass
from typing import Iterable, Dict
from typing import Dict
from typing import Iterable
from typing import List
from typing import Optional
from typing import Type
Expand Down
15 changes: 5 additions & 10 deletions cl/runtime/context/context_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@

import base64
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import serialization, hashes
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives import serialization
from cryptography.hazmat.primitives.asymmetric import padding
from cl.runtime import Context

Expand Down Expand Up @@ -45,19 +46,13 @@ def decrypt_secret(cls, key: str) -> str | None:

# Load the private key
private_key = serialization.load_pem_private_key(
private_key_pem.encode(),
password=None,
backend=default_backend()
private_key_pem.encode(), password=None, backend=default_backend()
)

# Decrypt the value
decrypted_value_bytes = private_key.decrypt(
encrypted_value_bytes,
padding.OAEP(
mgf=padding.MGF1(algorithm=hashes.SHA256()),
algorithm=hashes.SHA256(),
label=None
)
padding.OAEP(mgf=padding.MGF1(algorithm=hashes.SHA256()), algorithm=hashes.SHA256(), label=None),
)

return decrypted_value_bytes.decode('utf-8')
return decrypted_value_bytes.decode("utf-8")
1 change: 0 additions & 1 deletion cl/runtime/exceptions/error_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

from typing import Any
from typing import Type

from cl.runtime.log.exceptions.user_error import UserError
from cl.runtime.primitive.case_util import CaseUtil
from cl.runtime.primitive.string_util import StringUtil
Expand Down
2 changes: 1 addition & 1 deletion cl/runtime/plots/heat_map_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,4 @@ def _create_figure(self) -> plt.Figure:

fig.tight_layout()

return fig
return fig
15 changes: 6 additions & 9 deletions cl/runtime/routers/entity/list_panels_response_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,12 @@
from __future__ import annotations
from typing import List
from pydantic import BaseModel

from cl.runtime import Context
from cl.runtime.primitive.case_util import CaseUtil
from cl.runtime.routers.entity.list_panels_request import ListPanelsRequest
from cl.runtime.schema.handler_declare_block_decl import HandlerDeclareBlockDecl
from cl.runtime.schema.handler_declare_decl import HandlerDeclareDecl
from cl.runtime.schema.schema import Schema

from cl.runtime.serialization.string_serializer import StringSerializer


Expand Down Expand Up @@ -63,16 +61,15 @@ def list_panels(cls, request: ListPanelsRequest) -> List[ListPanelsResponseItem]

if handlers_block is not None and handlers_block:
return [
ListPanelsResponseItem(
name=handler.label,
type=cls.get_type(handler)
) for handler in handlers_block if handler.type_ == "Viewer"
ListPanelsResponseItem(name=handler.label, type=cls.get_type(handler))
for handler in handlers_block
if handler.type_ == "Viewer"
]
return []

@classmethod
def get_type(cls, handler: HandlerDeclareDecl) -> str | None:
"""Get type of the handler."""
if handler.type_ == 'Viewer' and handler.name == 'view_self':
return 'Primary'

if handler.type_ == "Viewer" and handler.name == "view_self":
return "Primary"
12 changes: 5 additions & 7 deletions cl/runtime/routers/storage/record_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,12 @@
# limitations under the License.

from __future__ import annotations

import dataclasses
from pydantic import BaseModel
from pydantic import Field
from typing import Any
from typing import Dict
from typing import List

from pydantic import BaseModel
from pydantic import Field
from cl.runtime import Context
from cl.runtime.backend.core.ui_app_state import UiAppState
from cl.runtime.backend.core.ui_app_state_key import UiAppStateKey
Expand Down Expand Up @@ -147,8 +145,7 @@ def get_record(cls, request: RecordRequest) -> RecordResponse:
deserialized_key = UiTypeStateKey(
user=UserKey(username=username or "root"),
type_=TypeDeclKey(
name=type_state_record_type_name,
module=ModuleDeclKey(module_name=type_state_record_module)
name=type_state_record_type_name, module=ModuleDeclKey(module_name=type_state_record_module)
),
)
else:
Expand All @@ -174,7 +171,8 @@ def get_record(cls, request: RecordRequest) -> RecordResponse:

all_handlers.extend(
[
handler_name for handler_decl in handlers_block
handler_name
for handler_decl in handlers_block
if (handler_name := handler_decl.get("Name")) not in all_handlers
]
)
Expand Down
1 change: 0 additions & 1 deletion cl/runtime/routers/storage/save_permanently_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,3 @@ class SavePermanentlyRequest(BaseModel):

with_dependencies: bool = False
"""Flag that indicated whether to include nested dependencies for Dag objects."""

15 changes: 7 additions & 8 deletions cl/runtime/routers/storage/save_permanently_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@

from collections import defaultdict
from pathlib import Path
from typing import Iterable, Type, DefaultDict

from typing import DefaultDict
from typing import Iterable
from typing import Type
from urllib import parse

import pandas as pd
from pydantic import BaseModel

from cl.runtime import Context
from cl.runtime.db.protocols import TRecord
from cl.runtime.file.file_util import FileUtil
Expand Down Expand Up @@ -65,7 +64,7 @@ def _get_extension(cls) -> str:

# TODO (Bohdan): Check if it makes sense to have a config which format/extension to use.
# If not - simplify the code.
return 'csv'
return "csv"

@classmethod
def _get_path_to_save_permanently_folder(cls) -> Path:
Expand All @@ -83,9 +82,9 @@ def _write_records(cls, file_path: Path, records: Iterable[TRecord]) -> None:
serializer = FlatDictSerializer() # TODO (Bohdan): Provide a proper serializer
serialized_records = [serializer.serialize_data(record) for record in records]

if file_extension == 'csv':
if file_extension == "csv":
df = pd.DataFrame([serialized_records])
df.to_csv(file_path, mode='w', index=False, header=True)
df.to_csv(file_path, mode="w", index=False, header=True)
else:
raise ValueError(f"File extension {file_extension} is not supported.")

Expand All @@ -94,7 +93,7 @@ def save_permanently(cls, request: SavePermanentlyRequest) -> "SavePermanentlyRe
"""Save records to the database on the disk."""

for record_type, records in get_type_to_records_map(request).items():
filename = f'{record_type.__name__}.{cls._get_extension()}'
filename = f"{record_type.__name__}.{cls._get_extension()}"
FileUtil.check_valid_filename(filename)
file_path = cls._get_path_to_save_permanently_folder() / filename
file_path.parent.mkdir(parents=True, exist_ok=True)
Expand Down
1 change: 0 additions & 1 deletion cl/runtime/routers/tasks/run_response_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import traceback
from typing import List
from pydantic import BaseModel

from cl.runtime import Context
from cl.runtime.primitive.case_util import CaseUtil
from cl.runtime.records.dataclasses_extensions import missing
Expand Down
6 changes: 3 additions & 3 deletions cl/runtime/settings/api_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

from dataclasses import dataclass
from typing import List

from cl.runtime.settings.settings import Settings


Expand Down Expand Up @@ -113,8 +112,9 @@ def init(self) -> None:
elif isinstance(self.allow_headers, str) or not hasattr(self.allow_headers, "__iter__"):
raise RuntimeError(f"{type(self).__name__} field 'allow_headers' must be a list or None.")

if self.expose_headers is not None and (isinstance(self.expose_headers, str) or
not hasattr(self.expose_headers, "__iter__")):
if self.expose_headers is not None and (
isinstance(self.expose_headers, str) or not hasattr(self.expose_headers, "__iter__")
):
raise RuntimeError(f"{type(self).__name__} field 'expose_headers' must be a list or None.")

if self.max_age is not None and not isinstance(self.max_age, int):
Expand Down
1 change: 0 additions & 1 deletion cl/runtime/tasks/celery/celery_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,3 @@ def submit_task(self, task: TaskKey):
retry=False, # Do not retry in case the task fails
ignore_result=True, # TODO: Do not publish to the Celery result backend
)

10 changes: 5 additions & 5 deletions cl/runtime/tasks/function_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ def _execute(self) -> None:

@classmethod
def create(
cls,
*,
queue: TaskQueueKey,
record_type: Type,
method: Callable,
cls,
*,
queue: TaskQueueKey,
record_type: Type,
method: Callable,
) -> Self:
"""Create from static or class handler method callable."""
raise NotImplementedError()
8 changes: 2 additions & 6 deletions cl/runtime/tasks/process_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,10 @@ def run_start_queue(self) -> None:
# TODO: Use DB queries with filter by queue field
all_tasks = context.load_all(Task)
awaiting_tasks = [
task for task in all_tasks
if task.queue.queue_id == queue_id
and task.status == TaskStatusEnum.AWAITING
task for task in all_tasks if task.queue.queue_id == queue_id and task.status == TaskStatusEnum.AWAITING
]
pending_tasks = [
task for task in all_tasks
if task.queue.queue_id == queue_id
and task.status == TaskStatusEnum.PENDING
task for task in all_tasks if task.queue.queue_id == queue_id and task.status == TaskStatusEnum.PENDING
]

# Awaiting tasks have priority over pending tasks
Expand Down
10 changes: 5 additions & 5 deletions cl/runtime/tasks/static_method_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ def _execute(self) -> None:

@classmethod
def create(
cls,
*,
queue: TaskQueueKey,
record_type: Type,
method_callable: Callable,
cls,
*,
queue: TaskQueueKey,
record_type: Type,
method_callable: Callable,
) -> Self:
"""Create from @staticmethod callable and record type."""

Expand Down
6 changes: 1 addition & 5 deletions cl/runtime/tasks/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,7 @@ def init(self) -> None:
self.task_id = Timestamp.create()
else:
# Otherwise validate
Timestamp.validate(
self.task_id,
value_name="task_id",
data_type="TaskKey"
)
Timestamp.validate(self.task_id, value_name="task_id", data_type="TaskKey")

# Set status and progress_pct if not yet set
if self.status is None:
Expand Down
7 changes: 1 addition & 6 deletions cl/runtime/tasks/task_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

from dataclasses import dataclass
from typing import Type

from cl.runtime.primitive.timestamp import Timestamp
from cl.runtime.records.dataclasses_extensions import missing
from cl.runtime.records.key_mixin import KeyMixin
Expand All @@ -40,11 +39,7 @@ class TaskKey(KeyMixin):
def init(self) -> None:
# Check only if inside a key, will be set automatically if inside a record
if is_key(self):
Timestamp.validate(
self.task_id,
value_name="task_id",
data_type="TaskKey"
)
Timestamp.validate(self.task_id, value_name="task_id", data_type="TaskKey")

@classmethod
def get_key_type(cls) -> Type:
Expand Down
1 change: 0 additions & 1 deletion cl/runtime/tasks/task_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,3 @@ def run_start_queue(self) -> None:
@abstractmethod
def run_stop_queue(self) -> None:
"""Exit after completing all currently executing tasks."""

8 changes: 5 additions & 3 deletions stubs/cl/runtime/configs/stub_runtime_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,24 @@
from cl.runtime.configs.config import Config
from cl.runtime.context.context import Context
from cl.runtime.plots.group_bar_plot import GroupBarPlot
from stubs.cl.runtime import StubDataclassDerivedFromDerivedRecord, StubFileViewers, StubDagViewers
from stubs.cl.runtime import StubDagViewers
from stubs.cl.runtime import StubDataclassComposite
from stubs.cl.runtime import StubDataclassDerivedFromDerivedRecord
from stubs.cl.runtime import StubDataclassDerivedRecord
from stubs.cl.runtime import StubDataclassDictFields
from stubs.cl.runtime import StubDataclassDictListFields
from stubs.cl.runtime import StubDataclassListDictFields
from stubs.cl.runtime import StubDataclassListFields
from stubs.cl.runtime import StubDataclassNestedFields
from stubs.cl.runtime import StubDataclassComposite
from stubs.cl.runtime import StubDataclassOptionalFields
from stubs.cl.runtime import StubDataclassOtherDerivedRecord
from stubs.cl.runtime import StubDataclassPrimitiveFields
from stubs.cl.runtime import StubDataclassRecord
from stubs.cl.runtime import StubDataclassSingleton
from stubs.cl.runtime import StubDataViewers
from stubs.cl.runtime import StubFileViewers
from stubs.cl.runtime import StubHandlers
from stubs.cl.runtime import StubPlotViewers
from stubs.cl.runtime import StubDataViewers


@dataclass(slots=True, kw_only=True)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,3 @@ class StubDataclassNestedFields(StubDataclassRecord):

record_as_key_field: StubDataclassRecordKey = field(default_factory=lambda: StubDataclassRecord())
"""Stub field with key type initialized to record type instance."""

9 changes: 6 additions & 3 deletions stubs/cl/runtime/views/stub_data_viewers.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@
from dataclasses import dataclass
from typing import List
from typing_extensions import Self

from stubs.cl.runtime import StubDataclassRecordKey, StubDataclassRecord, StubDataclassNestedFields, \
StubDataclassListFields, StubDataclassComposite, StubDataclassCompositeKey
from stubs.cl.runtime import StubDataclassComposite
from stubs.cl.runtime import StubDataclassCompositeKey
from stubs.cl.runtime import StubDataclassListFields
from stubs.cl.runtime import StubDataclassNestedFields
from stubs.cl.runtime import StubDataclassRecord
from stubs.cl.runtime import StubDataclassRecordKey
from stubs.cl.runtime.views.stub_viewers import StubViewers
from stubs.cl.runtime.views.stub_viewers_key import StubViewersKey

Expand Down
Loading

0 comments on commit 02b455c

Please sign in to comment.