Skip to content

Commit b5fbb12

Browse files
committed
[dev] Linting
1 parent 9a96d72 commit b5fbb12

File tree

5 files changed

+64
-58
lines changed

5 files changed

+64
-58
lines changed

sebs/aws/aws.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,12 @@ def package_code(
132132
if container_deployment:
133133
# build base image and upload to ECR
134134
_, container_uri = self.ecr_client.build_base_image(
135-
directory, language_name, language_version, architecture, benchmark, is_cached
135+
directory,
136+
language,
137+
language_version,
138+
architecture,
139+
benchmark,
140+
is_cached,
136141
)
137142

138143
CONFIG_FILES = {
@@ -675,4 +680,3 @@ def cloud_runtime(self, language: Language, language_version: str):
675680
return "provided.al2"
676681
else:
677682
raise NotImplementedError()
678-

sebs/benchmark.py

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
from sebs.faas.resources import SystemResources
1717
from sebs.utils import find_benchmark, project_absolute_path, LoggingBase
1818
from sebs.types import BenchmarkModule, Language
19-
from sebs.types import Language
2019
from typing import TYPE_CHECKING
2120

2221
if TYPE_CHECKING:
@@ -25,7 +24,11 @@
2524

2625
class BenchmarkConfig:
2726
def __init__(
28-
self, timeout: int, memory: int, languages: List["Language"], modules: List[BenchmarkModule]
27+
self,
28+
timeout: int,
29+
memory: int,
30+
languages: List["Language"],
31+
modules: List[BenchmarkModule],
2932
):
3033
self._timeout = timeout
3134
self._memory = memory
@@ -647,7 +650,12 @@ def build(
647650
"Using cached benchmark {} at {}".format(self.benchmark, self.code_location)
648651
)
649652
if self.container_deployment:
650-
return False, self.code_location, self.container_deployment, self.container_uri
653+
return (
654+
False,
655+
self.code_location,
656+
self.container_deployment,
657+
self.container_uri,
658+
)
651659

652660
return False, self.code_location, self.container_deployment, ""
653661

@@ -698,7 +706,12 @@ def build(
698706
self._cache_client.add_code_package(self._deployment_name, self)
699707
self.query_cache()
700708

701-
return True, self._code_location, self._container_deployment, self._container_uri
709+
return (
710+
True,
711+
self._code_location,
712+
self._container_deployment,
713+
self._container_uri,
714+
)
702715

703716
"""
704717
Locates benchmark input generator, inspect how many storage buckets
@@ -711,9 +724,11 @@ def build(
711724
"""
712725

713726
def prepare_input(
714-
self, system_resources: SystemResources, size: str, replace_existing: bool = False
727+
self,
728+
system_resources: SystemResources,
729+
size: str,
730+
replace_existing: bool = False,
715731
):
716-
717732
"""
718733
Handle object storage buckets.
719734
"""
@@ -740,7 +755,10 @@ def prepare_input(
740755
if hasattr(self._benchmark_input_module, "allocate_nosql"):
741756

742757
nosql_storage = system_resources.get_nosql_storage()
743-
for name, table_properties in self._benchmark_input_module.allocate_nosql().items():
758+
for (
759+
name,
760+
table_properties,
761+
) in self._benchmark_input_module.allocate_nosql().items():
744762
nosql_storage.create_benchmark_tables(
745763
self._benchmark,
746764
name,
@@ -757,7 +775,13 @@ def prepare_input(
757775
# storage.allocate_buckets(self.benchmark, buckets)
758776
# Get JSON and upload data as required by benchmark
759777
input_config = self._benchmark_input_module.generate_input(
760-
self._benchmark_data_path, size, bucket, input, output, storage_func, nosql_func
778+
self._benchmark_data_path,
779+
size,
780+
bucket,
781+
input,
782+
output,
783+
storage_func,
784+
nosql_func,
761785
)
762786

763787
# Cache only once we data is in the cloud.

sebs/faas/container.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,7 @@ def find_image(self, repository_name, image_tag) -> bool:
5353
else:
5454
try:
5555
# default version requires pulling for an image
56-
self.docker_client.images.pull(
57-
repository=repository_name, tag=image_tag
58-
)
56+
self.docker_client.images.pull(repository=repository_name, tag=image_tag)
5957
return True
6058
except docker.errors.NotFound:
6159
return False
@@ -86,9 +84,7 @@ def show_progress(self, txt: str, progress: Progress, layer_tasks: dict):
8684
elif any(x in status for x in ["Layer already exists", "Pushed"]):
8785
if id_ in layer_tasks:
8886
# Complete the task
89-
progress.update(
90-
layer_tasks[id_], completed=progress.tasks[layer_tasks[id_]].total
91-
)
87+
progress.update(layer_tasks[id_], completed=progress.tasks[layer_tasks[id_]].total)
9288

9389
elif "error" in line:
9490
raise Exception(line["error"])
@@ -119,9 +115,7 @@ def push_image(self, repository_uri, image_tag):
119115

120116
for val in ret:
121117
if "error" in val:
122-
self.logging.error(
123-
f"Failed to push the image to registry {repository_uri}"
124-
)
118+
self.logging.error(f"Failed to push the image to registry {repository_uri}")
125119
raise RuntimeError(val)
126120

127121
except docker.errors.APIError as e:
@@ -184,9 +178,7 @@ def build_base_image(
184178
os.makedirs(build_dir, exist_ok=True)
185179

186180
shutil.copy(
187-
os.path.join(
188-
DOCKER_DIR, self.name(), language.value, "Dockerfile.function"
189-
),
181+
os.path.join(DOCKER_DIR, self.name(), language.value, "Dockerfile.function"),
190182
os.path.join(build_dir, "Dockerfile"),
191183
)
192184
for fn in os.listdir(directory):
@@ -200,9 +192,7 @@ def build_base_image(
200192
builder_image = self.system_config.benchmark_base_images(
201193
self.name(), language.value, architecture
202194
)[language_version]
203-
self.logging.info(
204-
f"Build the benchmark base image {repository_name}:{image_tag}."
205-
)
195+
self.logging.info(f"Build the benchmark base image {repository_name}:{image_tag}.")
206196

207197
isa = platform.processor()
208198
if (isa == "x86_64" and architecture != "x64") or (

sebs/faas/function.py

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -134,15 +134,11 @@ def __init__(self):
134134
self.billing = ExecutionBilling()
135135

136136
@staticmethod
137-
def from_times(
138-
client_time_begin: datetime, client_time_end: datetime
139-
) -> "ExecutionResult":
137+
def from_times(client_time_begin: datetime, client_time_end: datetime) -> "ExecutionResult":
140138
ret = ExecutionResult()
141139
ret.times.client_begin = client_time_begin
142140
ret.times.client_end = client_time_end
143-
ret.times.client = int(
144-
(client_time_end - client_time_begin) / timedelta(microseconds=1)
145-
)
141+
ret.times.client = int((client_time_end - client_time_begin) / timedelta(microseconds=1))
146142
return ret
147143

148144
def parse_benchmark_output(self, output: dict):
@@ -192,9 +188,7 @@ def get(name: str) -> "Trigger.TriggerType":
192188
return member
193189
raise Exception("Unknown trigger type {}".format(member))
194190

195-
def _http_invoke(
196-
self, payload: dict, url: str, verify_ssl: bool = True
197-
) -> ExecutionResult:
191+
def _http_invoke(self, payload: dict, url: str, verify_ssl: bool = True) -> ExecutionResult:
198192
import pycurl
199193
from io import BytesIO
200194

@@ -248,9 +242,7 @@ def _http_invoke(
248242
self.logging.error("Output: {}".format(data.getvalue().decode()))
249243
else:
250244
self.logging.error("No output provided!")
251-
raise RuntimeError(
252-
f"Failed invocation of function! Output: {data.getvalue().decode()}"
253-
)
245+
raise RuntimeError(f"Failed invocation of function! Output: {data.getvalue().decode()}")
254246

255247
# FIXME: 3.7+, future annotations
256248
@staticmethod
@@ -287,9 +279,7 @@ def serialize(self) -> dict:
287279

288280
@staticmethod
289281
def deserialize(config: dict) -> Runtime:
290-
return Runtime(
291-
language=Language.deserialize(config["language"]), version=config["version"]
292-
)
282+
return Runtime(language=Language.deserialize(config["language"]), version=config["version"])
293283

294284

295285
T = TypeVar("T", bound="FunctionConfig")
@@ -304,12 +294,8 @@ class FunctionConfig:
304294

305295
@staticmethod
306296
def _from_benchmark(benchmark: Benchmark, obj_type: Type[T]) -> T:
307-
runtime = Runtime(
308-
language=benchmark.language, version=benchmark.language_version
309-
)
310-
architecture = Architecture.deserialize(
311-
benchmark._experiment_config._architecture
312-
)
297+
runtime = Runtime(language=benchmark.language, version=benchmark.language_version)
298+
architecture = Architecture.deserialize(benchmark._experiment_config._architecture)
313299
cfg = obj_type(
314300
timeout=benchmark.benchmark_config.timeout,
315301
memory=benchmark.benchmark_config.memory,
@@ -379,11 +365,7 @@ def updated_code(self, val: bool):
379365
self._updated_code = val
380366

381367
def triggers_all(self) -> List[Trigger]:
382-
return [
383-
trig
384-
for trigger_type, triggers in self._triggers.items()
385-
for trig in triggers
386-
]
368+
return [trig for trigger_type, triggers in self._triggers.items() for trig in triggers]
387369

388370
def triggers(self, trigger_type: Trigger.TriggerType) -> List[Trigger]:
389371
try:
@@ -404,9 +386,7 @@ def serialize(self) -> dict:
404386
"benchmark": self._benchmark,
405387
"config": self.config.serialize(),
406388
"triggers": [
407-
obj.serialize()
408-
for t_type, triggers in self._triggers.items()
409-
for obj in triggers
389+
obj.serialize() for t_type, triggers in self._triggers.items() for obj in triggers
410390
],
411391
}
412392

sebs/openwhisk/openwhisk.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ def __init__(
4444
self.logging_handlers = logger_handlers
4545

4646
self.container_client = OpenWhiskContainer(
47-
self.system_config, self.config, self.docker_client, self.config.experimentalManifest
47+
self.system_config,
48+
self.config,
49+
self.docker_client,
50+
self.config.experimentalManifest,
4851
)
4952

5053
if self.config.resources.docker_username:
@@ -108,7 +111,7 @@ def package_code(
108111
# Regardless of Docker image status, we need to create .zip file
109112
# to allow registration of function with OpenWhisk
110113
_, image_uri = self.container_client.build_base_image(
111-
directory, language.value, language_version, architecture, benchmark, is_cached
114+
directory, language, language_version, architecture, benchmark, is_cached
112115
)
113116

114117
# We deploy Minio config in code package since this depends on local
@@ -121,7 +124,9 @@ def package_code(
121124

122125
benchmark_archive = os.path.join(directory, f"{benchmark}.zip")
123126
subprocess.run(
124-
["zip", benchmark_archive] + package_config, stdout=subprocess.DEVNULL, cwd=directory
127+
["zip", benchmark_archive] + package_config,
128+
stdout=subprocess.DEVNULL,
129+
cwd=directory,
125130
)
126131
self.logging.info(f"Created {benchmark_archive} archive")
127132
bytes_size = os.path.getsize(benchmark_archive)
@@ -231,7 +236,10 @@ def create_function(
231236
)
232237
function_cfg.docker_image = docker_image
233238
res = OpenWhiskFunction(
234-
func_name, code_package.benchmark, code_package.hash, function_cfg
239+
func_name,
240+
code_package.benchmark,
241+
code_package.hash,
242+
function_cfg,
235243
)
236244
except subprocess.CalledProcessError as e:
237245
self.logging.error(f"Cannot create action {func_name}.")

0 commit comments

Comments
 (0)