Skip to content

Commit

Permalink
fix code quality with ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
MHHukiewitz committed Dec 5, 2023
1 parent e1c0f47 commit 7012170
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 32 deletions.
16 changes: 5 additions & 11 deletions aleph_message/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,7 @@
from hashlib import sha256
from json import JSONDecodeError
from pathlib import Path
from typing import (
Any,
Dict,
List,
Literal,
Optional,
Type,
Union, TypeVar, cast,
)
from typing import Any, Dict, List, Literal, Optional, Type, TypeVar, Union, cast

from pydantic import BaseModel, Extra, Field, validator
from typing_extensions import TypeAlias
Expand Down Expand Up @@ -204,7 +196,9 @@ class BaseMessage(BaseModel):
size: Optional[int] = Field(
default=None, description="Size of the content"
) # Almost always present
time: datetime.datetime = Field(description="Unix timestamp or datetime when the message was published")
time: datetime.datetime = Field(
description="Unix timestamp or datetime when the message was published"
)
item_type: ItemType = Field(description="Storage method used for the content")
item_content: Optional[str] = Field(
default=None,
Expand Down Expand Up @@ -343,7 +337,7 @@ class InstanceMessage(BaseMessage):
]


T = TypeVar('T', bound=AlephMessage)
T = TypeVar("T", bound=AlephMessage)

AlephMessageType: TypeAlias = Type[T]

Expand Down
8 changes: 2 additions & 6 deletions aleph_message/models/execution/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,9 @@

from pydantic import Field

from .environment import (
FunctionEnvironment,
HostRequirements,
MachineResources,
)
from .volume import MachineVolume
from ..abstract import BaseContent, HashableModel
from .environment import FunctionEnvironment, HostRequirements, MachineResources
from .volume import MachineVolume


class BaseExecutableContent(HashableModel, BaseContent, ABC):
Expand Down
6 changes: 3 additions & 3 deletions aleph_message/models/execution/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ class CpuProperties(HashableModel):
class Config:
extra = Extra.forbid

class HypervisorType(str, Enum):
qemu = 'qemu'
firecracker = 'firecracker'

class HypervisorType(str, Enum):
qemu = "qemu"
firecracker = "firecracker"


class FunctionEnvironment(HashableModel):
Expand Down
8 changes: 3 additions & 5 deletions aleph_message/models/execution/instance.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
from __future__ import annotations

from typing import Any, Dict

from pydantic import Field

from aleph_message.models.abstract import HashableModel
from aleph_message.models.item_hash import ItemHash

from .abstract import BaseExecutableContent
from .volume import VolumePersistence, PersistentVolumeSizeMib, ParentVolume
from .volume import ParentVolume, PersistentVolumeSizeMib, VolumePersistence


class RootfsVolume(HashableModel):
Expand All @@ -17,6 +15,7 @@ class RootfsVolume(HashableModel):
The root file system of an instance is built as a copy of a reference image, named parent
image. The user determines a custom size and persistence model.
"""

parent: ParentVolume
persistence: VolumePersistence
# Use the same size constraint as persistent volumes for now
Expand All @@ -29,4 +28,3 @@ class InstanceContent(BaseExecutableContent):
rootfs: RootfsVolume = Field(
description="Root filesystem of the system, will be booted by the kernel"
)

2 changes: 1 addition & 1 deletion aleph_message/models/execution/program.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

from pydantic import Field

from .environment import FunctionTriggers
from ..abstract import HashableModel
from ..item_hash import ItemHash
from .abstract import BaseExecutableContent
from .base import Encoding, MachineType
from .environment import FunctionTriggers


class FunctionRuntime(HashableModel):
Expand Down
4 changes: 2 additions & 2 deletions aleph_message/models/execution/volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

from abc import ABC, abstractmethod
from enum import Enum
from typing import Literal, Optional, Type, Union
from typing import Literal, Optional, Union

from pydantic import ConstrainedInt, Extra, conint
from pydantic import ConstrainedInt, Extra

from ...utils import Gigabytes, gigabyte_to_mebibyte
from ..abstract import HashableModel
Expand Down
8 changes: 4 additions & 4 deletions aleph_message/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from os import listdir
from os.path import isdir, join
from pathlib import Path
from typing import Dict

import pytest
import requests
Expand All @@ -13,6 +12,7 @@
from aleph_message.exceptions import UnknownHashError
from aleph_message.models import (
AggregateMessage,
AlephMessage,
ForgetMessage,
InstanceMessage,
ItemType,
Expand All @@ -25,7 +25,7 @@
create_message_from_file,
create_message_from_json,
create_new_message,
parse_message, AlephMessage,
parse_message,
)
from aleph_message.tests.download_messages import MESSAGES_STORAGE_PATH

Expand Down Expand Up @@ -289,10 +289,10 @@ def test_create_new_message():
assert new_message_1
assert new_message_1.type == MessageType.post
# Check that the time was converted to a datetime
assert new_message_1.time.isoformat() == '2021-07-07T10:04:47.017000+00:00'
assert new_message_1.time.isoformat() == "2021-07-07T10:04:47.017000+00:00"

# The time field can be either a float or a datetime as string
message_dict["time"] = '2021-07-07T10:04:47.017000+00:00'
message_dict["time"] = "2021-07-07T10:04:47.017000+00:00"
new_message_2 = create_message_from_json(
json.dumps(message_dict), factory=PostMessage
)
Expand Down

0 comments on commit 7012170

Please sign in to comment.