azure-mgmt-resources
is an interesting package that is consisteting of sub-folders:
But it also has a azure/mgmt/resources/__init__.py
file that contains aliases to client, in order to avoid using the subnamespace:
from .managedapplications import ApplicationClient
from .deploymentscripts import DeploymentScriptsClient
from .features import FeatureClient
from .links import ManagementLinkClient
from .locks import ManagementLockClient
from .policy import PolicyClient
from .resources import ResourceManagementClient
from .subscriptions import SubscriptionClient
from .deploymentstacks import DeploymentStacksClient
from .databoundaries import DataBoundaryMgmtClient
__all__ = [
"ApplicationClient",
"DeploymentScriptsClient",
"FeatureClient",
"PolicyClient",
"ManagementLinkClient",
"ManagementLockClient",
"ResourceManagementClient",
"SubscriptionClient",
"DeploymentStacksClient",
"DataBoundaryMgmtClient",
]
To be clear, this was allowing people to import a client in two ways:
# Those two lines do the same thing
from azure.mgmt.resources import DeploymentScriptsClient
from azure.mgmt.resources.deploymentscripts import DeploymentScriptsClient
New package should follow the 4 part name convention. Example: azure-mgmt-resources-deploymentscripts
This package should contain the folder azure/mgmt/resources/deploymentscripts
in its entirety.
Remove the folder in question entirely.
For the __init__.py
, in case someone was using the alias import, remove the import and add that code:
def _build_compat_message(client_name: str, packagee_namee: str) -> str:
return f"""
{client_name} is no longer available in azure-mgmt-resources. Please use {package_name} instead.
You can import the client using `from {package_name.replace('-', '.')} import {client_name}
"""
def __getattr__(name: str):
if name == DeploymentScriptsClient:
raise ImportError(_build_compat_message("DeploymentScriptsClient", "azure-mgmt-resources-deploymentscripts")
raise AttributeError(f"module 'azure.mgmt.resources' has no attribute {name}")
-
Installing a new version of
azure-mgmt-resources
will break import ofazure.mgmt.resources.xxxxxx
Migration: Install the new package along, and things will work the same unchanged -
Installing a new version of
azure-mgmt-resources
will break import ofXXXClient
fromazure.mgmt.resources
Migration: Install the new package along, and update your import to importXXXClient
fromazure.mgmt.resources.xxxxxx
-
Installing together an old
azure-mgmt-resources
will overwrite code. Migration: It should actually work fine, this is the same code shipped twice. TBH, I have no conncerns on people using a mix of old and new, people have shown they update all.