Skip to content

Commit 33ca6d1

Browse files
Unexclude _scope_dependent_operation.py file (#34039)
* update * update after merge from main - 2
1 parent c8f68ca commit 33ca6d1

File tree

10 files changed

+61
-55
lines changed

10 files changed

+61
-55
lines changed

sdk/ml/azure-ai-ml/azure/ai/ml/_ml_client.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -212,14 +212,14 @@ def __init__(
212212
if registry_name or registry_reference:
213213
# get the workspace location here if workspace_reference is provided
214214
self._ws_operation_scope = OperationScope(
215-
subscription_id,
216-
resource_group_name,
215+
str(subscription_id),
216+
str(resource_group_name),
217217
workspace_name,
218218
)
219219
workspace_reference = kwargs.pop("workspace_reference", None)
220220
if workspace_reference or registry_reference:
221221
ws_ops = WorkspaceOperations(
222-
OperationScope(subscription_id, resource_group_name, workspace_reference),
222+
OperationScope(str(subscription_id), str(resource_group_name), workspace_reference),
223223
ServiceClient042023Preview(
224224
credential=self._credential,
225225
subscription_id=subscription_id,
@@ -246,8 +246,8 @@ def __init__(
246246
workspace_name = workspace_reference
247247

248248
self._operation_scope = OperationScope(
249-
subscription_id,
250-
resource_group_name,
249+
str(subscription_id),
250+
str(resource_group_name),
251251
workspace_name,
252252
registry_name,
253253
workspace_id,
@@ -426,7 +426,7 @@ def __init__(
426426
dataplane_client=self._service_client_workspace_dataplane,
427427
**app_insights_handler_kwargs,
428428
)
429-
self._operation_container.add(AzureMLResourceType.WORKSPACE, self._workspaces)
429+
self._operation_container.add(AzureMLResourceType.WORKSPACE, self._workspaces) # type: ignore[arg-type]
430430

431431
self._workspace_outbound_rules = WorkspaceOutboundRuleOperations(
432432
self._operation_scope,
@@ -444,7 +444,7 @@ def __init__(
444444
self._credential,
445445
**app_insights_handler_kwargs,
446446
)
447-
self._operation_container.add(AzureMLResourceType.REGISTRY, self._registries)
447+
self._operation_container.add(AzureMLResourceType.REGISTRY, self._registries) # type: ignore[arg-type]
448448

449449
self._workspace_connections = WorkspaceConnectionsOperations(
450450
self._operation_scope,
@@ -604,7 +604,9 @@ def __init__(
604604
_service_client_kwargs=kwargs,
605605
**ops_kwargs,
606606
)
607-
self._operation_container.add(AzureMLResourceType.VIRTUALCLUSTER, self._virtual_clusters)
607+
self._operation_container.add(
608+
AzureMLResourceType.VIRTUALCLUSTER, self._virtual_clusters # type: ignore[arg-type]
609+
)
608610
except Exception as ex: # pylint: disable=broad-except
609611
module_logger.debug("Virtual Cluster operations could not be initialized due to %s ", ex)
610612

@@ -639,9 +641,9 @@ def __init__(
639641
self._credential,
640642
**app_insights_handler_kwargs,
641643
)
642-
self._operation_container.add(AzureMLResourceType.WORKSPACE_HUB, self._workspace_hubs)
644+
self._operation_container.add(AzureMLResourceType.WORKSPACE_HUB, self._workspace_hubs) # type: ignore[arg-type]
643645

644-
self._operation_container.add(AzureMLResourceType.FEATURE_STORE, self._featurestores)
646+
self._operation_container.add(AzureMLResourceType.FEATURE_STORE, self._featurestores) # type: ignore[arg-type]
645647
self._operation_container.add(AzureMLResourceType.FEATURE_SET, self._featuresets)
646648
self._operation_container.add(AzureMLResourceType.FEATURE_STORE_ENTITY, self._featurestoreentities)
647649

sdk/ml/azure-ai-ml/azure/ai/ml/_scope_dependent_operations.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,7 @@
77
import logging
88
from typing import Callable, Dict, Optional, TypeVar, cast
99

10-
from azure.ai.ml.exceptions import (
11-
ErrorCategory,
12-
ErrorTarget,
13-
ValidationErrorType,
14-
ValidationException,
15-
)
10+
from azure.ai.ml.exceptions import ErrorCategory, ErrorTarget, ValidationErrorType, ValidationException
1611

1712
T = TypeVar("T")
1813
module_logger = logging.getLogger(__name__)
@@ -77,14 +72,14 @@ def resource_group_name(self) -> str:
7772
def workspace_name(self) -> Optional[str]:
7873
return self._workspace_name
7974

80-
@property
81-
def registry_name(self) -> Optional[str]:
82-
return self._registry_name
83-
8475
@workspace_name.setter
8576
def workspace_name(self, value: str) -> None:
8677
self._workspace_name = value
8778

79+
@property
80+
def registry_name(self) -> Optional[str]:
81+
return self._registry_name
82+
8883
@registry_name.setter
8984
def registry_name(self, value: str) -> None:
9085
self._registry_name = value
@@ -94,7 +89,7 @@ class _ScopeDependentOperations(object):
9489
def __init__(self, operation_scope: OperationScope, operation_config: OperationConfig):
9590
self._operation_scope = operation_scope
9691
self._operation_config = operation_config
97-
self._scope_kwargs = {
92+
self._scope_kwargs: Dict = {
9893
"resource_group_name": self._operation_scope.resource_group_name,
9994
}
10095

@@ -128,7 +123,7 @@ def __init__(self):
128123
self._all_operations = {}
129124

130125
@property
131-
def all_operations(self) -> Dict[str, _ScopeDependentOperations]:
126+
def all_operations(self) -> Dict:
132127
return self._all_operations
133128

134129
def add(self, name: str, operation: _ScopeDependentOperations) -> None:

sdk/ml/azure-ai-ml/azure/ai/ml/entities/_deployment/deployment_collection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def _from_rest_object(cls, rest_obj: RestCollection) -> "DeploymentCollection":
5454

5555
def _to_rest_object(self) -> RestCollection:
5656
return RestCollection(
57-
data_collection_mode="enabled" if self.enabled.lower() == "true" else "disabled",
57+
data_collection_mode="enabled" if str(self.enabled).lower() == "true" else "disabled",
5858
sampling_rate=self.sampling_rate,
5959
data_id=self.data,
6060
client_id=self.client_id,

sdk/ml/azure-ai-ml/azure/ai/ml/operations/_component_operations.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def __init__(
112112

113113
@property
114114
def _code_operations(self) -> CodeOperations:
115-
res: CodeOperations = self._all_operations.get_operation(
115+
res: CodeOperations = self._all_operations.get_operation( # type: ignore[misc]
116116
AzureMLResourceType.CODE, lambda x: isinstance(x, CodeOperations)
117117
)
118118
return res
@@ -121,7 +121,7 @@ def _code_operations(self) -> CodeOperations:
121121
def _environment_operations(self) -> EnvironmentOperations:
122122
return cast(
123123
EnvironmentOperations,
124-
self._all_operations.get_operation(
124+
self._all_operations.get_operation( # type: ignore[misc]
125125
AzureMLResourceType.ENVIRONMENT,
126126
lambda x: isinstance(x, EnvironmentOperations),
127127
),
@@ -131,7 +131,7 @@ def _environment_operations(self) -> EnvironmentOperations:
131131
def _workspace_operations(self) -> WorkspaceOperations:
132132
return cast(
133133
WorkspaceOperations,
134-
self._all_operations.get_operation(
134+
self._all_operations.get_operation( # type: ignore[misc]
135135
AzureMLResourceType.WORKSPACE,
136136
lambda x: isinstance(x, WorkspaceOperations),
137137
),
@@ -141,7 +141,9 @@ def _workspace_operations(self) -> WorkspaceOperations:
141141
def _job_operations(self) -> Any:
142142
from ._job_operations import JobOperations
143143

144-
return self._all_operations.get_operation(AzureMLResourceType.JOB, lambda x: isinstance(x, JobOperations))
144+
return self._all_operations.get_operation( # type: ignore[misc]
145+
AzureMLResourceType.JOB, lambda x: isinstance(x, JobOperations)
146+
)
145147

146148
@monitor_with_activity(logger, "Component.List", ActivityType.PUBLICAPI)
147149
def list(

sdk/ml/azure-ai-ml/azure/ai/ml/operations/_data_operations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def __init__(
114114
service_client: Union[ServiceClient042023_preview, ServiceClient102021Dataplane],
115115
service_client_012024_preview: ServiceClient012024_preview,
116116
datastore_operations: DatastoreOperations,
117-
**kwargs: Dict,
117+
**kwargs: Any,
118118
):
119119
super(DataOperations, self).__init__(operation_scope, operation_config)
120120
ops_logger.update_info(kwargs)

sdk/ml/azure-ai-ml/azure/ai/ml/operations/_job_operations.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ def __init__(
184184
def _component_operations(self) -> ComponentOperations:
185185
return cast(
186186
ComponentOperations,
187-
self._all_operations.get_operation(
187+
self._all_operations.get_operation( # type: ignore[misc]
188188
AzureMLResourceType.COMPONENT, lambda x: isinstance(x, ComponentOperations)
189189
),
190190
)
@@ -193,14 +193,16 @@ def _component_operations(self) -> ComponentOperations:
193193
def _compute_operations(self) -> ComputeOperations:
194194
return cast(
195195
ComputeOperations,
196-
self._all_operations.get_operation(AzureMLResourceType.COMPUTE, lambda x: isinstance(x, ComputeOperations)),
196+
self._all_operations.get_operation( # type: ignore[misc]
197+
AzureMLResourceType.COMPUTE, lambda x: isinstance(x, ComputeOperations)
198+
),
197199
)
198200

199201
@property
200202
def _virtual_cluster_operations(self) -> VirtualClusterOperations:
201203
return cast(
202204
VirtualClusterOperations,
203-
self._all_operations.get_operation(
205+
self._all_operations.get_operation( # type: ignore[misc]
204206
AzureMLResourceType.VIRTUALCLUSTER, lambda x: isinstance(x, VirtualClusterOperations)
205207
),
206208
)

sdk/ml/azure-ai-ml/azure/ai/ml/operations/_model_operations.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def __init__(
101101
operation_config: OperationConfig,
102102
service_client: Union[ServiceClient082023Preview, ServiceClient102021Dataplane],
103103
datastore_operations: DatastoreOperations,
104-
all_operations: OperationsContainer = None,
104+
all_operations: Optional[OperationsContainer] = None,
105105
**kwargs: Dict,
106106
):
107107
super(ModelOperations, self).__init__(operation_scope, operation_config)
@@ -631,7 +631,7 @@ def package(self, name: str, version: str, package_request: ModelPackage, **kwar
631631
is_deployment_flow = kwargs.pop("skip_to_rest", False)
632632
if not is_deployment_flow:
633633
orchestrators = OperationOrchestrator(
634-
operation_container=self._all_operations,
634+
operation_container=self._all_operations, # type: ignore[arg-type]
635635
operation_scope=self._operation_scope,
636636
operation_config=self._operation_config,
637637
)
@@ -681,13 +681,14 @@ def package(self, name: str, version: str, package_request: ModelPackage, **kwar
681681
if self._operation_scope._workspace_location and self._operation_scope._workspace_id:
682682
package_request.target_environment_id = f"azureml://locations/{self._operation_scope._workspace_location}/workspaces/{self._operation_scope._workspace_id}/environments/{package_request.target_environment_id}"
683683
else:
684-
ws = self._all_operations.all_operations.get("workspaces")
685-
ws_details = ws.get(self._workspace_name)
686-
workspace_location, workspace_id = (
687-
ws_details.location,
688-
ws_details._workspace_id,
689-
)
690-
package_request.target_environment_id = f"azureml://locations/{workspace_location}/workspaces/{workspace_id}/environments/{package_request.target_environment_id}"
684+
if self._all_operations is not None:
685+
ws: Any = self._all_operations.all_operations.get("workspaces")
686+
ws_details = ws.get(self._workspace_name)
687+
workspace_location, workspace_id = (
688+
ws_details.location,
689+
ws_details._workspace_id,
690+
)
691+
package_request.target_environment_id = f"azureml://locations/{workspace_location}/workspaces/{workspace_id}/environments/{package_request.target_environment_id}"
691692

692693
if package_request.environment_version is not None:
693694
package_request.target_environment_id = (
@@ -747,7 +748,8 @@ def package(self, name: str, version: str, package_request: ModelPackage, **kwar
747748
package_out = Environment._from_rest_object(env_out)
748749
self._scope_kwargs["resource_group_name"] = current_rg
749750
else:
750-
environment_operation = self._all_operations.all_operations[AzureMLResourceType.ENVIRONMENT]
751-
package_out = environment_operation.get(name=environment_name, version=environment_version)
751+
if self._all_operations is not None:
752+
environment_operation = self._all_operations.all_operations[AzureMLResourceType.ENVIRONMENT]
753+
package_out = environment_operation.get(name=environment_name, version=environment_version)
752754

753755
return package_out

sdk/ml/azure-ai-ml/azure/ai/ml/operations/_operation_orchestrator.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -276,10 +276,10 @@ def _get_code_asset_arm_id(self, code_asset: Code, register_asset: bool = True)
276276
try:
277277
self._validate_datastore_name(code_asset.path)
278278
if register_asset:
279-
code_asset = self._code_assets.create_or_update(code_asset)
279+
code_asset = self._code_assets.create_or_update(code_asset) # type: ignore[attr-defined]
280280
return str(code_asset.id)
281281
sas_info = get_storage_info_for_non_registry_asset(
282-
service_client=self._code_assets._service_client,
282+
service_client=self._code_assets._service_client, # type: ignore[attr-defined]
283283
workspace_name=self._operation_scope.workspace_name,
284284
name=code_asset.name,
285285
version=code_asset.version,
@@ -315,7 +315,7 @@ def _get_environment_arm_id(self, environment: Environment, register_asset: bool
315315
if register_asset:
316316
if environment.id:
317317
return environment.id
318-
env_response = self._environments.create_or_update(environment)
318+
env_response = self._environments.create_or_update(environment) # type: ignore[attr-defined]
319319
return env_response.id
320320
environment = _check_and_upload_env_build_context(
321321
environment=environment, operations=self._environments, show_progress=self._operation_config.show_progress
@@ -335,7 +335,7 @@ def _get_model_arm_id(self, model: Model, register_asset: bool = True) -> Union[
335335
if register_asset:
336336
if model.id:
337337
return model.id
338-
return self._model.create_or_update(model).id
338+
return self._model.create_or_update(model).id # type: ignore[attr-defined]
339339
uploaded_model, _ = _check_and_upload_path(
340340
artifact=model,
341341
asset_operations=self._model,
@@ -364,7 +364,7 @@ def _get_data_arm_id(self, data_asset: Data, register_asset: bool = True) -> Uni
364364
self._validate_datastore_name(data_asset.path)
365365

366366
if register_asset:
367-
return self._data.create_or_update(data_asset).id
367+
return self._data.create_or_update(data_asset).id # type: ignore[attr-defined]
368368
data_asset, _ = _check_and_upload_path(
369369
artifact=data_asset,
370370
asset_operations=self._data,
@@ -385,7 +385,7 @@ def _get_component_arm_id(self, component: Component) -> str:
385385
# If component arm id is already resolved, return the id otherwise get arm id via remote call.
386386
# Register the component if necessary, and FILL BACK the arm id to component to reduce remote call.
387387
if not component.id:
388-
component._id = self._component.create_or_update(
388+
component._id = self._component.create_or_update( # type: ignore[attr-defined]
389389
component, is_anonymous=True, show_progress=self._operation_config.show_progress
390390
).id
391391
return str(component.id)
@@ -396,14 +396,14 @@ def _get_singularity_arm_id_from_full_name(self, singularity: str) -> str:
396396
resource_group_name = match.group("resource_group_name") if match is not None else ""
397397
vc_name = match.group("name") if match is not None else ""
398398
arm_id = SINGULARITY_ID_FORMAT.format(subscription_id, resource_group_name, vc_name)
399-
vc = self._virtual_cluster.get(arm_id)
399+
vc = self._virtual_cluster.get(arm_id) # type: ignore[attr-defined]
400400
return str(vc["id"])
401401

402402
def _get_singularity_arm_id_from_short_name(self, singularity: str) -> str:
403403
match = re.match(SINGULARITY_SHORT_NAME_REGEX_FORMAT, singularity)
404404
vc_name = match.group("name") if match is not None else ""
405405
# below list operation can be time-consuming, may need an optimization on this
406-
match_vcs = [vc for vc in self._virtual_cluster.list() if vc["name"] == vc_name]
406+
match_vcs = [vc for vc in self._virtual_cluster.list() if vc["name"] == vc_name] # type: ignore[attr-defined]
407407
num_match_vc = len(match_vcs)
408408
if num_match_vc != 1:
409409
if num_match_vc == 0:
@@ -524,7 +524,7 @@ def _validate_datastore_name(self, datastore_uri: Optional[Union[str, PathLike]]
524524
if datastore_name.startswith(ARM_ID_PREFIX):
525525
datastore_name = datastore_name[len(ARM_ID_PREFIX) :]
526526

527-
self._datastore_operation.get(datastore_name)
527+
self._datastore_operation.get(datastore_name) # type: ignore[attr-defined]
528528
except ResourceNotFoundError as e:
529529
msg = "The datastore {} could not be found in this workspace."
530530
raise ValidationException(

sdk/ml/azure-ai-ml/azure/ai/ml/operations/_schedule_operations.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,16 @@ def __init__(
9292
def _job_operations(self) -> JobOperations:
9393
return cast(
9494
JobOperations,
95-
self._all_operations.get_operation(AzureMLResourceType.JOB, lambda x: isinstance(x, JobOperations)),
95+
self._all_operations.get_operation( # type: ignore[misc]
96+
AzureMLResourceType.JOB, lambda x: isinstance(x, JobOperations)
97+
),
9698
)
9799

98100
@property
99101
def _online_deployment_operations(self) -> OnlineDeploymentOperations:
100102
return cast(
101103
OnlineDeploymentOperations,
102-
self._all_operations.get_operation(
104+
self._all_operations.get_operation( # type: ignore[misc]
103105
AzureMLResourceType.ONLINE_DEPLOYMENT, lambda x: isinstance(x, OnlineDeploymentOperations)
104106
),
105107
)
@@ -108,7 +110,9 @@ def _online_deployment_operations(self) -> OnlineDeploymentOperations:
108110
def _data_operations(self) -> DataOperations:
109111
return cast(
110112
DataOperations,
111-
self._all_operations.get_operation(AzureMLResourceType.DATA, lambda x: isinstance(x, DataOperations)),
113+
self._all_operations.get_operation( # type: ignore[misc]
114+
AzureMLResourceType.DATA, lambda x: isinstance(x, DataOperations)
115+
),
112116
)
113117

114118
@distributed_trace

sdk/ml/azure-ai-ml/pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ exclude = [
4343
"azure/ai/ml/sweep/",
4444
"azure/ai/ml/_azure_environments.py",
4545
"azure/ai/ml/exceptions.py",
46-
"azure/ai/ml/_scope_dependent_operations.py",
4746
"azure/ai/ml/_exception_helper.py",
4847
]
4948
warn_unused_configs = true

0 commit comments

Comments
 (0)