Skip to content

Commit 3b6c4fd

Browse files
committed
[local] Linting
1 parent d82ca9b commit 3b6c4fd

File tree

3 files changed

+21
-17
lines changed

3 files changed

+21
-17
lines changed

sebs/local/config.py

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import json
22

3-
from typing import cast, Optional
3+
from typing import cast, Optional, Set
44

55
from sebs.cache import Cache
66
from sebs.faas.config import Config, Credentials, Resources
@@ -28,7 +28,7 @@ def __init__(self, storage_cfg: Optional[MinioConfig] = None):
2828
self._path: str = ""
2929
super().__init__(name="local")
3030
self._storage = storage_cfg
31-
self._allocated_ports = set()
31+
self._allocated_ports: Set[int] = set()
3232

3333
@property
3434
def storage_config(self) -> Optional[MinioConfig]:
@@ -39,27 +39,33 @@ def allocated_ports(self) -> set:
3939
return self._allocated_ports
4040

4141
def serialize(self) -> dict:
42-
out = {
43-
"allocated_ports": list(self._allocated_ports),
44-
"storage": self._storage.serialize()
45-
}
42+
out: dict = {}
43+
out["allocated_ports"] = list(self._allocated_ports)
44+
if self._storage is not None:
45+
out["storage"] = self._storage.serialize()
4646
return out
4747

4848
@staticmethod
4949
def initialize(res: Resources, config: dict):
5050

51+
resources = cast(LocalResources, res)
5152
# Check for new config
5253
if "storage" in config:
53-
res._storage = MinioConfig.deserialize(config["storage"])
54-
res.logging.info("Using user-provided configuration of storage for local containers.")
54+
resources._storage = MinioConfig.deserialize(config["storage"])
55+
resources.logging.info(
56+
"Using user-provided configuration of storage for local containers."
57+
)
5558

5659
if "allocated_ports" in config:
57-
res._allocated_ports = set(config["allocated_ports"])
60+
resources._allocated_ports = set(config["allocated_ports"])
5861

5962
def update_cache(self, cache: Cache):
6063
super().update_cache(cache)
61-
cache.update_config(val=list(self._allocated_ports), keys=["local", "resources", "allocated_ports"])
62-
self._storage.update_cache(["local", "resources", "storage"], cache)
64+
cache.update_config(
65+
val=list(self._allocated_ports), keys=["local", "resources", "allocated_ports"]
66+
)
67+
if self._storage is not None:
68+
self._storage.update_cache(["local", "resources", "storage"], cache)
6369

6470
@staticmethod
6571
def deserialize(config: dict, cache: Cache, handlers: LoggingHandlers) -> Resources:
@@ -116,11 +122,7 @@ def deserialize(config: dict, cache: Cache, handlers: LoggingHandlers) -> Config
116122
return config_obj
117123

118124
def serialize(self) -> dict:
119-
out = {
120-
"name": "local",
121-
"region": self._region,
122-
"resources": self._resources.serialize()
123-
}
125+
out = {"name": "local", "region": self._region, "resources": self._resources.serialize()}
124126
return out
125127

126128
def update_cache(self, cache: Cache):

sebs/local/local.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ def create_function(self, code_package: Benchmark, func_name: str) -> "LocalFunc
222222
)
223223

224224
container_kwargs["command"] = f"/bin/bash /sebs/run_server.sh {port}"
225-
container_kwargs["ports"] = {f'{port}/tcp': port}
225+
container_kwargs["ports"] = {f"{port}/tcp": port}
226226

227227
container = self._docker_client.containers.run(**container_kwargs)
228228

sebs/utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,10 +252,12 @@ def logging_handlers(self, handlers: LoggingHandlers):
252252
def has_platform(name: str) -> bool:
253253
return os.environ.get(f"SEBS_WITH_{name.upper()}", "False").lower() == "true"
254254

255+
255256
# Check if the system is Linux and that it's not WSL
256257
def is_linux() -> bool:
257258
return platform.system() == "Linux" and "microsoft" not in platform.release().lower()
258259

260+
259261
def catch_interrupt():
260262

261263
import signal

0 commit comments

Comments
 (0)