Skip to content

Commit

Permalink
Fix style issues using black auto-formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan-innis committed Nov 30, 2021
1 parent 1574714 commit db2c222
Show file tree
Hide file tree
Showing 13 changed files with 1,009 additions and 683 deletions.
1 change: 1 addition & 0 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ ignore =
F401, # imported but unused, too many violations, to be removed in the future
F811, # redefinition of unused, to be removed in the future
C901 # code flow is too complex, too many violations, to be removed in the future
W503 # line break before binary operator effect on readability is subjective
W504 # line break after binary operator effect on readability is subjective
exclude =
*/vendored_sdks
Expand Down
12 changes: 7 additions & 5 deletions src/k8s-configuration/azext_k8s_configuration/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,25 @@


class K8sConfigurationCommandsLoader(AzCommandsLoader):

def __init__(self, cli_ctx=None):
from azure.cli.core.commands import CliCommandType
from azext_k8s_configuration._client_factory import k8s_configuration_client

k8s_configuration_custom = CliCommandType(
operations_tmpl='azext_k8s_configuration.custom#{}',
client_factory=k8s_configuration_client)
super().__init__(cli_ctx=cli_ctx,
custom_command_type=k8s_configuration_custom)
operations_tmpl="azext_k8s_configuration.custom#{}",
client_factory=k8s_configuration_client,
)
super().__init__(cli_ctx=cli_ctx, custom_command_type=k8s_configuration_custom)

def load_command_table(self, args):
from azext_k8s_configuration.commands import load_command_table

load_command_table(self, args)
return self.command_table

def load_arguments(self, command):
from azext_k8s_configuration._params import load_arguments

load_arguments(self, command)


Expand Down
32 changes: 22 additions & 10 deletions src/k8s-configuration/azext_k8s_configuration/_client_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,51 @@

def k8s_configuration_client(cli_ctx, **kwargs):
from azext_k8s_configuration.vendored_sdks import SourceControlConfigurationClient

return get_mgmt_service_client(cli_ctx, SourceControlConfigurationClient, **kwargs)


def k8s_configuration_fluxconfig_client(cli_ctx, *_):
return k8s_configuration_client(cli_ctx, api_version=consts.FLUXCONFIG_API_VERSION).flux_configurations
return k8s_configuration_client(
cli_ctx, api_version=consts.FLUXCONFIG_API_VERSION
).flux_configurations


def k8s_configuration_sourcecontrol_client(cli_ctx, *_):
return k8s_configuration_client(
cli_ctx,
api_version=consts.SOURCE_CONTROL_API_VERSION
cli_ctx, api_version=consts.SOURCE_CONTROL_API_VERSION
).source_control_configurations


def k8s_configuration_extension_client(cli_ctx, *_):
return k8s_configuration_client(cli_ctx, api_version=consts.EXTENSION_API_VERSION).extensions
return k8s_configuration_client(
cli_ctx, api_version=consts.EXTENSION_API_VERSION
).extensions


def resource_providers_client(cli_ctx):
from azure.mgmt.resource import ResourceManagementClient

return get_mgmt_service_client(cli_ctx, ResourceManagementClient).providers


def cf_resource_groups(cli_ctx, subscription_id=None):
return get_mgmt_service_client(cli_ctx, ResourceType.MGMT_RESOURCE_RESOURCES,
subscription_id=subscription_id).resource_groups
return get_mgmt_service_client(
cli_ctx, ResourceType.MGMT_RESOURCE_RESOURCES, subscription_id=subscription_id
).resource_groups


def cf_resources(cli_ctx, subscription_id=None):
return get_mgmt_service_client(cli_ctx, ResourceType.MGMT_RESOURCE_RESOURCES,
subscription_id=subscription_id).resources
return get_mgmt_service_client(
cli_ctx, ResourceType.MGMT_RESOURCE_RESOURCES, subscription_id=subscription_id
).resources


def cf_log_analytics(cli_ctx, subscription_id=None):
from azure.mgmt.loganalytics import LogAnalyticsManagementClient # pylint: disable=no-name-in-module
return get_mgmt_service_client(cli_ctx, LogAnalyticsManagementClient, subscription_id=subscription_id)
from azure.mgmt.loganalytics import (
LogAnalyticsManagementClient,
) # pylint: disable=no-name-in-module

return get_mgmt_service_client(
cli_ctx, LogAnalyticsManagementClient, subscription_id=subscription_id
)
27 changes: 13 additions & 14 deletions src/k8s-configuration/azext_k8s_configuration/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,28 @@
from .vendored_sdks.v2022_01_01_preview.models import (
KustomizationDefinition,
KustomizationPatchDefinition,
DependsOnDefinition
)
DependsOnDefinition,
)
from .validators import validate_kustomization
from . import consts
from .utils import parse_dependencies, parse_duration


class InternalKustomizationDefinition(KustomizationDefinition):
def __init__(self, **kwargs):
self.name = kwargs.get('name', "")
self.name = kwargs.get("name", "")
super().__init__(**kwargs)

def to_KustomizationDefinition(self):
k_dict = dict(self.__dict__)
del k_dict['name']
del k_dict['additional_properties']
del k_dict["name"]
del k_dict["additional_properties"]
return KustomizationDefinition(**k_dict)

def to_KustomizationPatchDefinition(self):
k_dict = dict(self.__dict__)
del k_dict['name']
del k_dict['additional_properties']
del k_dict["name"]
del k_dict["additional_properties"]
return KustomizationPatchDefinition(**k_dict)


Expand All @@ -44,14 +44,12 @@ def __call__(self, parser, namespace, values, option_string=None):
kwargs = {}
for item in values:
try:
key, value = item.split('=', 1)
key, value = item.split("=", 1)
if key in consts.DEPENDENCY_KEYS:
dependencies = parse_dependencies(value)
for dep in dependencies:
model_dependency.append(
DependsOnDefinition(
kustomization_name=dep
)
DependsOnDefinition(kustomization_name=dep)
)
elif key in consts.SYNC_INTERVAL_KEYS:
sync_interval = value
Expand All @@ -62,8 +60,9 @@ def __call__(self, parser, namespace, values, option_string=None):
else:
kwargs[key] = value
except ValueError as ex:
raise InvalidArgumentValueError('usage error: {} KEY=VALUE [KEY=VALUE ...]'
.format(option_string)) from ex
raise InvalidArgumentValueError(
"usage error: {} KEY=VALUE [KEY=VALUE ...]".format(option_string)
) from ex
super().__call__(
parser,
namespace,
Expand All @@ -74,5 +73,5 @@ def __call__(self, parser, namespace, values, option_string=None):
timeout_in_seconds=parse_duration(timeout),
**kwargs
),
option_string
option_string,
)
116 changes: 87 additions & 29 deletions src/k8s-configuration/azext_k8s_configuration/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from azure.cli.core.commands import CliCommandType
from azext_k8s_configuration._client_factory import (
k8s_configuration_fluxconfig_client,
k8s_configuration_sourcecontrol_client
k8s_configuration_sourcecontrol_client,
)
from .format import (
fluxconfig_deployed_object_list_table_format,
Expand All @@ -17,41 +17,99 @@
fluxconfig_kustomization_list_table_format,
fluxconfig_kustomization_show_table_format,
sourcecontrol_list_table_format,
sourcecontrol_show_table_format
sourcecontrol_show_table_format,
)


def load_command_table(self, _):
flux_configuration_custom_type = CliCommandType(
operations_tmpl='azext_k8s_configuration.providers.FluxConfigurationProvider#{}',
client_factory=k8s_configuration_fluxconfig_client
operations_tmpl="azext_k8s_configuration.providers.FluxConfigurationProvider#{}",
client_factory=k8s_configuration_fluxconfig_client,
)

source_control_configuration_custom_type = CliCommandType(
operations_tmpl='azext_k8s_configuration.providers.SourceControlConfigurationProvider#{}',
client_factory=k8s_configuration_sourcecontrol_client
operations_tmpl="azext_k8s_configuration.providers.SourceControlConfigurationProvider#{}",
client_factory=k8s_configuration_sourcecontrol_client,
)

with self.command_group('k8s-configuration flux', k8s_configuration_fluxconfig_client, custom_command_type=flux_configuration_custom_type, is_preview=True) as g:
g.custom_command('create', 'create', supports_no_wait=True)
g.custom_command('update', 'update', supports_no_wait=True)
g.custom_command('list', "list", table_transformer=fluxconfig_list_table_format)
g.custom_show_command('show', 'show', table_transformer=fluxconfig_show_table_format)
g.custom_command('delete', 'delete', supports_no_wait=True)

with self.command_group('k8s-configuration flux kustomization', k8s_configuration_fluxconfig_client, custom_command_type=flux_configuration_custom_type, is_preview=True) as g:
g.custom_command('create', 'create_kustomization', supports_no_wait=True)
g.custom_command('update', 'update_kustomization', supports_no_wait=True)
g.custom_command('delete', 'delete_kustomization', supports_no_wait=True)
g.custom_command('list', 'list_kustomization', table_transformer=fluxconfig_kustomization_list_table_format)
g.custom_show_command('show', 'show_kustomization', table_transformer=fluxconfig_kustomization_show_table_format)

with self.command_group('k8s-configuration flux deployed-object', k8s_configuration_fluxconfig_client, custom_command_type=flux_configuration_custom_type, is_preview=True) as g:
g.custom_command('list', 'list_deployed_object', table_transformer=fluxconfig_deployed_object_list_table_format)
g.custom_show_command('show', 'show_deployed_object', table_transformer=fluxconfig_deployed_object_show_table_format)

with self.command_group('k8s-configuration', k8s_configuration_sourcecontrol_client, custom_command_type=source_control_configuration_custom_type) as g:
g.custom_command('create', 'create', deprecate_info=self.deprecate(redirect='k8s-configuration flux create'))
g.custom_command('list', 'list', table_transformer=sourcecontrol_list_table_format, deprecate_info=self.deprecate(redirect='k8s-configuration flux list'))
g.custom_show_command('show', 'show', table_transformer=sourcecontrol_show_table_format, deprecate_info=self.deprecate(redirect='k8s-configuration flux show'))
g.custom_command('delete', 'delete', confirmation=True, deprecate_info=self.deprecate(redirect='k8s-configuration flux delete'))
with self.command_group(
"k8s-configuration flux",
k8s_configuration_fluxconfig_client,
custom_command_type=flux_configuration_custom_type,
is_preview=True,
) as g:
g.custom_command("create", "create_config", supports_no_wait=True)
g.custom_command("update", "update_config", supports_no_wait=True)
g.custom_command(
"list", "list_configs", table_transformer=fluxconfig_list_table_format
)
g.custom_show_command(
"show", "show_config", table_transformer=fluxconfig_show_table_format
)
g.custom_command("delete", "delete_config", supports_no_wait=True)

with self.command_group(
"k8s-configuration flux kustomization",
k8s_configuration_fluxconfig_client,
custom_command_type=flux_configuration_custom_type,
is_preview=True,
) as g:
g.custom_command("create", "create_kustomization", supports_no_wait=True)
g.custom_command("update", "update_kustomization", supports_no_wait=True)
g.custom_command("delete", "delete_kustomization", supports_no_wait=True)
g.custom_command(
"list",
"list_kustomization",
table_transformer=fluxconfig_kustomization_list_table_format,
)
g.custom_show_command(
"show",
"show_kustomization",
table_transformer=fluxconfig_kustomization_show_table_format,
)

with self.command_group(
"k8s-configuration flux deployed-object",
k8s_configuration_fluxconfig_client,
custom_command_type=flux_configuration_custom_type,
is_preview=True,
) as g:
g.custom_command(
"list",
"list_deployed_object",
table_transformer=fluxconfig_deployed_object_list_table_format,
)
g.custom_show_command(
"show",
"show_deployed_object",
table_transformer=fluxconfig_deployed_object_show_table_format,
)

with self.command_group(
"k8s-configuration",
k8s_configuration_sourcecontrol_client,
custom_command_type=source_control_configuration_custom_type,
) as g:
g.custom_command(
"create",
"create_config",
deprecate_info=self.deprecate(redirect="k8s-configuration flux create"),
)
g.custom_command(
"list",
"list_configs",
table_transformer=sourcecontrol_list_table_format,
deprecate_info=self.deprecate(redirect="k8s-configuration flux list"),
)
g.custom_show_command(
"show",
"show_config",
table_transformer=sourcecontrol_show_table_format,
deprecate_info=self.deprecate(redirect="k8s-configuration flux show"),
)
g.custom_command(
"delete",
"delete_config",
confirmation=True,
deprecate_info=self.deprecate(redirect="k8s-configuration flux delete"),
)
6 changes: 4 additions & 2 deletions src/k8s-configuration/azext_k8s_configuration/confirm.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
from azure.cli.core.util import user_confirmation


def user_confirmation_factory(cmd, yes, message="Are you sure you want to perform this operation?"):
if cmd.cli_ctx.config.getboolean('core', 'disable_confirm_prompt', fallback=False):
def user_confirmation_factory(
cmd, yes, message="Are you sure you want to perform this operation?"
):
if cmd.cli_ctx.config.getboolean("core", "disable_confirm_prompt", fallback=False):
return
user_confirmation(message, yes=yes)
Loading

0 comments on commit db2c222

Please sign in to comment.