Skip to content

Commit 53034ff

Browse files
authored
[ml] Hit next-pylint compliance (#35342)
* Remove Optional type annotation from get() methods * Remove duplicate overloads * Remove interrogate from pre-commit-config * Ignore bare exception errors * Update disable comment for exceptions * Fix more errors * Fix exception disable comments * Fix exception disable comments * Fix pylint errors * Fix import pylint error * Reformat with black * Fix dictionary literal error * Fix sphinx error in sweep * Add clarifying note about kwargs to from_config
1 parent 79a8083 commit 53034ff

File tree

94 files changed

+285
-355
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+285
-355
lines changed

sdk/ml/azure-ai-ml/.pre-commit-config.yaml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,6 @@ repos:
55
hooks:
66
- id: black
77
args: [--config=eng/black-pyproject.toml]
8-
- repo: https://github.com/econchick/interrogate
9-
rev: 1.5.0
10-
hooks:
11-
- id: interrogate
12-
types_or: [python]
13-
args: [--ignore-init-method, --ignore-private, --ignore-semiprivate, --ignore-magic]
14-
exclude: ^(sdk/ml/azure-ai-ml/tests/|sdk/ml/azure-ai-ml/samples/|sdk/ml/azure-ai-ml/scripts/|sdk/ml/azure-ai-ml/azure/ai/ml/_restclient|sdk/ml/azure-ai-ml/setup.py)
15-
# exclude defined here because exclude in pyproject.toml is not being respected
168
- repo: https://github.com/streetsidesoftware/cspell-cli
179
rev: v6.31.0
1810
hooks:

sdk/ml/azure-ai-ml/azure/ai/ml/_arm_deployments/arm_deployment_executor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def deploy_resource(
111111

112112
if poller._exception is not None:
113113
error = poller._exception
114-
except Exception as e: # pylint: disable=broad-except
114+
except Exception as e: # pylint: disable=W0718
115115
error = e
116116
finally:
117117
# one last check to make sure all print statements make it
@@ -213,7 +213,7 @@ def _check_deployment_status(self) -> None:
213213
# duration comes in format: "PT1M56.3454108S"
214214
try:
215215
duration_in_min_sec = from_iso_duration_format_min_sec(duration)
216-
except Exception: # pylint: disable=broad-except
216+
except Exception: # pylint: disable=W0718
217217
duration_in_min_sec = ""
218218

219219
self._resources_being_deployed[resource_name] = (

sdk/ml/azure-ai-ml/azure/ai/ml/_artifacts/_artifact_utilities.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
from azure.ai.ml.entities._assets._artifacts.artifact import Artifact, ArtifactStorageInfo
4545
from azure.ai.ml.entities._credentials import AccountKeyConfiguration
4646
from azure.ai.ml.entities._datastore._constants import WORKSPACE_BLOB_STORE
47-
from azure.ai.ml.exceptions import ErrorTarget, ValidationException
47+
from azure.ai.ml.exceptions import ErrorTarget, MlException, ValidationException
4848
from azure.ai.ml.operations._datastore_operations import DatastoreOperations
4949
from azure.storage.blob import BlobSasPermissions, generate_blob_sas
5050
from azure.storage.filedatalake import FileSasPermissions, generate_file_sas
@@ -116,7 +116,7 @@ def get_datastore_info(
116116
else:
117117
try:
118118
datastore_info["credential"] = credential.sas_token
119-
except Exception as e: # pylint: disable=broad-except
119+
except Exception as e: # pylint: disable=W0718
120120
if not hasattr(credential, "sas_token"):
121121
datastore_info["credential"] = operations._credential
122122
else:
@@ -127,10 +127,11 @@ def get_datastore_info(
127127
elif datastore.type == DatastoreType.AZURE_DATA_LAKE_GEN2:
128128
datastore_info["container_name"] = str(datastore.filesystem)
129129
else:
130-
raise Exception(
130+
msg = (
131131
f"Datastore type {datastore.type} is not supported for uploads. "
132132
f"Supported types are {DatastoreType.AZURE_BLOB} and {DatastoreType.AZURE_DATA_LAKE_GEN2}."
133133
)
134+
raise MlException(message=msg, no_personal_data_message=msg)
134135

135136
for override_param_name, value in kwargs.items():
136137
if override_param_name in datastore_info:
@@ -162,7 +163,8 @@ def list_logs_in_datastore(
162163
DatastoreType.AZURE_BLOB,
163164
DatastoreType.AZURE_DATA_LAKE_GEN2,
164165
]:
165-
raise Exception("Only Blob and Azure DataLake Storage Gen2 datastores are supported.")
166+
msg = "Only Blob and Azure DataLake Storage Gen2 datastores are supported."
167+
raise MlException(message=msg, no_personal_data_message=msg)
166168

167169
storage_client = get_storage_client(
168170
credential=ds_info["credential"],

sdk/ml/azure-ai-ml/azure/ai/ml/_artifacts/_blob_storage_helper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ def check_blob_exists(self) -> None:
196196
self.overwrite = True # if upload never confirmed, approve overriding the partial upload
197197
except ResourceNotFoundError:
198198
pass
199-
except Exception as e: # pylint: disable=broad-except
199+
except Exception as e: # pylint: disable=W0718
200200
# pylint: disable=no-member
201201
if hasattr(e, "error_code") and e.error_code == STORAGE_AUTH_MISMATCH_ERROR:
202202
msg = (

sdk/ml/azure-ai-ml/azure/ai/ml/_artifacts/_gen2_storage_helper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ def check_blob_exists(self) -> None:
165165
self.name = metadata.get("name")
166166
self.version = metadata.get("version")
167167
raise AssetNotChangedError
168-
except Exception as e: # pylint: disable=broad-except
168+
except Exception as e: # pylint: disable=W0718
169169
# pylint: disable=no-member
170170
if hasattr(e, "error_code") and e.error_code == STORAGE_AUTH_MISMATCH_ERROR:
171171
msg = (

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
from azure.ai.ml._utils.utils import _get_mfe_url_override
1212
from azure.ai.ml.constants._common import AZUREML_CLOUD_ENV_NAME, ArmConstants
13+
from azure.ai.ml.exceptions import MlException
1314
from azure.core.rest import HttpRequest
1415
from azure.mgmt.core import ARMPipelineClient
1516

@@ -73,7 +74,8 @@ def _get_cloud(cloud: str) -> Dict[str, str]:
7374
_environments.update(new_cloud) # type: ignore[arg-type]
7475
return new_cloud
7576
except KeyError as e:
76-
raise Exception('Unknown cloud environment "{0}".'.format(cloud)) from e
77+
msg = 'Unknown cloud environment "{0}".'.format(cloud)
78+
raise MlException(message=msg, no_personal_data_message=msg) from e
7779

7880

7981
def _get_default_cloud_name() -> str:
@@ -111,7 +113,8 @@ def _set_cloud(cloud: str = AzureEnvironments.ENV_DEFAULT):
111113
try:
112114
_get_cloud(cloud)
113115
except Exception as e:
114-
raise Exception('Unknown cloud environment supplied: "{0}".'.format(cloud)) from e
116+
msg = 'Unknown cloud environment supplied: "{0}".'.format(cloud)
117+
raise MlException(message=msg, no_personal_data_message=msg) from e
115118
else:
116119
cloud = _get_default_cloud_name()
117120
os.environ[AZUREML_CLOUD_ENV_NAME] = cloud

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import json
66
import logging
77
import traceback
8-
from typing import Dict, Optional, Tuple, Union, NoReturn
8+
from typing import Dict, NoReturn, Optional, Tuple, Union
99

1010
from colorama import Fore, Style, init
1111
from marshmallow.exceptions import ValidationError as SchemaValidationError
@@ -15,7 +15,7 @@
1515
SCHEMA_VALIDATION_ERROR_TEMPLATE,
1616
YAML_CREATION_ERROR_DESCRIPTION,
1717
)
18-
from azure.ai.ml.exceptions import ErrorTarget, ValidationErrorType, ValidationException
18+
from azure.ai.ml.exceptions import ErrorTarget, MlException, ValidationErrorType, ValidationException
1919

2020
module_logger = logging.getLogger(__name__)
2121

@@ -334,4 +334,4 @@ def log_and_raise_error(error: Exception, debug: bool = False, yaml_operation: b
334334
else:
335335
raise error
336336

337-
raise Exception(formatted_error)
337+
raise MlException(message=formatted_error, no_personal_data_message=formatted_error)

sdk/ml/azure-ai-ml/azure/ai/ml/_internal/entities/component.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ def _read_additional_include_configs(cls, yaml_path: Path) -> List[str]:
187187
configs = yaml.safe_load(file_content)
188188
if isinstance(configs, dict):
189189
return configs.get(_ADDITIONAL_INCLUDES_CONFIG_KEY, [])
190-
except Exception: # pylint: disable=broad-except
190+
except Exception: # pylint: disable=W0718
191191
# TODO: check if we should catch yaml.YamlError instead here
192192
pass
193193
return [line.strip() for line in file_content.splitlines(keepends=False) if len(line.strip()) > 0]

sdk/ml/azure-ai-ml/azure/ai/ml/_logging/debug_mode.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def stack_info() -> list:
4242

4343
def connection_info(gc_objects: list) -> List[ConnectionInfo]:
4444
connections = [obj for obj in gc_objects if isinstance(obj, http.client.HTTPConnection)]
45-
return [ConnectionInfo(host=c.host, port=c.port, hasSocket=(c.sock is not None)) for c in connections]
45+
return [ConnectionInfo(host=c.host, port=c.port, hasSocket=c.sock is not None) for c in connections] # disable
4646

4747

4848
# pylint: disable=client-incorrect-naming-convention

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,8 @@ def from_config(
698698
}
699699
700700
Then, you can use this method to load the same workspace in different Python notebooks or projects without
701-
retyping the workspace ARM properties.
701+
retyping the workspace ARM properties. Note that `from_config` accepts the same kwargs as the main
702+
`~azure.ai.ml.MLClient` constructor such as `cloud`.
702703
703704
:param credential: The credential object for the workspace.
704705
:type credential: ~azure.core.credentials.TokenCredential
@@ -708,8 +709,6 @@ def from_config(
708709
:keyword file_name: The configuration file name to search for when path is a directory path. Defaults to
709710
"config.json".
710711
:paramtype file_name: Optional[str]
711-
:keyword cloud: The cloud name to use. Defaults to "AzureCloud".
712-
:paramtype cloud: Optional[str]
713712
:raises ~azure.ai.ml.exceptions.ValidationException: Raised if "config.json", or file_name if overridden,
714713
cannot be found in directory. Details will be provided in the error message.
715714
:returns: The client for an existing Azure ML Workspace.

0 commit comments

Comments
 (0)