Skip to content

Commit

Permalink
{Containerapp} Fix style (#7680)
Browse files Browse the repository at this point in the history
  • Loading branch information
Greedygre committed Jun 11, 2024
1 parent 3680f94 commit 8d630db
Show file tree
Hide file tree
Showing 29 changed files with 225 additions and 183 deletions.
2 changes: 0 additions & 2 deletions src/containerapp/azext_containerapp/_client_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,6 @@ def log_analytics_shared_key_client_factory(cli_ctx):


def custom_location_client_factory(cli_ctx, api_version=None, subscription_id=None, **_):
from azure.cli.core.profiles import ResourceType
from azure.cli.core.commands.client_factory import get_mgmt_service_client

return get_mgmt_service_client(cli_ctx, ResourceType.MGMT_CUSTOMLOCATION, api_version=api_version,
subscription_id=subscription_id).custom_locations
Expand Down
2 changes: 1 addition & 1 deletion src/containerapp/azext_containerapp/_clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
# pylint: disable=line-too-long, super-with-arguments, too-many-instance-attributes, consider-using-f-string, no-else-return, no-self-use
# pylint: disable=line-too-long, no-else-return, useless-return, broad-except, no-else-raise

import json
import os
Expand Down
3 changes: 2 additions & 1 deletion src/containerapp/azext_containerapp/_cloud_build_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
# pylint: disable=line-too-long, too-many-locals, missing-timeout, too-many-statements, consider-using-with, too-many-branches
# pylint: disable=line-too-long, too-many-locals

from threading import Thread
import os
Expand Down Expand Up @@ -31,6 +31,7 @@ class CloudBuildError(Exception):
pass


# pylint: disable=too-many-branches
def run_cloud_build(cmd, source, build_env_vars, location, resource_group_name, environment_name, container_app_name, run_full_id, logs_file, logs_file_path):
generated_build_name = f"build{run_full_id}"[:12]
log_in_file(f"Starting the Cloud Build for build of id '{generated_build_name}'\n", logs_file, no_print=True)
Expand Down
8 changes: 4 additions & 4 deletions src/containerapp/azext_containerapp/_decorator_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from azure.cli.core.azclierror import (ValidationError)

from ._constants import (RUNTIME_GENERIC, RUNTIME_JAVA)
from ._constants import RUNTIME_JAVA
from ._utils import safe_get


Expand Down Expand Up @@ -43,7 +43,7 @@ def create_deserializer(models):


def process_loaded_yaml(yaml_containerapp):
if type(yaml_containerapp) != dict: # pylint: disable=unidiomatic-typecheck
if not isinstance(yaml_containerapp, dict): # pylint: disable=unidiomatic-typecheck
raise ValidationError('Invalid YAML provided. Please see https://aka.ms/azure-container-apps-yaml for a valid containerapps YAML spec.')
if not yaml_containerapp.get('properties'):
yaml_containerapp['properties'] = {}
Expand Down Expand Up @@ -83,7 +83,7 @@ def process_loaded_yaml(yaml_containerapp):

def process_containerapp_resiliency_yaml(containerapp_resiliency):

if type(containerapp_resiliency) != dict: # pylint: disable=unidiomatic-typecheck
if not isinstance(containerapp_resiliency, dict): # pylint: disable=unidiomatic-typecheck
raise ValidationError('Invalid YAML provided. Please provide a valid container app resiliency YAML spec.')
if 'additionalProperties' in containerapp_resiliency and not containerapp_resiliency['additionalProperties']:
raise ValidationError('Invalid YAML provided. Please provide a valid containerapp resiliency YAML spec.')
Expand All @@ -108,7 +108,7 @@ def process_containerapp_resiliency_yaml(containerapp_resiliency):

def process_dapr_component_resiliency_yaml(dapr_component_resiliency):

if type(dapr_component_resiliency) != dict: # pylint: disable=unidiomatic-typecheck
if not isinstance(dapr_component_resiliency, dict): # pylint: disable=unidiomatic-typecheck
raise ValidationError('Invalid YAML provided. Please provide a valid dapr component resiliency YAML spec.')
if 'additionalProperties' in dapr_component_resiliency and not dapr_component_resiliency['additionalProperties']:
raise ValidationError('Invalid YAML provided. Please provide a valid dapr component resiliency YAML spec.')
Expand Down
7 changes: 4 additions & 3 deletions src/containerapp/azext_containerapp/_dev_service_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
# pylint: disable=line-too-long

from azure.cli.core.azclierror import ValidationError, CLIError, ResourceNotFoundError
from azure.cli.core.azclierror import CLIError, ResourceNotFoundError
from ._client_factory import handle_raw_exception
from ._clients import ManagedEnvironmentClient, ContainerAppClient
from ._constants import (
Expand All @@ -26,7 +27,7 @@ def create_service(cmd, service_name, environment_name, resource_group_name, no_
try:
env_info = ManagedEnvironmentClient.show(cmd=cmd, resource_group_name=resource_group_name,
name=environment_name)
except Exception:
except Exception: # pylint: disable=broad-except
pass

if not env_info:
Expand All @@ -47,7 +48,7 @@ def delete_service(cmd, service_name, resource_group_name, no_wait, service_type
try:
containerapp_def = ContainerAppClient.show(cmd=cmd, resource_group_name=resource_group_name,
name=service_name)
except Exception:
except Exception: # pylint: disable=broad-except
pass

if not containerapp_def:
Expand Down
10 changes: 5 additions & 5 deletions src/containerapp/azext_containerapp/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -1649,7 +1649,7 @@
examples:
- name: Show container apps environment telemetry data dog settings.
text: |
az containerapp env telemetry data-dog show -n MyContainerappEnvironment -g MyResourceGroup
az containerapp env telemetry data-dog show -n MyContainerappEnvironment -g MyResourceGroup
"""

helps['containerapp env telemetry app-insights set'] = """
Expand All @@ -1668,7 +1668,7 @@
examples:
- name: Show container apps environment telemetry app insights settings.
text: |
az containerapp env telemetry app-insights show -n MyContainerappEnvironment -g MyResourceGroup
az containerapp env telemetry app-insights show -n MyContainerappEnvironment -g MyResourceGroup
"""

helps['containerapp env telemetry data-dog delete'] = """
Expand Down Expand Up @@ -1787,7 +1787,7 @@

helps['containerapp sessionpool create'] = """
type: command
short-summary: Create or update a Session pool.
short-summary: Create or update a Session pool.
examples:
- name: Create or update a Session Pool with container type PythonLTS default settings.
text: |
Expand Down Expand Up @@ -1875,7 +1875,7 @@

helps['containerapp session code-interpreter execute'] = """
type: command
short-summary: Execute code in a code interpreter session.
short-summary: Execute code in a code interpreter session.
examples:
- name: Execute a simple hello world.
text: |
Expand All @@ -1890,7 +1890,7 @@
- name: Upload a file to a session.
text: |
az containerapp session code-interpreter upload-file -n MySessionPool -g MyResourceGroup --identifier MySession \\
--filepath example.txt
--filepath example.txt
"""

helps['containerapp session code-interpreter show-file-content'] = """
Expand Down
4 changes: 2 additions & 2 deletions src/containerapp/azext_containerapp/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def load_arguments(self, _):
# App Resiliency
with self.argument_context('containerapp resiliency') as c:
c.argument('resource_group_name', arg_type=resource_group_name_type, id_part=None)
c.argument('container_app_name', options_list=['--container-app-name'], help=f"The name of the existing Container App.")
c.argument('container_app_name', options_list=['--container-app-name'], help="The name of the existing Container App.")
c.argument('name', name_type, help=f"The name of the Container App Resiliency Policy. A name must consist of lower case alphanumeric characters or '-', start with a letter, end with an alphanumeric character, cannot have '--', and must be less than {MAXIMUM_APP_RESILIENCY_NAME_LENGTH} characters.")
c.argument('yaml', type=file_type, help='Path to a .yaml file with the configuration of a container app resiliency policy. All other parameters will be ignored.')
c.argument('default', options_list=['--recommended'], help='Set recommended values of resiliency policies for a container app.')
Expand Down Expand Up @@ -297,7 +297,7 @@ def load_arguments(self, _):

# scale
with self.argument_context('containerapp', arg_group='Scale') as c:
c.argument('scale_rule_identity', options_list=['--scale-rule-identity', '--sri'],
c.argument('scale_rule_identity', options_list=['--scale-rule-identity', '--sri'],
help='Resource ID of a managed identity to authenticate with Azure scaler resource(storage account/eventhub or else), or System to use a system-assigned identity.', is_preview=True)

with self.argument_context('containerapp job', arg_group='Scale') as c:
Expand Down
4 changes: 4 additions & 0 deletions src/containerapp/azext_containerapp/_sdk_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
# Code generated by Microsoft (R) AutoRest Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------
# pylint: disable=line-too-long, unused-import, useless-super-delegation
# pylint: disable=redefined-builtin, import-self
# pylint: disable=too-many-instance-attributes, useless-parent-delegation, anomalous-backslash-in-string
# flake8: noqa W605

import datetime
import sys
Expand Down
35 changes: 19 additions & 16 deletions src/containerapp/azext_containerapp/_transformers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
from azure.cli.command_modules.containerapp._utils import safe_set, safe_get
from .containerapp_env_telemetry_decorator import DATA_DOG_DEST, APP_INSIGHTS_DEST
# pylint: disable=bare-except, line-too-long

from knack.log import get_logger

from azure.cli.command_modules.containerapp._utils import safe_set, safe_get
from azure.cli.core.azclierror import ResourceNotFoundError

from .containerapp_env_telemetry_decorator import DATA_DOG_DEST, APP_INSIGHTS_DEST

logger = get_logger(__name__)


Expand Down Expand Up @@ -61,14 +65,14 @@ def transform_telemetry_data_dog_values(response_json):
existing_traces = safe_get(containerapp_env_def, "properties", "openTelemetryConfiguration", "tracesConfiguration", "destinations")
if existing_traces and DATA_DOG_DEST in existing_traces:
enable_open_telemetry_traces = True

safe_set(r, "enableOpenTelemetryTraces", value=enable_open_telemetry_traces)

enable_open_telemetry_metrics = False
existing_metrics = safe_get(containerapp_env_def, "properties", "openTelemetryConfiguration", "metricsConfiguration", "destinations")
if existing_metrics and DATA_DOG_DEST in existing_metrics:
enable_open_telemetry_metrics = True

safe_set(r, "enableOpenTelemetryMetrics", value=enable_open_telemetry_metrics)

return r
Expand All @@ -87,19 +91,20 @@ def transform_telemetry_app_insights_values(response_json):
existing_traces = safe_get(containerapp_env_def, "properties", "openTelemetryConfiguration", "tracesConfiguration", "destinations")
if existing_traces and APP_INSIGHTS_DEST in existing_traces:
enable_open_telemetry_traces = True

safe_set(r, "enableOpenTelemetryTraces", value=enable_open_telemetry_traces)

enable_open_telemetry_logs = False
existing_logs = safe_get(containerapp_env_def, "properties", "openTelemetryConfiguration", "logsConfiguration", "destinations")
if existing_logs and APP_INSIGHTS_DEST in existing_logs:
enable_open_telemetry_logs = True

safe_set(r, "enableOpenTelemetryLogs", value=enable_open_telemetry_logs)

return r


# pylint: disable=too-many-nested-blocks
def transform_telemetry_otlp_values(response_json):
containerapp_env_def = response_json

Expand All @@ -111,9 +116,9 @@ def transform_telemetry_otlp_values(response_json):
if existing_otlps is not None:
for otlp in existing_otlps:
if "headers" in otlp:
dict = otlp["headers"]
if dict:
for header in dict:
headers_dict = otlp["headers"]
if headers_dict:
for header in headers_dict:
if "value" in header:
header["value"] = None
enable_open_telemetry_traces = False
Expand All @@ -123,19 +128,19 @@ def transform_telemetry_otlp_values(response_json):
enable_open_telemetry_traces = False
if existing_traces and otlp_name in existing_traces:
enable_open_telemetry_traces = True

safe_set(otlp, "enableOpenTelemetryTraces", value=enable_open_telemetry_traces)

enable_open_telemetry_logs = False
if existing_logs and otlp_name in existing_logs:
enable_open_telemetry_logs = True

safe_set(otlp, "enableOpenTelemetryLogs", value=enable_open_telemetry_logs)

enable_open_telemetry_metrics = False
if existing_metrics and otlp_name in existing_metrics:
enable_open_telemetry_metrics = True

safe_set(otlp, "enableOpenTelemetryMetrics", value=enable_open_telemetry_metrics)

return existing_otlps
Expand All @@ -146,7 +151,7 @@ def transform_telemetry_otlp_values_by_name(response_json):
if '--otlp-name' in args:
otlp_name = args[args.index("--otlp-name") + 1]
if not otlp_name:
raise ResourceNotFoundError(f"Otlp entry does not exist, please retry with different name")
raise ResourceNotFoundError("Otlp entry does not exist, please retry with different name")
existing_otlps = safe_get(response_json, "properties", "openTelemetryConfiguration", "destinationsConfiguration", "otlpConfigurations")
otlp = [p for p in existing_otlps if p["name"].lower() == otlp_name.lower()]
if otlp:
Expand All @@ -157,9 +162,7 @@ def transform_telemetry_otlp_values_by_name(response_json):
existing_otlps = transform_telemetry_otlp_values(response_json)
if existing_otlps:
return existing_otlps[0]

raise ResourceNotFoundError(f"Otlp entry with name --otlp-name {otlp_name} does not exist, please retry with different name")

return transform_telemetry_otlp_values_by_name


22 changes: 11 additions & 11 deletions src/containerapp/azext_containerapp/_up_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
# pylint: disable=line-too-long, consider-using-f-string, no-else-return, duplicate-string-formatting-argument, expression-not-assigned, too-many-locals, logging-fstring-interpolation, arguments-differ, abstract-method, logging-format-interpolation, broad-except
# pylint: disable=line-too-long, unused-argument, too-many-instance-attributes, consider-using-f-string, logging-fstring-interpolation, logging-format-interpolation, no-else-return, broad-except

from random import randint
from tempfile import NamedTemporaryFile
from urllib.parse import urlparse
Expand Down Expand Up @@ -55,7 +56,6 @@
ConnectedEnvironmentClient, ManagedEnvironmentPreviewClient

from ._utils import (
get_pack_exec_path,
is_docker_running,
get_pack_exec_path, _validate_custom_loc_and_location, _validate_connected_k8s_exists, get_custom_location,
create_extension, create_custom_location, get_cluster_extension, validate_environment_location,
Expand Down Expand Up @@ -249,7 +249,7 @@ def create_if_needed(self, app_name):
f"Using {type(self).__name__} '{self.name}' in resource group {self.resource_group.name}"
) # TODO use .info()

def create(self):
def create(self): # pylint: disable=arguments-differ
register_provider_if_needed(self.cmd, LOG_ANALYTICS_RP)
# for creating connected environment, the location infer from custom location
if self.is_connected_environment():
Expand Down Expand Up @@ -345,8 +345,8 @@ def __init__(
self.registry_user = registry_user
self.registry_pass = registry_pass
self.env_vars = env_vars
self.trigger_type = trigger_type,
self.replica_timeout = replica_timeout,
self.trigger_type = trigger_type
self.replica_timeout = replica_timeout
self.replica_retry_limit = replica_retry_limit
self.replica_completion_count = replica_completion_count
self.parallelism = parallelism
Expand All @@ -357,7 +357,7 @@ def __init__(
def _get(self):
return ContainerAppsJobClient.show(self.cmd, self.resource_group.name, self.name)

def create(self, no_registry=False):
def create(self, no_registry=False): # pylint: disable=arguments-differ
# no_registry: don't pass in a registry during create even if the app has one (used for GH actions)
if get_containerapps_job_if_exists(self.cmd, self.resource_group.name, self.name):
logger.warning(
Expand Down Expand Up @@ -387,7 +387,7 @@ def create(self, no_registry=False):
)


class AzureContainerRegistry(Resource):
class AzureContainerRegistry(Resource): # pylint: disable=abstract-method
def __init__(self, name: str, resource_group: "ResourceGroup"): # pylint: disable=super-init-not-called

self.name = name
Expand Down Expand Up @@ -431,7 +431,7 @@ def __init__(
def _get(self):
return ContainerAppPreviewClient.show(self.cmd, self.resource_group.name, self.name)

def create(self, no_registry=False):
def create(self, no_registry=False): # pylint: disable=arguments-differ
# no_registry: don't pass in a registry during create even if the app has one (used for GH actions)
if get_container_app_if_exists(self.cmd, self.resource_group.name, self.name):
logger.warning(
Expand Down Expand Up @@ -857,7 +857,7 @@ def __init__(
if "resource_group" in custom_location_dict:
self.resource_group_name = custom_location_dict["resource_group"]

def create(self):
def create(self): # pylint: disable=arguments-differ
register_provider_if_needed(self.cmd, EXTENDED_LOCATION_RP)
custom_location = create_custom_location(
cmd=self.cmd,
Expand Down Expand Up @@ -1443,7 +1443,7 @@ def _infer_existing_connected_env(
env.set_name(env_list[0]["id"])
env.custom_location_id = env_list[0]["extendedLocation"]["name"]
if len(env_list) > 1:
if env.name:
if env.name: # pylint: disable=no-else-raise
raise ValidationError(
f"There are multiple Connected Environments with name {env.name} on the subscription. "
"Please specify which resource group your Connected environment is in."
Expand Down Expand Up @@ -1556,7 +1556,7 @@ def up_output(app: 'ContainerApp', no_dockerfile):
if no_dockerfile and app.ingress:
logger.warning(f"Your app is running image {app.image} and listening on port {app.target_port}")

url and logger.warning(f"Browse to your container app at: {url} \n")
url and logger.warning(f"Browse to your container app at: {url} \n") # pylint: disable=expression-not-assigned
logger.warning(
f"Stream logs for your container with: az containerapp logs show -n {app.name} -g {app.resource_group.name} \n"
)
Expand Down
Loading

0 comments on commit 8d630db

Please sign in to comment.