Skip to content

Commit 9675d0a

Browse files
committed
Black Lint fixes
1 parent 7123e63 commit 9675d0a

10 files changed

+137
-90
lines changed

iib/common/pydantic_models.py

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,14 @@
3737

3838

3939
class PydanticModel(BaseModel):
40-
4140
@classmethod
4241
def _get_all_keys_to_check_in_db(cls):
42+
"""Class that returns request specific keys to check."""
4343
raise NotImplementedError("Not implemented")
4444

4545
def get_keys_to_check_in_db(self):
4646
"""Filter keys, which need to be checked in db. Return only a keys that are set to values."""
47-
return [
48-
k for k in self._get_all_keys_to_check_in_db() if getattr(self, k, None)
49-
]
47+
return [k for k in self._get_all_keys_to_check_in_db() if getattr(self, k, None)]
5048

5149

5250
class AddPydanticModel(PydanticModel):
@@ -66,14 +64,16 @@ class AddPydanticModel(PydanticModel):
6664
AfterValidator(images_format_check),
6765
]
6866
cnr_token: Optional[SecretStr] = None # deprecated
69-
check_related_images: Optional[bool] = None # old request without this parameter will not have False but None
67+
# TODO remove this comment -> old request without this parameter will not have False but None
68+
check_related_images: Optional[bool] = None
7069
deprecation_list: Annotated[
7170
Optional[List[str]],
7271
AfterValidator(get_unique_deprecation_list_items),
7372
AfterValidator(images_format_check),
7473
] = [] # deprecated
7574
distribution_scope: Annotated[
76-
Optional[DISTRIBUTION_SCOPE_LITERAL], BeforeValidator(distribution_scope_lower),
75+
Optional[DISTRIBUTION_SCOPE_LITERAL],
76+
BeforeValidator(distribution_scope_lower),
7777
] = None
7878
force_backport: Optional[bool] = False # deprecated
7979
from_index: Annotated[str, AfterValidator(image_format_check)]
@@ -102,7 +102,7 @@ def verify_graph_update_mode_with_index_image(self) -> 'AddPydanticModel':
102102
@model_validator(mode='after')
103103
def from_index_needed_if_no_bundles(self) -> 'AddPydanticModel':
104104
"""
105-
Check if no bundles and `from_index is specified
105+
Check if no bundles and `from_index is specified.
106106
107107
if no bundles and no from index then an empty index will be created which is a no-op
108108
"""
@@ -113,7 +113,7 @@ def from_index_needed_if_no_bundles(self) -> 'AddPydanticModel':
113113
# TODO remove this comment -> Validator from RequestADD class
114114
@model_validator(mode='after')
115115
def bundles_needed_with_check_related_images(self) -> 'AddPydanticModel':
116-
"""Verify that `check_related_images` is specified when bundles are specified"""
116+
"""Verify that `check_related_images` is specified when bundles are specified."""
117117
if self.check_related_images and not self.bundles:
118118
raise ValidationError(
119119
'"check_related_images" must be specified only when bundles are specified'
@@ -123,7 +123,6 @@ def bundles_needed_with_check_related_images(self) -> 'AddPydanticModel':
123123
def get_json_for_request(self):
124124
"""Return json with the parameters we store in the db."""
125125
return self.model_dump(
126-
# include=["deprecation_list"],
127126
exclude=[
128127
"add_arches",
129128
"build_tags",
@@ -135,7 +134,6 @@ def get_json_for_request(self):
135134
exclude_none=True,
136135
)
137136

138-
139137
def _get_all_keys_to_check_in_db(self):
140138
return ["binary_image", "bundles", "deprecation_list", "from_index"]
141139

@@ -150,7 +148,8 @@ class RmPydanticModel(PydanticModel):
150148
] = None
151149
build_tags: Optional[List[str]] = []
152150
distribution_scope: Annotated[
153-
Optional[DISTRIBUTION_SCOPE_LITERAL], BeforeValidator(distribution_scope_lower),
151+
Optional[DISTRIBUTION_SCOPE_LITERAL],
152+
BeforeValidator(distribution_scope_lower),
154153
] = None
155154
from_index: Annotated[str, AfterValidator(image_format_check)]
156155
operators: Annotated[List[str], AfterValidator(length_validator)]
@@ -167,7 +166,12 @@ def verify_overwrite_from_index_token(self) -> 'RmPydanticModel':
167166
def get_json_for_request(self):
168167
"""Return json with the parameters we store in the db."""
169168
return self.model_dump(
170-
exclude=["add_arches", "build_tags", "overwrite_from_index", "overwrite_from_index_token"],
169+
exclude=[
170+
"add_arches",
171+
"build_tags",
172+
"overwrite_from_index",
173+
"overwrite_from_index_token",
174+
],
171175
exclude_none=True,
172176
)
173177

@@ -228,10 +232,11 @@ class MergeIndexImagePydanticModel(PydanticModel):
228232
AfterValidator(images_format_check),
229233
] = []
230234
distribution_scope: Annotated[
231-
Optional[DISTRIBUTION_SCOPE_LITERAL], BeforeValidator(distribution_scope_lower),
235+
Optional[DISTRIBUTION_SCOPE_LITERAL],
236+
BeforeValidator(distribution_scope_lower),
232237
] = None
233238
graph_update_mode: Optional[GRAPH_MODE_LITERAL] = None
234-
overwrite_target_index: Optional[bool] = False # Why do we need this bool? Isn't the token enough?
239+
overwrite_target_index: Optional[bool] = False
235240
overwrite_target_index_token: Optional[SecretStr] = None
236241
source_from_index: Annotated[str, AfterValidator(image_format_check)]
237242
target_index: Annotated[Optional[str], AfterValidator(image_format_check)] = None
@@ -260,7 +265,13 @@ def get_json_for_request(self):
260265
)
261266

262267
def _get_all_keys_to_check_in_db(self):
263-
return ["binary_image", "deprecation_list", "source_from_index", "target_index", "target_index"]
268+
return [
269+
"binary_image",
270+
"deprecation_list",
271+
"source_from_index",
272+
"target_index",
273+
"target_index",
274+
]
264275

265276

266277
class CreateEmptyIndexPydanticModel(PydanticModel):
@@ -276,8 +287,10 @@ class CreateEmptyIndexPydanticModel(PydanticModel):
276287
AfterValidator(image_format_check),
277288
AfterValidator(length_validator),
278289
]
279-
labels: Optional[Dict[str, str]] = None # old request without this parameter will not have empty labels
280-
output_fbc: Optional[bool] = None # old request without this parameter will not have empty output_fbc
290+
# TODO (remove comment) old request without this parameter will not have empty labels
291+
labels: Optional[Dict[str, str]] = None
292+
# TODO (remove comment) old request without this parameter will not have empty output_fbc
293+
output_fbc: Optional[bool] = None
281294

282295
def get_json_for_request(self):
283296
"""Return json with the parameters we store in the db."""
@@ -305,7 +318,6 @@ def get_json_for_request(self):
305318
exclude_none=True,
306319
)
307320

308-
309321
def _get_all_keys_to_check_in_db(self):
310322
return ["parent_bundle_image"]
311323

@@ -317,15 +329,17 @@ class FbcOperationsPydanticModel(PydanticModel):
317329
AfterValidator(image_format_check),
318330
AfterValidator(binary_image_check),
319331
] = None
332+
# TODO (remove comment) old request without this parameter will not have empty list but None
320333
bundles: Annotated[
321334
Optional[List[str]],
322335
AfterValidator(length_validator),
323336
AfterValidator(get_unique_bundles),
324337
AfterValidator(images_format_check),
325-
] = None # old request without this parameter will not have empty list but None
338+
] = None
326339
build_tags: Optional[List[str]] = []
327340
distribution_scope: Annotated[
328-
Optional[DISTRIBUTION_SCOPE_LITERAL], BeforeValidator(distribution_scope_lower),
341+
Optional[DISTRIBUTION_SCOPE_LITERAL],
342+
BeforeValidator(distribution_scope_lower),
329343
] = None
330344
fbc_fragment: Annotated[
331345
str,
@@ -349,7 +363,12 @@ def verify_overwrite_from_index_token(self) -> 'FbcOperationsPydanticModel':
349363
def get_json_for_request(self):
350364
"""Return json with the parameters we store in the db."""
351365
return self.model_dump(
352-
exclude=["add_arches", "build_tags", "overwrite_from_index", "overwrite_from_index_token"],
366+
exclude=[
367+
"add_arches",
368+
"build_tags",
369+
"overwrite_from_index",
370+
"overwrite_from_index_token",
371+
],
353372
exclude_none=True,
354373
)
355374

iib/common/pydantic_utils.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@
1515
# TODO add regex in future to not allow following values ":s", "s:", ":"?
1616
def image_format_check(image_name: str) -> str:
1717
if '@' not in image_name and ':' not in image_name:
18-
raise ValidationError(
19-
f'Image {image_name} should have a tag or a digest specified.'
20-
)
18+
raise ValidationError(f'Image {image_name} should have a tag or a digest specified.')
2119
return image_name
2220

2321

@@ -48,7 +46,10 @@ def get_unique_deprecation_list_items(deprecation_list: Optional[List[str]]) ->
4846
return list(set(deprecation_list))
4947

5048

51-
def validate_graph_mode_index_image(graph_update_mode: str, index_image: str) -> 'MergeIndexImageRequestPayload':
49+
def validate_graph_mode_index_image(
50+
graph_update_mode: str,
51+
index_image: str,
52+
) -> 'MergeIndexImageRequestPayload':
5253
"""
5354
Validate graph mode and check if index image is allowed to use different graph mode.
5455
@@ -57,9 +58,9 @@ def validate_graph_mode_index_image(graph_update_mode: str, index_image: str) ->
5758
:raises: ValidationError when incorrect graph_update_mode is set
5859
:raises: Forbidden when graph_mode can't be used for given index image
5960
"""
60-
6161
if graph_update_mode:
62-
allowed_from_indexes: List[str] = ["REMOVE_#:r"] # current_app.config['IIB_GRAPH_MODE_INDEX_ALLOW_LIST']
62+
# TODO remove this comment, replace value with current_app.config['IIB_GRAPH_MODE_INDEX_ALLOW_LIST']
63+
allowed_from_indexes: List[str] = ["REMOVE_#:r"]
6364
if index_image not in allowed_from_indexes:
6465
raise Forbidden(
6566
'"graph_update_mode" can only be used on the'
@@ -70,9 +71,7 @@ def validate_graph_mode_index_image(graph_update_mode: str, index_image: str) ->
7071

7172
# RequestIndexImageMixin
7273
def from_index_add_arches(model: 'AddRequestPydanticModel') -> 'AddRequestPydanticModel':
73-
"""
74-
Check if both `from_index` and `add_arches` are not specified
75-
"""
74+
"""Check if both `from_index` and `add_arches` are not specified."""
7675
if not model.from_index and not model.add_arches:
7776
raise ValidationError('One of "from_index" or "add_arches" must be specified')
7877
return model
@@ -81,7 +80,7 @@ def from_index_add_arches(model: 'AddRequestPydanticModel') -> 'AddRequestPydant
8180
# RequestIndexImageMixin
8281
def binary_image_check(binary_image: str) -> str:
8382
"""
84-
# Validate binary_image is correctly provided
83+
# Validate binary_image is correctly provided.
8584
"""
8685
if not binary_image and not current_app.config['IIB_BINARY_IMAGE_CONFIG']:
8786
raise ValidationError('The "binary_image" value must be a non-empty string')
@@ -95,9 +94,7 @@ def validate_overwrite_params(
9594
disable_auth_check: Optional[bool] = False,
9695
) -> None:
9796
"""
98-
Check if both `overwrite_index_image` and `overwrite_index_image_token` are specified
99-
100-
97+
Check if both `overwrite_index_image` and `overwrite_index_image_token` are specified.
10198
"""
10299
if overwrite_index_image_token and not overwrite_index_image:
103100
raise ValidationError(
@@ -122,5 +119,7 @@ def distribution_scope_lower(distribution_scope: str) -> str:
122119

123120
def length_validator(model_property: Any) -> Any:
124121
if len(model_property) == 0:
125-
raise ValidationError(f"The {type(model_property)} {model_property} should have at least 1 item.")
122+
raise ValidationError(
123+
f"The {type(model_property)} {model_property} should have at least 1 item."
124+
)
126125
return model_property

0 commit comments

Comments
 (0)