Skip to content

Commit

Permalink
Linting
Browse files Browse the repository at this point in the history
  • Loading branch information
mharding-hpe committed Aug 29, 2024
1 parent c958a4c commit 856c6f3
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 32 deletions.
16 changes: 3 additions & 13 deletions src/bos/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,7 @@ def using_sbps_check_kernel_parameters(kernel_parameters: str) -> bool:
Return True if it is and False if it is not.
"""
# Check for the 'root=sbps-s3' string.
pattern = re.compile("root=sbps-s3")
match = pattern.search(kernel_parameters)
if match:
return True
return False
return "root=sbps-s3" in kernel_parameters

def components_by_id(components: List[dict]) -> dict:
"""
Expand All @@ -149,12 +145,7 @@ def components_by_id(components: List[dict]) -> dict:
Purpose: It makes searching more efficient because you can
index by component name.
"""
components_by_id = {}
for component in components:
id = component["id"]
components_by_id[id] = component

return components_by_id
return { component["id"]: component for component in components }

def reverse_components_by_id(components_by_id: dict) -> List[dict]:
"""
Expand All @@ -166,5 +157,4 @@ def reverse_components_by_id(components_by_id: dict) -> List[dict]:
Purpose: Reverse the effect of components_by_id.
"""
components = [component for component in components_by_id.values()]
return components
return list(components_by_id.values())
5 changes: 2 additions & 3 deletions src/bos/operators/utils/clients/ims.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ def tag_image(image_id: str, operation: str, key: str, value: str = None, sessio
raise TagFailure(msg)

if value:
LOGGER.debug(f"Patching image {image_id} {operation}ing key: {key} value: {value}")
LOGGER.debug("Patching image %s %sing key: %s value: %s", image_id, operation, key, value)
else:
LOGGER.debug(f"Patching image {image_id} {operation}ing key: {key}")
LOGGER.debug("Patching image %s %sing key: %s", image_id, operation, key)

if not session:
session = requests_retry_session()
Expand All @@ -81,4 +81,3 @@ def tag_image(image_id: str, operation: str, key: str, value: str = None, sessio
}
}
patch_image(image_id=image_id, data=data, session=session)

40 changes: 24 additions & 16 deletions utils/convert_oas/convert_oas.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ class ConversionException(Exception):

def _cleanse_schema(schema):
if not isinstance(schema, dict):
raise ConversionException(f"Expecting schema to be type dict, but found type {type(schema).__name__}: {schema}")
raise ConversionException(
f"Expecting schema to be type dict, but found type {type(schema).__name__}: {schema}")
if len(schema) == 1:
key = list(schema.keys())[0]
match key:
Expand All @@ -60,7 +61,8 @@ def _cleanse_schema(schema):
# If this is oneOf, anyOf, or allOf, then it should map to a list, and we need to
# parse each element of that list
if not isinstance(schema[key], list):
raise ConversionException(f"Expecting '{key}' to map to a list, but it does not: {schema}")
raise ConversionException(
f"Expecting '{key}' to map to a list, but it does not: {schema}")
for v in schema[key]:
_cleanse_schema(v)
return
Expand Down Expand Up @@ -88,9 +90,10 @@ def _cleanse_generic_schema(schema):
if schema.pop("nullable", False):
schema["type"] = [ schema["type"], "null" ]

# Remove keywords that are not part of JSON schema, as well
# as ones which are not needed for validation, and have different meanings between OAS and JSON schema
for k in ["deprecated", "discriminator", "example", "externalDocs", "readOnly", "writeOnly", "xml", "description"]:
# Remove keywords that are not part of JSON schema, as well as ones which are not needed for
# validation, and have different meanings between OAS and JSON schema
for k in ["deprecated", "discriminator", "example", "externalDocs", "readOnly", "writeOnly",
"xml", "description"]:
schema.pop(k, None)


Expand All @@ -99,37 +102,42 @@ def _cleanse_array_schema(schema):
try:
items_schema = schema["items"]
except KeyError as exc:
raise ConversionException(f"Array schema is missing required 'items' field: {schema}") from exc
raise ConversionException(
f"Array schema is missing required 'items' field: {schema}") from exc
_cleanse_schema(items_schema)


def _cleanse_numeric_schema(schema):
_cleanse_generic_schema(schema)
if any(field in schema for field in [ "exclusiveMinimum", "exclusiveMaximum" ]):
# Rather than worry about dealing with this programmatically, we should just fail. This is run at build time,
# so if it fails, the API spec can be fixed before this gets checked in.
raise ConversionException(f"Integer/Number schema has exclusiveMinimum/Maximum field. Cannot handle automatically. Schema: {schema}")
# Rather than worry about dealing with this programmatically, we should just fail.
# This is run at build time, so if it fails, the API spec can be fixed before this
# gets checked in.
raise ConversionException(
f"Integer/Number schema has exclusiveMinimum/Maximum field. Schema: {schema}")


def _cleanse_object_schema(schema):
_cleanse_generic_schema(schema)
object_properties = schema.get("properties", {})
if not isinstance(object_properties, dict):
raise ConversionException(f"Object schema has non-dict 'properties' value. Schema: {schema}")
raise ConversionException(
f"Object schema has non-dict 'properties' value. Schema: {schema}")
for v in object_properties.values():
_cleanse_schema(v)

# additionalProperties is allowed to map to a schema dict. But it's also allowed to map to a boolean. Or to be absent.
# If it is present and mapped to a non-empty dict, then we need to cleanse it.
# additionalProperties is allowed to map to a schema dict. But it's also allowed to map
# to a boolean. Or to be absent. If it is present and mapped to a non-empty dict, then we
# need to cleanse it.
try:
additionalProperties = schema['additionalProperties']
additional_properties = schema['additionalProperties']
except KeyError:
return
if not isinstance(additionalProperties, dict):
if not isinstance(additional_properties, dict):
return
if not additionalProperties:
if not additional_properties:
return
_cleanse_schema(additionalProperties)
_cleanse_schema(additional_properties)


def convert_oas(input_file: TextIO, output_file: TextIO|None=None) -> dict:
Expand Down

0 comments on commit 856c6f3

Please sign in to comment.