Skip to content

Commit 308b156

Browse files
fixing style and removing tests
1 parent 118cbef commit 308b156

File tree

8 files changed

+80
-647
lines changed

8 files changed

+80
-647
lines changed

src/machinelearningservices/azext_mlv2/manual/_help/_deployment_template_help.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,22 @@
77

88
def get_deployment_template_help():
99
"""Load deployment template help content."""
10-
pass # Help content is defined below using helps dictionary
10+
1111

1212
helps['ml deployment-template'] = """
1313
type: group
1414
short-summary: Manage Azure ML deployment templates.
1515
long-summary: |
16-
Deployment templates are reusable templates that define deployment configurations for Azure ML.
17-
They support registry-based operations only (not workspace-based) and provide a way to
16+
Deployment templates are reusable templates that define deployment configurations for Azure ML.
17+
They support registry-based operations only (not workspace-based) and provide a way to
1818
standardize and share deployment configurations across teams and projects.
1919
"""
2020

2121
helps['ml deployment-template list'] = """
2222
type: command
2323
short-summary: List deployment templates in a registry.
2424
long-summary: |
25-
List all deployment templates available in the specified registry. This command
25+
List all deployment templates available in the specified registry. This command
2626
returns all templates along with their metadata including name, version, description, and tags.
2727
examples:
2828
- name: List all deployment templates in a registry
@@ -35,7 +35,7 @@ def get_deployment_template_help():
3535
type: command
3636
short-summary: Get a specific deployment template by name and version.
3737
long-summary: |
38-
Retrieve detailed information about a specific deployment template. If version is not
38+
Retrieve detailed information about a specific deployment template. If version is not
3939
specified, the latest version will be returned.
4040
examples:
4141
- name: Get a specific version of a deployment template
@@ -46,7 +46,7 @@ def get_deployment_template_help():
4646
type: command
4747
short-summary: Create a new deployment template from a YAML file.
4848
long-summary: |
49-
Create a new deployment template using a YAML configuration file. The YAML file should
49+
Create a new deployment template using a YAML configuration file. The YAML file should
5050
contain the complete deployment template definition including endpoints, parameters, and metadata.
5151
You can override specific values using command-line parameters.
5252
examples:
@@ -62,11 +62,11 @@ def get_deployment_template_help():
6262
type: command
6363
short-summary: Update specific fields of an existing deployment template.
6464
long-summary: |
65-
Update metadata fields (description and tags) of an existing deployment template without
66-
requiring a YAML file. This command follows Azure CLI conventions and only accepts specific
65+
Update metadata fields (description and tags) of an existing deployment template without
66+
requiring a YAML file. This command follows Azure CLI conventions and only accepts specific
6767
field updates. Tags are merged with existing tags rather than replaced.
68-
69-
For structural changes to the deployment template (endpoints, deployment configuration, etc.),
68+
69+
For structural changes to the deployment template (endpoints, deployment configuration, etc.),
7070
use the 'create' command with a YAML file.
7171
examples:
7272
- name: Update deployment template description
@@ -81,8 +81,8 @@ def get_deployment_template_help():
8181
type: command
8282
short-summary: Archive a deployment template.
8383
long-summary: |
84-
Archive a deployment template to mark it as inactive. Archived templates are not
85-
returned in list operations by default. You can archive a specific version or all
84+
Archive a deployment template to mark it as inactive. Archived templates are not
85+
returned in list operations by default. You can archive a specific version or all
8686
versions of a template.
8787
examples:
8888
- name: Archive a specific version
@@ -95,8 +95,8 @@ def get_deployment_template_help():
9595
type: command
9696
short-summary: Restore an archived deployment template.
9797
long-summary: |
98-
Restore a previously archived deployment template to make it active again. Restored
99-
templates will appear in list operations. You can restore a specific version or all
98+
Restore a previously archived deployment template to make it active again. Restored
99+
templates will appear in list operations. You can restore a specific version or all
100100
versions of a template.
101101
examples:
102102
- name: Restore a specific version

src/machinelearningservices/azext_mlv2/manual/_params/_deployment_template_params.py

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,14 @@
22
# Copyright (c) Microsoft Corporation. All rights reserved.
33
# ---------------------------------------------------------
44

5-
from ._common_params import add_common_params, add_description_param, add_file_param, add_lro_param, add_override_param, add_tags_param
5+
from ._common_params import (
6+
add_common_params,
7+
add_description_param,
8+
add_file_param,
9+
add_lro_param,
10+
add_override_param,
11+
add_tags_param,
12+
)
613

714

815
def add_deployment_template_common_param(
@@ -23,7 +30,10 @@ def load_deployment_template_params(self):
2330
"registry_name",
2431
options_list=["--registry-name", "-r"],
2532
required=True,
26-
help="Name of the registry. This is required since deployment templates only support registry-name and not workspace.",
33+
help=(
34+
"Name of the registry. This is required since deployment templates "
35+
"only support registry-name and not workspace."
36+
),
2737
)
2838

2939
with self.argument_context("ml deployment-template get") as c:
@@ -33,20 +43,27 @@ def load_deployment_template_params(self):
3343
"registry_name",
3444
options_list=["--registry-name", "-r"],
3545
required=True,
36-
help="Name of the registry. This is required since deployment templates only support registry-name and not workspace.",
46+
help=(
47+
"Name of the registry. This is required since deployment templates "
48+
"only support registry-name and not workspace."
49+
),
3750
)
3851

3952
with self.argument_context("ml deployment-template create") as c:
4053
add_common_params(c)
41-
add_deployment_template_common_param(c, name_required=False, version_required=False) # Optional for create since they can come from file
54+
# Optional for create since they can come from file
55+
add_deployment_template_common_param(c, name_required=False, version_required=False)
4256
add_lro_param(c)
4357
add_file_param(c, "deployment-template", "https://aka.ms/ml-cli-v2-deployment-template-yaml")
4458
add_override_param(c)
4559
c.argument(
4660
"registry_name",
4761
options_list=["--registry-name", "-r"],
4862
required=True,
49-
help="Name of the registry. This is required since deployment templates only support registry-name and not workspace.",
63+
help=(
64+
"Name of the registry. This is required since deployment templates "
65+
"only support registry-name and not workspace."
66+
),
5067
)
5168

5269
with self.argument_context("ml deployment-template update") as c:
@@ -59,7 +76,10 @@ def load_deployment_template_params(self):
5976
"registry_name",
6077
options_list=["--registry-name", "-r"],
6178
required=True,
62-
help="Name of the registry. This is required since deployment templates only support registry-name and not workspace.",
79+
help=(
80+
"Name of the registry. This is required since deployment templates "
81+
"only support registry-name and not workspace."
82+
),
6383
)
6484

6585
with self.argument_context("ml deployment-template archive") as c:
@@ -70,7 +90,10 @@ def load_deployment_template_params(self):
7090
"registry_name",
7191
options_list=["--registry-name", "-r"],
7292
required=True,
73-
help="Name of the registry. This is required since deployment templates only support registry-name and not workspace.",
93+
help=(
94+
"Name of the registry. This is required since deployment templates "
95+
"only support registry-name and not workspace."
96+
),
7497
)
7598

7699
with self.argument_context("ml deployment-template restore") as c:
@@ -81,5 +104,8 @@ def load_deployment_template_params(self):
81104
"registry_name",
82105
options_list=["--registry-name", "-r"],
83106
required=True,
84-
help="Name of the registry. This is required since deployment templates only support registry-name and not workspace.",
107+
help=(
108+
"Name of the registry. This is required since deployment templates "
109+
"only support registry-name and not workspace."
110+
),
85111
)

src/machinelearningservices/azext_mlv2/manual/commands.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,16 +231,19 @@ def load_command_table(self, _):
231231
custom_deployment_template = CliCommandType(operations_tmpl=custom_tmpl)
232232
g.custom_command("list", "ml_deployment_template_list", command_type=custom_deployment_template)
233233
g.custom_command("get", "ml_deployment_template_get", command_type=custom_deployment_template)
234-
g.custom_command("create", "ml_deployment_template_create", supports_no_wait=True, command_type=custom_deployment_template)
234+
g.custom_command("create", "ml_deployment_template_create", supports_no_wait=True,
235+
command_type=custom_deployment_template)
235236
g.generic_update_command(
236237
"update",
237238
getter_name="ml_deployment_template_get",
238239
getter_type=custom_deployment_template,
239240
setter_name="_ml_deployment_template_update",
240241
setter_type=custom_deployment_template,
241242
)
242-
g.custom_command("archive", "ml_deployment_template_archive", supports_no_wait=True, command_type=custom_deployment_template)
243-
g.custom_command("restore", "ml_deployment_template_restore", supports_no_wait=True, command_type=custom_deployment_template)
243+
g.custom_command("archive", "ml_deployment_template_archive", supports_no_wait=True,
244+
command_type=custom_deployment_template)
245+
g.custom_command("restore", "ml_deployment_template_restore", supports_no_wait=True,
246+
command_type=custom_deployment_template)
244247

245248
with self.command_group("ml compute", client_factory=cf_ml_cl) as g:
246249
custom_tmpl = "azext_mlv2.manual.custom.compute#{}"

src/machinelearningservices/azext_mlv2/manual/custom/deployment_template.py

Lines changed: 26 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# ---------------------------------------------------------
1+
# ---------------------------------------------------------
22
# Copyright (c) Microsoft Corporation. All rights reserved.
33
# ---------------------------------------------------------
44

@@ -10,11 +10,8 @@
1010
except ImportError:
1111
load_deployment_template = None
1212

13-
from azure.ai.ml.exceptions import ErrorCategory, ErrorTarget, UserErrorException, ValidationException
14-
1513
from .raise_error import log_and_raise_error
1614
from .utils import (
17-
_dump_entity_with_warnings,
1815
get_ml_client,
1916
is_not_found_error,
2017
wrap_lro,
@@ -30,7 +27,7 @@ def ml_deployment_template_list(cmd, registry_name=None):
3027
ml_client, debug = get_ml_client(
3128
cli_ctx=cmd.cli_ctx, registry_name=registry_name
3229
)
33-
30+
3431
try:
3532
deployment_templates = ml_client.deployment_templates.list()
3633
# Handle DeploymentTemplate serialization - try as_dict() first, then _to_dict()
@@ -57,16 +54,15 @@ def ml_deployment_template_get(cmd, name, version=None, registry_name=None):
5754
ml_client, debug = get_ml_client(
5855
cli_ctx=cmd.cli_ctx, registry_name=registry_name
5956
)
60-
57+
6158
try:
6259
deployment_template = ml_client.deployment_templates.get(name=name, version=version)
6360
# Handle DeploymentTemplate serialization
6461
if hasattr(deployment_template, 'as_dict'):
6562
return deployment_template.as_dict()
66-
elif hasattr(deployment_template, '_to_dict'):
63+
if hasattr(deployment_template, '_to_dict'):
6764
return deployment_template._to_dict() # pylint: disable=protected-access
68-
else:
69-
return dict(deployment_template)
65+
return dict(deployment_template)
7066
except Exception as err: # pylint: disable=broad-except
7167
if is_not_found_error(err):
7268
raise ValueError(f"Deployment template '{name}' with version '{version}' does not exist.") from err
@@ -87,35 +83,35 @@ def ml_deployment_template_create(
8783
ml_client, debug = get_ml_client(
8884
cli_ctx=cmd.cli_ctx, registry_name=registry_name
8985
)
90-
86+
9187
params_override = params_override or []
92-
88+
9389
try:
9490
if name:
9591
params_override.append({"name": name})
9692
if version:
9793
params_override.append({"version": version})
98-
94+
9995
if load_deployment_template:
10096
deployment_template = load_deployment_template(source=file, params_override=params_override)
10197
else:
10298
# Fallback: load YAML manually if load_deployment_template is not available
10399
import yaml
104100
if not file:
105101
raise ValueError("A YAML file must be provided for deployment template creation.")
106-
102+
107103
with open(file, 'r', encoding='utf-8') as f:
108104
yaml_content = yaml.safe_load(f)
109-
105+
110106
# Apply parameter overrides
111107
for override in params_override:
112108
if isinstance(override, dict):
113109
yaml_content.update(override)
114-
110+
115111
deployment_template = yaml_content
116-
112+
117113
deployment_template_result = ml_client.deployment_templates.create_or_update(deployment_template)
118-
114+
119115
if no_wait:
120116
module_logger.warning(
121117
"Deployment template create/update request initiated. "
@@ -124,16 +120,14 @@ def ml_deployment_template_create(
124120
deployment_template.version if hasattr(deployment_template, 'version') else version or "unknown"
125121
)
126122
return None
127-
else:
128-
deployment_template_result = wrap_lro(cmd.cli_ctx, deployment_template_result)
129-
123+
deployment_template_result = wrap_lro(cmd.cli_ctx, deployment_template_result)
124+
130125
# Handle serialization
131126
if hasattr(deployment_template_result, 'as_dict'):
132127
return deployment_template_result.as_dict()
133-
elif hasattr(deployment_template_result, '_to_dict'):
128+
if hasattr(deployment_template_result, '_to_dict'):
134129
return deployment_template_result._to_dict() # pylint: disable=protected-access
135-
else:
136-
return dict(deployment_template_result)
130+
return dict(deployment_template_result)
137131
except Exception as err: # pylint: disable=broad-except
138132
yaml_operation = bool(file)
139133
log_and_raise_error(err, debug, yaml_operation=yaml_operation)
@@ -158,10 +152,9 @@ def _ml_deployment_template_update(
158152
# Handle serialization
159153
if hasattr(deployment_template_result, 'as_dict'):
160154
return deployment_template_result.as_dict()
161-
elif hasattr(deployment_template_result, '_to_dict'):
155+
if hasattr(deployment_template_result, '_to_dict'):
162156
return deployment_template_result._to_dict() # pylint: disable=protected-access
163-
else:
164-
return dict(deployment_template_result)
157+
return dict(deployment_template_result)
165158
except Exception as err: # pylint: disable=broad-except
166159
log_and_raise_error(err, debug)
167160

@@ -171,19 +164,18 @@ def _ml_deployment_template_show(cmd, name, version=None, registry_name=None):
171164
ml_client, debug = get_ml_client(
172165
cli_ctx=cmd.cli_ctx, registry_name=registry_name
173166
)
174-
167+
175168
try:
176169
deployment_template = ml_client.deployment_templates.get(name=name, version=version)
177-
170+
178171
# Use to_rest_object to get proper field naming (snake_case instead of camelCase)
179172
if hasattr(deployment_template, 'to_rest_object'):
180173
return deployment_template.to_rest_object()
181-
elif hasattr(deployment_template, 'as_dict'):
174+
if hasattr(deployment_template, 'as_dict'):
182175
return deployment_template.as_dict()
183-
elif hasattr(deployment_template, '_to_dict'):
176+
if hasattr(deployment_template, '_to_dict'):
184177
return deployment_template._to_dict() # pylint: disable=protected-access
185-
else:
186-
return dict(deployment_template)
178+
return dict(deployment_template)
187179
except Exception as err: # pylint: disable=broad-except
188180
if is_not_found_error(err):
189181
raise ValueError(f"Deployment template '{name}' with version '{version}' does not exist.") from err
@@ -202,7 +194,7 @@ def ml_deployment_template_archive(
202194
ml_client, debug = get_ml_client(
203195
cli_ctx=cmd.cli_ctx, registry_name=registry_name
204196
)
205-
197+
206198
try:
207199
ml_client.deployment_templates.archive(name=name, version=version)
208200
except Exception as err: # pylint: disable=broad-except
@@ -221,11 +213,8 @@ def ml_deployment_template_restore(
221213
ml_client, debug = get_ml_client(
222214
cli_ctx=cmd.cli_ctx, registry_name=registry_name
223215
)
224-
216+
225217
try:
226218
ml_client.deployment_templates.restore(name=name, version=version)
227219
except Exception as err: # pylint: disable=broad-except
228220
log_and_raise_error(err, debug)
229-
230-
231-

0 commit comments

Comments
 (0)