Skip to content

Commit 09b86c2

Browse files
Unexclude _local_endpoints folder (#33990)
* unexclude _local_endpoints folder * update * update
1 parent 02d019e commit 09b86c2

14 files changed

+99
-90
lines changed

sdk/ml/azure-ai-ml/azure/ai/ml/_local_endpoints/azureml_image_context.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55

66
import logging
7-
from pathlib import Path
87
import os
8+
from pathlib import Path
99
from typing import Dict
1010

1111
from azure.ai.ml.constants._endpoint import LocalEndpointConstants
@@ -108,7 +108,8 @@ def docker_conda_file_name(self) -> str:
108108
:return: The conda file name
109109
:rtype: str
110110
"""
111-
return self._docker_conda_file_name # pylint: disable=no-member
111+
# pylint: disable=no-member
112+
return self._docker_conda_file_name # type: ignore[attr-defined]
112113

113114
@property
114115
def volumes(self) -> Dict[str, Dict[str, Dict[str, str]]]:

sdk/ml/azure-ai-ml/azure/ai/ml/_local_endpoints/docker_client.py

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
module_logger = logging.getLogger(__name__)
2828
initialize_logger_info(module_logger, terminator="")
2929

30-
DEFAULT_LABELS = {
30+
DEFAULT_LABELS: Dict = {
3131
LocalEndpointConstants.LABEL_KEY_AZUREML_LOCAL_ENDPOINT: "",
3232
LocalEndpointConstants.LABEL_KEY_ENDPOINT_NAME: "",
3333
LocalEndpointConstants.LABEL_KEY_DEPLOYMENT_NAME: "",
@@ -45,14 +45,14 @@ class DockerClient(object):
4545

4646
def __init__(
4747
self,
48-
client: Optional["docker.DockerClient"] = None,
48+
client: Optional["docker.DockerClient"] = None, # type: ignore[name-defined]
4949
vscode_client: Optional[VSCodeClient] = None,
5050
):
5151
self._lazy_client = client
5252
self._vscode_client = vscode_client if vscode_client else VSCodeClient()
5353

5454
@property
55-
def _client(self) -> "docker.DockerClient":
55+
def _client(self) -> "docker.DockerClient": # type: ignore[name-defined]
5656
"""Lazy initializer for docker-py client.
5757
5858
:return: docker.client.DockerClient
@@ -184,8 +184,8 @@ def create_deployment(
184184
labels = get_container_labels(
185185
endpoint_name=endpoint_name,
186186
deployment_name=deployment_name,
187-
endpoint_metadata=endpoint_metadata,
188-
deployment_metadata=deployment_metadata,
187+
endpoint_metadata=endpoint_metadata, # type: ignore[arg-type]
188+
deployment_metadata=deployment_metadata, # type: ignore[arg-type]
189189
azureml_port=azureml_port,
190190
)
191191
module_logger.debug("Setting labels: '%s'\n", labels)
@@ -213,7 +213,7 @@ def create_deployment(
213213
build_directory=build_directory,
214214
image_name=image_name,
215215
environment=environment,
216-
volumes=volumes,
216+
volumes=volumes, # type: ignore[arg-type]
217217
labels=labels,
218218
)
219219
finally:
@@ -262,7 +262,7 @@ def delete(
262262
container.remove()
263263
module_logger.debug("Endpoint container '%s' is removed.", container.name)
264264

265-
def get_endpoint(self, endpoint_name: str) -> dict:
265+
def get_endpoint(self, endpoint_name: str) -> Optional[dict]:
266266
"""Returns metadata for local endpoint or deployment.
267267
268268
:param endpoint_name: name of local endpoint
@@ -275,7 +275,7 @@ def get_endpoint(self, endpoint_name: str) -> dict:
275275
raise LocalEndpointNotFoundError(endpoint_name=endpoint_name)
276276
return get_endpoint_json_from_container(container=container)
277277

278-
def get_deployment(self, endpoint_name: str, deployment_name: Optional[str] = None) -> dict:
278+
def get_deployment(self, endpoint_name: str, deployment_name: Optional[str] = None) -> Optional[dict]:
279279
"""Returns metadata for local deployment.
280280
281281
:param endpoint_name: name of local endpoint
@@ -290,7 +290,7 @@ def get_deployment(self, endpoint_name: str, deployment_name: Optional[str] = No
290290
raise LocalEndpointNotFoundError(endpoint_name=endpoint_name, deployment_name=deployment_name)
291291
return get_deployment_json_from_container(container=container)
292292

293-
def get_scoring_uri(self, endpoint_name: str, deployment_name: Optional[str] = None) -> str:
293+
def get_scoring_uri(self, endpoint_name: str, deployment_name: Optional[str] = None) -> Optional[str]:
294294
"""Returns scoring uri for local endpoint or deployment.
295295
296296
:param endpoint_name: name of local endpoint
@@ -309,7 +309,7 @@ def get_scoring_uri(self, endpoint_name: str, deployment_name: Optional[str] = N
309309
return None
310310
_validate_container_state(
311311
endpoint_name=endpoint_name,
312-
deployment_name=deployment_name,
312+
deployment_name=str(deployment_name),
313313
container=container,
314314
)
315315
return get_scoring_uri_from_container(container=container)
@@ -363,7 +363,7 @@ def get_endpoint_container(
363363
deployment_name: Optional[str] = None,
364364
verify_single_deployment: bool = False,
365365
include_stopped: bool = True,
366-
) -> "docker.models.containers.Container":
366+
) -> "docker.models.containers.Container": # type: ignore[name-defined]
367367
"""Builds and runs an image from provided image context.
368368
369369
:param endpoint_name: name of local endpoint
@@ -470,21 +470,25 @@ def get_container_labels(
470470
return labels
471471

472472

473-
def get_endpoint_json_from_container(container: "docker.models.containers.Container") -> dict:
473+
def get_endpoint_json_from_container(
474+
container: "docker.models.containers.Container", # type: ignore[name-defined]
475+
) -> Optional[dict]:
474476
if container:
475477
data = container.labels[LocalEndpointConstants.LABEL_KEY_ENDPOINT_JSON]
476478
return json.loads(data)
477479
return None
478480

479481

480-
def get_deployment_json_from_container(container: "docker.models.containers.Container") -> dict:
482+
def get_deployment_json_from_container(
483+
container: "docker.models.containers.Container", # type: ignore[name-defined]
484+
) -> Optional[dict]:
481485
if container:
482486
data = container.labels[LocalEndpointConstants.LABEL_KEY_DEPLOYMENT_JSON]
483487
return json.loads(data)
484488
return None
485489

486490

487-
def get_status_from_container(container: "docker.models.containers.Container") -> str:
491+
def get_status_from_container(container: "docker.models.containers.Container") -> str: # type: ignore[name-defined]
488492
"""Returns status of container.
489493
490494
:param container: container of local Deployment
@@ -495,7 +499,9 @@ def get_status_from_container(container: "docker.models.containers.Container") -
495499
return container.status
496500

497501

498-
def get_scoring_uri_from_container(container: "docker.models.containers.Container") -> str:
502+
def get_scoring_uri_from_container(
503+
container: "docker.models.containers.Container", # type: ignore[name-defined]
504+
) -> str:
499505
"""Returns scoring_uri of container.
500506
501507
:param container: container of local Deployment
@@ -547,7 +553,7 @@ def _get_container_name(endpoint_name: str, deployment_name: Optional[str] = Non
547553
def _validate_container_state(
548554
endpoint_name: str,
549555
deployment_name: str,
550-
container: "docker.models.containers.Container",
556+
container: "docker.models.containers.Container", # type: ignore[name-defined]
551557
):
552558
"""Returns a container name.
553559

sdk/ml/azure-ai-ml/azure/ai/ml/_local_endpoints/dockerfile_resolver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def _construct(self, install_debugpy: bool = False) -> None:
9393
self._instructions.extend(
9494
[
9595
Run(f"mkdir -p {self._docker_azureml_app_path}"),
96-
Workdir(self._docker_azureml_app_path),
96+
Workdir(str(self._docker_azureml_app_path)),
9797
]
9898
)
9999

sdk/ml/azure-ai-ml/azure/ai/ml/_local_endpoints/endpoint_stub.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def _create_endpoint_cache(self, endpoint: OnlineEndpoint) -> Path:
8282
:return: The endpoint cache path
8383
:rtype: Path
8484
"""
85-
endpoint_cache_path = self._get_endpoint_cache_file(endpoint_name=endpoint.name)
85+
endpoint_cache_path = self._get_endpoint_cache_file(endpoint_name=str(endpoint.name))
8686
endpoint_metadata = json.dumps(endpoint.dump())
8787
endpoint_cache_path.write_text(endpoint_metadata, encoding=DefaultOpenEncoding.WRITE)
8888
return endpoint_cache_path

sdk/ml/azure-ai-ml/azure/ai/ml/_local_endpoints/mdc_config_resolver.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import json
55
import os.path
66
from pathlib import Path
7+
from typing import Any, Dict
78

89
from azure.ai.ml.constants._common import DefaultOpenEncoding
910
from azure.ai.ml.entities._deployment.data_collector import DataCollector
@@ -21,9 +22,9 @@ def __init__(
2122
self,
2223
data_collector: DataCollector,
2324
):
24-
self.environment_variables = {}
25-
self.volumes = {}
26-
self.mdc_config = None
25+
self.environment_variables: Dict = {}
26+
self.volumes: Dict = {}
27+
self.mdc_config: Any = None
2728
self.config_path = "/etc/mdc-config.json"
2829
self.local_config_name = "mdc-config.json"
2930
self._construct(data_collector)

sdk/ml/azure-ai-ml/azure/ai/ml/_local_endpoints/validators/code_validator.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# pylint: disable=protected-access
66

77
from pathlib import Path
8+
from typing import Optional, Union
89

910
from azure.ai.ml._artifacts._artifact_utilities import download_artifact_from_storage_url
1011
from azure.ai.ml._utils._arm_id_utils import parse_prefixed_name_version
@@ -21,7 +22,7 @@ def get_code_configuration_artifacts(
2122
deployment: OnlineDeployment,
2223
code_operations: CodeOperations,
2324
download_path: str,
24-
) -> str:
25+
) -> Optional[Union[str, Path]]:
2526
"""Validates and returns code artifacts from deployment specification.
2627
2728
:param endpoint_name: name of endpoint which this deployment is linked to
@@ -51,7 +52,7 @@ def get_code_configuration_artifacts(
5152

5253
if _code_configuration_contains_cloud_artifacts(deployment=deployment):
5354
return _get_cloud_code_configuration_artifacts(
54-
deployment.code_configuration.code, code_operations, download_path
55+
str(deployment.code_configuration.code), code_operations, download_path
5556
)
5657

5758
if not _local_code_path_is_valid(deployment=deployment):

sdk/ml/azure-ai-ml/azure/ai/ml/_local_endpoints/validators/environment_validator.py

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66

77
import os
88
from pathlib import Path
9-
from typing import Dict, Optional, Tuple, Union
9+
from typing import Optional, Tuple, Union
1010

1111
from azure.ai.ml._artifacts._artifact_utilities import download_artifact_from_storage_url
12-
from azure.ai.ml._utils._arm_id_utils import parse_name_version, parse_name_label
12+
from azure.ai.ml._utils._arm_id_utils import parse_name_label, parse_name_version
1313
from azure.ai.ml._utils.utils import dump_yaml, is_url
1414
from azure.ai.ml.constants._common import DefaultOpenEncoding
1515
from azure.ai.ml.entities import OnlineDeployment
@@ -23,9 +23,7 @@ def get_environment_artifacts(
2323
deployment: OnlineDeployment,
2424
environment_operations: EnvironmentOperations,
2525
download_path: str,
26-
) -> Union[
27-
Tuple[str, Optional[Path], str, None, None, Optional[Dict]], Tuple[None, None, None, Path, str, Optional[Dict]]
28-
]:
26+
) -> Optional[Tuple]:
2927
"""Validates and returns artifacts from environment specification.
3028
3129
:param endpoint_name: name of endpoint which this deployment is linked to
@@ -82,16 +80,14 @@ def get_environment_artifacts(
8280
required_artifact_type=str(Environment),
8381
deployment_name=deployment.name,
8482
)
85-
return _get_local_environment_artifacts(deployment.base_path, deployment.environment)
83+
return _get_local_environment_artifacts(deployment.base_path, deployment.environment) # type: ignore[arg-type]
8684

8785

8886
def _get_cloud_environment_artifacts(
8987
environment_operations: EnvironmentOperations,
9088
environment_asset: Environment,
9189
download_path: str,
92-
) -> Union[
93-
Tuple[str, Optional[Path], str, None, None, Optional[Dict]], Tuple[None, None, None, Path, str, Optional[Dict]]
94-
]:
90+
) -> Tuple:
9591
"""Retrieves the cloud environment's artifacts
9692
9793
:param environment_operations: The environment operations
@@ -116,7 +112,7 @@ def _get_cloud_environment_artifacts(
116112
datastore_operation=environment_operations._datastore_operation,
117113
datastore_name="workspaceartifactstore",
118114
)
119-
dockerfile_path = Path(environment_build_directory, environment_asset.build.dockerfile_path)
115+
dockerfile_path = Path(environment_build_directory, str(environment_asset.build.dockerfile_path))
120116
dockerfile_contents = dockerfile_path.read_text(encoding=DefaultOpenEncoding.READ)
121117
return (
122118
None,
@@ -137,11 +133,7 @@ def _get_cloud_environment_artifacts(
137133
)
138134

139135

140-
def _get_local_environment_artifacts(
141-
base_path: Union[str, os.PathLike], environment: Environment
142-
) -> Union[
143-
Tuple[str, Optional[Path], str, None, None, Optional[Dict]], Tuple[None, None, None, Path, str, Optional[Dict]]
144-
]:
136+
def _get_local_environment_artifacts(base_path: Union[str, os.PathLike], environment: Environment) -> Optional[Tuple]:
145137
"""Retrieves the local environment's artifacts
146138
147139
:param base_path: The base path
@@ -168,7 +160,7 @@ def _get_local_environment_artifacts(
168160
environment.inference_config,
169161
)
170162
if environment.build and environment.build.dockerfile_path:
171-
absolute_build_directory = Path(base_path, environment.build.path).resolve()
163+
absolute_build_directory = Path(base_path, str(environment.build.path)).resolve()
172164
absolute_dockerfile_path = Path(absolute_build_directory, environment.build.dockerfile_path).resolve()
173165
dockerfile_contents = absolute_dockerfile_path.read_text(encoding=DefaultOpenEncoding.READ)
174166
return (
@@ -205,4 +197,6 @@ def _cloud_environment_is_valid(environment: Environment):
205197

206198

207199
def _environment_contains_cloud_artifacts(deployment: OnlineDeployment):
208-
return isinstance(deployment.environment, str) or deployment.environment.id is not None
200+
return isinstance(deployment.environment, str) or (
201+
deployment.environment is not None and deployment.environment.id is not None
202+
)

sdk/ml/azure-ai-ml/azure/ai/ml/_local_endpoints/validators/model_validator.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44

55
# pylint: disable=protected-access
66

7+
from os import PathLike
78
from pathlib import Path
8-
from typing import Tuple
9+
from typing import Tuple, Union
910

1011
from azure.ai.ml._artifacts._artifact_utilities import download_artifact
1112
from azure.ai.ml._utils._arm_id_utils import parse_prefixed_name_version
@@ -21,7 +22,7 @@ def get_model_artifacts(
2122
deployment: OnlineDeployment,
2223
model_operations: ModelOperations,
2324
download_path: str,
24-
) -> Tuple[str, str, Path]:
25+
) -> Union[str, Tuple]:
2526
"""Validates and returns model artifacts from deployment specification.
2627
2728
:param endpoint_name: name of endpoint which this deployment is linked to
@@ -41,7 +42,7 @@ def get_model_artifacts(
4142
if _model_contains_cloud_artifacts(deployment=deployment):
4243
return _get_cloud_model_artifacts(
4344
model_operations=model_operations,
44-
model=deployment.model,
45+
model=str(deployment.model),
4546
download_path=download_path,
4647
)
4748
if not _local_model_is_valid(deployment=deployment):
@@ -51,10 +52,12 @@ def get_model_artifacts(
5152
required_artifact_type=str,
5253
deployment_name=deployment.name,
5354
)
55+
_model: Model = deployment.model # type: ignore[assignment]
56+
_model_path: Union[str, PathLike] = _model.path # type: ignore[assignment]
5457
return (
55-
deployment.model.name,
56-
deployment.model.version,
57-
Path(deployment._base_path, deployment.model.path).resolve().parent,
58+
_model.name,
59+
_model.version,
60+
Path(deployment._base_path, _model_path).resolve().parent,
5861
)
5962

6063

@@ -64,10 +67,10 @@ def _local_model_is_valid(deployment: OnlineDeployment):
6467

6568
def _model_contains_cloud_artifacts(deployment: OnlineDeployment):
6669
# If the deployment.model is a string, then it is the cloud model name or full arm ID
67-
return isinstance(deployment.model, str) or deployment.model.id is not None
70+
return isinstance(deployment.model, str) or (deployment.model is not None and deployment.model.id is not None)
6871

6972

70-
def _get_cloud_model_artifacts(model_operations: ModelOperations, model: str, download_path: str) -> str:
73+
def _get_cloud_model_artifacts(model_operations: ModelOperations, model: str, download_path: str) -> Tuple:
7174
if isinstance(model, Model):
7275
name = model.name
7376
version = model._version

sdk/ml/azure-ai-ml/azure/ai/ml/_local_endpoints/vscode_debug/devcontainer_properties.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# Reference: https://code.visualstudio.com/docs/remote/devcontainerjson-reference
77

88

9-
from typing import Optional
9+
from typing import Dict, Optional
1010

1111
from azure.ai.ml.constants._endpoint import LocalEndpointConstants
1212

@@ -37,7 +37,7 @@ def __init__(
3737
self._target = target
3838

3939
def to_dict(self) -> dict:
40-
build = {
40+
build: Dict = {
4141
"build": {
4242
"dockerfile": self._dockerfile_path,
4343
}

0 commit comments

Comments
 (0)