Skip to content

Commit 7060a90

Browse files
committed
Clean optional and list with hatch fmt
1 parent 8a85ad6 commit 7060a90

File tree

8 files changed

+23
-28
lines changed

8 files changed

+23
-28
lines changed

src/aleph/vm/conf.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from os.path import abspath, exists, isdir, isfile, join
1010
from pathlib import Path
1111
from subprocess import CalledProcessError, check_output
12-
from typing import Any, List, Literal, NewType, Optional
12+
from typing import Any, Literal, NewType
1313

1414
from aleph_message.models import Chain
1515
from aleph_message.models.execution.environment import HypervisorType
@@ -188,21 +188,21 @@ class Settings(BaseSettings):
188188
CONNECTOR_URL = Url("http://localhost:4021")
189189

190190
CACHE_ROOT: Path = Path("/var/cache/aleph/vm")
191-
MESSAGE_CACHE: Optional[Path] = Field(
191+
MESSAGE_CACHE: Path | None = Field(
192192
None,
193193
description="Default to CACHE_ROOT/message",
194194
)
195-
CODE_CACHE: Optional[Path] = Field(None, description="Default to CACHE_ROOT/code")
196-
RUNTIME_CACHE: Optional[Path] = Field(None, description="Default to CACHE_ROOT/runtime")
197-
DATA_CACHE: Optional[Path] = Field(None, description="Default to CACHE_ROOT/data")
195+
CODE_CACHE: Path | None = Field(None, description="Default to CACHE_ROOT/code")
196+
RUNTIME_CACHE: Path | None = Field(None, description="Default to CACHE_ROOT/runtime")
197+
DATA_CACHE: Path | None = Field(None, description="Default to CACHE_ROOT/data")
198198

199199
EXECUTION_ROOT: Path = Path("/var/lib/aleph/vm")
200-
JAILER_BASE_DIRECTORY: Optional[Path] = Field(None, description="Default to EXECUTION_ROOT/jailer")
201-
EXECUTION_DATABASE: Optional[Path] = Field(
200+
JAILER_BASE_DIRECTORY: Path | None = Field(None, description="Default to EXECUTION_ROOT/jailer")
201+
EXECUTION_DATABASE: Path | None = Field(
202202
None, description="Location of database file. Default to EXECUTION_ROOT/executions.sqlite3"
203203
)
204204
EXECUTION_LOG_ENABLED: bool = False
205-
EXECUTION_LOG_DIRECTORY: Optional[Path] = Field(
205+
EXECUTION_LOG_DIRECTORY: Path | None = Field(
206206
None, description="Location of executions log. Default to EXECUTION_ROOT/executions/"
207207
)
208208

@@ -267,12 +267,12 @@ class Settings(BaseSettings):
267267
"with SEV and SEV-ES",
268268
)
269269

270-
CONFIDENTIAL_DIRECTORY: Optional[Path] = Field(
270+
CONFIDENTIAL_DIRECTORY: Path | None = Field(
271271
None,
272272
description="Confidential Computing default directory. Default to EXECUTION_ROOT/confidential",
273273
)
274274

275-
CONFIDENTIAL_SESSION_DIRECTORY: Optional[Path] = Field(None, description="Default to EXECUTION_ROOT/sessions")
275+
CONFIDENTIAL_SESSION_DIRECTORY: Path | None = Field(None, description="Default to EXECUTION_ROOT/sessions")
276276

277277
ENABLE_GPU_SUPPORT: bool = Field(
278278
default=False,

src/aleph/vm/controllers/qemu/instance.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from asyncio import Task
66
from asyncio.subprocess import Process
77
from pathlib import Path
8-
from typing import Generic, List, TypeVar
8+
from typing import Generic, TypeVar
99

1010
import psutil
1111
from aleph_message.models import ItemHash
@@ -38,7 +38,7 @@
3838

3939

4040
class AlephQemuResources(AlephFirecrackerResources):
41-
gpus: List[HostGPU] = []
41+
gpus: list[HostGPU] = []
4242

4343
async def download_runtime(self) -> None:
4444
volume = self.message_content.rootfs

src/aleph/vm/garbage_collector.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ def check_api(item_hash):
9898
f"systemctl status aleph-vm-controller@{item_hash}.service --no-pager",
9999
shell=True,
100100
capture_output=True,
101+
check=False,
101102
)
102103
exit_code = proc_ret.returncode
103104
if exit_code == 0:

src/aleph/vm/models.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from collections.abc import Callable, Coroutine
77
from dataclasses import dataclass
88
from datetime import datetime, timezone
9-
from typing import List
109

1110
from aleph_message.models import (
1211
ExecutableContent,
@@ -76,7 +75,7 @@ class VmExecution:
7675
AlephProgramResources | AlephInstanceResources | AlephQemuResources | AlephQemuConfidentialInstance | None
7776
) = None
7877
vm: AlephFirecrackerExecutable | AlephQemuInstance | AlephQemuConfidentialInstance | None = None
79-
gpus: List[HostGPU] = []
78+
gpus: list[HostGPU] = []
8079

8180
times: VmExecutionTimes
8281

@@ -223,7 +222,7 @@ async def prepare(self) -> None:
223222
self.times.prepared_at = datetime.now(tz=timezone.utc)
224223
self.resources = resources
225224

226-
def prepare_gpus(self, available_gpus: List[GpuDevice]) -> None:
225+
def prepare_gpus(self, available_gpus: list[GpuDevice]) -> None:
227226
gpus = []
228227
if self.message.requirements and self.message.requirements.gpu:
229228
for gpu in self.message.requirements.gpu:

src/aleph/vm/orchestrator/resources.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import math
22
from datetime import datetime, timezone
33
from functools import lru_cache
4-
from typing import List, Optional
54

65
import cpuinfo
76
import psutil
@@ -77,8 +76,8 @@ class MachineProperties(BaseModel):
7776

7877

7978
class GpuProperties(BaseModel):
80-
devices: Optional[List[GpuDevice]]
81-
available_devices: Optional[List[GpuDevice]]
79+
devices: list[GpuDevice] | None
80+
available_devices: list[GpuDevice] | None
8281

8382

8483
class MachineUsage(BaseModel):

src/aleph/vm/pool.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import logging
66
from collections.abc import Iterable
77
from datetime import datetime, timezone
8-
from typing import List
98

109
from aleph_message.models import (
1110
Chain,
@@ -45,7 +44,7 @@ class VmPool:
4544
snapshot_manager: SnapshotManager | None = None
4645
systemd_manager: SystemDManager
4746
creation_lock: asyncio.Lock
48-
gpus: List[GpuDevice] = []
47+
gpus: list[GpuDevice] = []
4948

5049
def __init__(self, loop: asyncio.AbstractEventLoop):
5150
self.executions = {}
@@ -249,7 +248,7 @@ async def load_persistent_executions(self):
249248
if execution.is_running:
250249
# TODO: Improve the way that we re-create running execution
251250
# Load existing GPUs assigned to VMs
252-
execution.gpus = parse_raw_as(List[HostGPU], saved_execution.gpus) if saved_execution.gpus else []
251+
execution.gpus = parse_raw_as(list[HostGPU], saved_execution.gpus) if saved_execution.gpus else []
253252
# Load and instantiate the rest of resources and already assigned GPUs
254253
await execution.prepare()
255254
if self.network:
@@ -303,7 +302,7 @@ def get_instance_executions(self) -> Iterable[VmExecution]:
303302
)
304303
return executions or []
305304

306-
def get_available_gpus(self) -> List[GpuDevice]:
305+
def get_available_gpus(self) -> list[GpuDevice]:
307306
available_gpus = []
308307
for gpu in self.gpus:
309308
used = False

src/aleph/vm/resources.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import subprocess
22
from enum import Enum
3-
from typing import List, Optional
43

54
from aleph_message.models import HashableModel
65
from pydantic import BaseModel, Extra, Field
76

8-
from aleph.vm.conf import settings
97
from aleph.vm.orchestrator.utils import get_compatible_gpus
108

119

@@ -97,7 +95,7 @@ def is_kernel_enabled_gpu(pci_host: str) -> bool:
9795
return False
9896

9997

100-
def parse_gpu_device_info(line: str) -> Optional[GpuDevice]:
98+
def parse_gpu_device_info(line: str) -> GpuDevice | None:
10199
"""Parse GPU device info from a line of lspci output."""
102100

103101
pci_host, device = line.split(' "', maxsplit=1)
@@ -134,7 +132,7 @@ def parse_gpu_device_info(line: str) -> Optional[GpuDevice]:
134132
)
135133

136134

137-
def get_gpu_devices() -> Optional[List[GpuDevice]]:
135+
def get_gpu_devices() -> list[GpuDevice] | None:
138136
"""Get GPU info using lspci command."""
139137

140138
result = subprocess.run(["lspci", "-mmnnn"], capture_output=True, text=True, check=True)

src/aleph/vm/storage.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import logging
1111
import re
1212
import sys
13-
import uuid
1413
from datetime import datetime, timezone
1514
from pathlib import Path
1615
from shutil import copy2, make_archive
@@ -382,7 +381,7 @@ async def get_volume_path(volume: MachineVolume, namespace: str) -> Path:
382381
raise NotImplementedError(msg)
383382
if not re.match(r"^[\w\-_/]+$", volume_name):
384383
# Sanitize volume names
385-
logger.debug(f"Invalid values for volume name: {repr(volume_name)} detected, sanitizing")
384+
logger.debug(f"Invalid values for volume name: {volume_name!r} detected, sanitizing")
386385
volume_name = re.sub(r"[^\w\-_]", "_", volume_name)
387386
(Path(settings.PERSISTENT_VOLUMES_DIR) / namespace).mkdir(exist_ok=True)
388387
if volume.parent:

0 commit comments

Comments
 (0)