Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/dev' into bump_version_pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
evelyn-ys committed Jun 27, 2022
2 parents f4cc578 + 6bd87c5 commit 3fcc82a
Show file tree
Hide file tree
Showing 528 changed files with 194,784 additions and 120,743 deletions.
3 changes: 2 additions & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
/src/azure-cli-core/azure/cli/core/auth/ @jiasli @evelyn-ys @calvinhzy
/src/azure-cli-core/azure/cli/core/extension/ @jsntcy @kairu-ms
/src/azure-cli-core/azure/cli/core/style.py @jiasli @evelyn-ys @zhoxing-ms
/src/azure-cli-core/azure/cli/core/aaz/ @kairu-ms @necusjz @calvinhzy @jsntcy

/src/azure-cli/azure/cli/command_modules/acr/ @zhoxing-ms @northtyphoon @rosanch @jsntcy
/src/azure-cli/azure/cli/command_modules/acs/ @zhoxing-ms @zqingqing1 @gtracer @xizhamsft @andyliuliming @fumingzhang @jsntcy
Expand Down Expand Up @@ -45,7 +46,7 @@
/src/azure-cli/azure/cli/command_modules/identity/ @zhoxing-ms @jiasli
/src/azure-cli/azure/cli/command_modules/iot/ @digimaun @zhoxing-ms
/src/azure-cli/azure/cli/command_modules/keyvault/ @evelyn-ys @jiasli @calvinhzy
/src/azure-cli/azure/cli/command_modules/monitor/ @jsntcy @kairu-ms
/src/azure-cli/azure/cli/command_modules/monitor/ @jsntcy @kairu-ms @necusjz
/src/azure-cli/azure/cli/command_modules/natgateway/ @khannarheams @jsntcy @kairu-ms @necusjz
/src/azure-cli/azure/cli/command_modules/network/ @jsntcy @kairu-ms @wangzelin007 @necusjz
/src/azure-cli/azure/cli/command_modules/policyinsights/ @cheggert
Expand Down
15 changes: 10 additions & 5 deletions src/azure-cli-core/azure/cli/core/aaz/_arg.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ def to_cmd_arg(self, name):
options_list=[*self._options] if self._options else None,
required=self._required,
help=self._help.get('short-summary', None),
id_part=self._id_part,
default=self._default,
)
if self._arg_group:
Expand Down Expand Up @@ -197,11 +198,15 @@ def _build_cmd_action(self):
def to_cmd_arg(self, name):
from ._help import shorthand_help_messages
arg = super().to_cmd_arg(name)
short_summery = arg.type.settings.get('help', None) or ''
if short_summery:
short_summery += ' '
short_summery += shorthand_help_messages['show-help'] + ' ' + shorthand_help_messages['short-summery']
arg.help = short_summery
short_summary = arg.type.settings.get('help', None) or ''
if short_summary:
short_summary += ' '
short_summary += shorthand_help_messages['short-summary'] + ' ' + shorthand_help_messages['show-help']
if isinstance(self, AAZListArg) and self.singular_options:
singular_options = ' Singular flags: ' + ' '.join(
[f'`{opt}`' for opt in self.singular_options])
short_summary += singular_options + '.'
arg.help = short_summary
return arg


Expand Down
2 changes: 1 addition & 1 deletion src/azure-cli-core/azure/cli/core/aaz/_arg_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ def format_data(cls, data):
raise AAZInvalidValueError(f"list type value expected, got '{data}'({type(data)})")


class AAZGenericUpdateAction(Action):
class AAZGenericUpdateAction(Action): # pylint: disable=too-few-public-methods
DEST = '_generic_update_args'

def __call__(self, parser, namespace, values, option_string=None):
Expand Down
8 changes: 6 additions & 2 deletions src/azure-cli-core/azure/cli/core/aaz/_arg_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class AAZArgBrowser:
@classmethod
def create(cls, arg):
assert isinstance(arg, AAZBaseValue)
return cls(arg_value=arg, arg_data=arg.to_serialized_data())
return cls(arg_value=arg, arg_data=arg.to_serialized_data(keep_undefined_in_list=True))

def __init__(self, arg_value, arg_data, parent=None):
assert isinstance(arg_value, AAZBaseValue)
Expand All @@ -33,7 +33,7 @@ def get_prop(self, key):
if key.startswith('.'):
names = key[1:].split('.', maxsplit=1)
prop_name = names[0]
if prop_name not in self._arg_data:
if self._arg_data is None or prop_name not in self._arg_data:
return None
sub_value = self._arg_value[prop_name]
sub_data = self._arg_data[prop_name]
Expand All @@ -47,6 +47,10 @@ def get_prop(self, key):

def get_elements(self):
"""Iter over sub elements of list or dict."""
if self._arg_data is None:
# stop iteration
return

if isinstance(self._arg_data, list):
for idx, d in enumerate(self._arg_data):
# not support to access parent from element args
Expand Down
2 changes: 1 addition & 1 deletion src/azure-cli-core/azure/cli/core/aaz/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def __init__(self, schema, data):
self._is_patch = False

@abc.abstractmethod
def to_serialized_data(self, processor=None):
def to_serialized_data(self, processor=None, **kwargs):
""" serialize value into python build-in type """
raise NotImplementedError()

Expand Down
20 changes: 16 additions & 4 deletions src/azure-cli-core/azure/cli/core/aaz/_content_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,15 @@ def set_prop(self, prop_name, typ, arg_key=None, typ_kwargs=None):
if isinstance(value[prop_name], AAZSimpleValue):
value[prop_name] = sub_arg.data
elif isinstance(value[prop_name], AAZList):
value[prop_name] = []
if sub_arg.data is None:
value[prop_name] = None
else:
value[prop_name] = []
elif isinstance(value[prop_name], (AAZDict, AAZObject)):
value[prop_name] = {}
if sub_arg.data is None:
value[prop_name] = None
else:
value[prop_name] = {}
else:
raise NotImplementedError()
sub_values.append(value[prop_name])
Expand Down Expand Up @@ -102,9 +108,15 @@ def set_elements(self, typ, arg_key=None, typ_kwargs=None):
if isinstance(value[key], AAZSimpleValue):
value[key] = sub_arg.data
elif isinstance(value[key], AAZList):
value[key] = []
if sub_arg.data is None:
value[key] = None
else:
value[key] = []
elif isinstance(value[key], (AAZDict, AAZObject)):
value[key] = {}
if sub_arg.data is None:
value[key] = None
else:
value[key] = {}
else:
raise NotImplementedError()
sub_values.append(value[key])
Expand Down
11 changes: 6 additions & 5 deletions src/azure-cli-core/azure/cli/core/aaz/_field_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
AAZInvalidFieldError

# pylint: disable=protected-access, too-few-public-methods, isinstance-second-argument-not-valid-type
# pylint: disable=too-many-instance-attributes


# build in types
Expand Down Expand Up @@ -218,11 +219,11 @@ def get_discriminator(self, data):
if isinstance(data, AAZObject):
data = data._data
assert isinstance(data, dict)
if self._discriminator_field_name not in data:
return None

field_data = data[self._discriminator_field_name] # get discriminator field data
return self._discriminators.get(field_data, None)
for key, field_data in data.items():
name = self.get_attr_name(key)
if name == self._discriminator_field_name:
return self._discriminators.get(field_data, None)
return None


class AAZDictType(AAZBaseType):
Expand Down
79 changes: 51 additions & 28 deletions src/azure-cli-core/azure/cli/core/aaz/_field_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def __ge__(self, other):
other = other._data
return self._data >= other

def to_serialized_data(self, processor=None):
def to_serialized_data(self, processor=None, **kwargs):
result = self._data
if processor:
result = processor(self._schema, result)
Expand Down Expand Up @@ -115,22 +115,26 @@ def __eq__(self, other):
def __ne__(self, other):
return not self == other

def to_serialized_data(self, processor=None):
result = {}
schemas = [self._schema]
def to_serialized_data(self, processor=None, **kwargs):
if self._data is None:
result = None

disc_schema = self._schema.get_discriminator(self._data)
if disc_schema:
schemas.append(disc_schema)

for schema in schemas:
for name, field_schema in schema._fields.items():
v = self[name].to_serialized_data(processor=processor)
if v == AAZUndefined:
continue
if field_schema._serialized_name: # pylint: disable=protected-access
name = field_schema._serialized_name # pylint: disable=protected-access
result[name] = v
else:
result = {}
schemas = [self._schema]

disc_schema = self._schema.get_discriminator(self._data)
if disc_schema:
schemas.append(disc_schema)

for schema in schemas:
for name, field_schema in schema._fields.items():
v = self[name].to_serialized_data(processor=processor, **kwargs)
if v == AAZUndefined:
continue
if field_schema._serialized_name: # pylint: disable=protected-access
name = field_schema._serialized_name # pylint: disable=protected-access
result[name] = v

if not result and self._is_patch:
return AAZUndefined
Expand Down Expand Up @@ -218,13 +222,17 @@ def items(self):
for key in self._data:
yield key, self[key]

def to_serialized_data(self, processor=None):
result = {}
for key, v in self.items():
v = v.to_serialized_data(processor=processor)
if v == AAZUndefined:
continue
result[key] = v
def to_serialized_data(self, processor=None, **kwargs):
if self._data is None:
result = None
else:
result = {}
for key, v in self.items():
v = v.to_serialized_data(processor=processor, **kwargs)
if v == AAZUndefined:
continue
result[key] = v

if not result and self._is_patch:
return AAZUndefined
if processor:
Expand Down Expand Up @@ -335,11 +343,26 @@ def clear(self):
self._data.clear()
self._len = 0

def to_serialized_data(self, processor=None):
result = []
for v in self:
v = v.to_serialized_data(processor=processor)
result.append(v)
def to_serialized_data(self, processor=None, keep_undefined_in_list=False, # pylint: disable=arguments-differ
**kwargs):
if self._data is None:
result = None
else:
result = []
has_valid = False
for v in self:
v = v.to_serialized_data(
processor=processor, keep_undefined_in_list=keep_undefined_in_list, **kwargs)
if v == AAZUndefined and not keep_undefined_in_list:
# When AAZUndefined is ignore it, the index of the following value will be changed.
continue
if v != AAZUndefined:
has_valid = True
result.append(v)
if not has_valid:
# when elements are all undefined, the result will be empty.
result = []

if not result and self._is_patch:
return AAZUndefined
if processor:
Expand Down
20 changes: 10 additions & 10 deletions src/azure-cli-core/azure/cli/core/aaz/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@

shorthand_help_messages = {
"show-help": 'Try `??` to show more.',
"short-summery": 'Shorthand syntax supported.',
"long-summery": 'See https://github.com/Azure/azure-cli/tree/dev/doc/shorthand_syntax.md '
"short-summary": 'Shorthand syntax supported.',
"long-summary": 'See https://github.com/Azure/azure-cli/tree/dev/doc/shorthand_syntax.md '
'for more about shorthand syntax.'
}

Expand Down Expand Up @@ -92,11 +92,11 @@ def _print_schema_basic(cls, key, schema):
else:
_print_indent(f"{key}{FIRST_LINE_PREFIX}{schema_type}", indent=1)

short_summary = cls._build_short_summery(schema)
short_summary = cls._build_short_summary(schema)
if short_summary:
_print_indent(short_summary, indent=2)

long_summary = cls._build_long_summery(schema)
long_summary = cls._build_long_summary(schema)
if long_summary:
_print_indent(long_summary, indent=2)

Expand All @@ -112,7 +112,7 @@ def _print_object_props_schema(cls, schema, title):
prop_tags = cls._build_schema_tags(prop_schema)
prop_name = ' '.join(prop_schema._options)

prop_short_summary = cls._build_short_summery(prop_schema, is_prop=True)
prop_short_summary = cls._build_short_summary(prop_schema, is_prop=True)

prop_group_name = prop_schema._arg_group or ""
header_len = len(prop_name) + len(prop_tags) + (1 if prop_tags else 0)
Expand Down Expand Up @@ -149,7 +149,7 @@ def _build_schema_tags(schema, required=True, preview=True, experimental=False):
return tags

@staticmethod
def _build_short_summery(schema, is_prop=False):
def _build_short_summary(schema, is_prop=False):
from ._arg import AAZSimpleTypeArg, AAZCompoundTypeArg
short_summary = schema._help.get("short-summary", "")

Expand All @@ -160,22 +160,22 @@ def _build_short_summery(schema, is_prop=False):
short_summary += ' '
short_summary += 'Allowed values: {}.'.format(', '.join(sorted([str(x) for x in choices])))
elif isinstance(schema, AAZCompoundTypeArg):
if short_summary:
short_summary += ' '
if is_prop:
if short_summary:
short_summary += ' '
short_summary += shorthand_help_messages['show-help']
return short_summary

@staticmethod
def _build_long_summery(schema):
def _build_long_summary(schema):
from ._arg import AAZCompoundTypeArg
lines = []
long_summary = schema._help.get("long-summary", "")
if long_summary:
lines.append(long_summary)

if isinstance(schema, AAZCompoundTypeArg):
lines.append(shorthand_help_messages['long-summery'])
lines.append(shorthand_help_messages['long-summary'])

if schema._is_preview:
preview = status_tag_messages['preview'].format("This argument")
Expand Down
Loading

0 comments on commit 3fcc82a

Please sign in to comment.