From ad701c0fb3a0dc195ea3c1577e9556629da3b8e8 Mon Sep 17 00:00:00 2001 From: Manya Sharma <214554783+ManyaS-Git@users.noreply.github.com> Date: Fri, 14 Aug 2026 20:25:35 +0530 Subject: [PATCH] Fix bugs in Azure ML CI helper scripts Fix several bugs in .ci/scripts/aml_creation.py and .ci/scripts/aml_attach_blob.py: - aml_creation.py: the workspace creation block was indented inside the option-parsing 'for' loop, so Workspace.create was invoked once per CLI option instead of once. Also removed leftover cookiecutter template placeholders after __main__. - aml_attach_blob.py: all five datastore CLI options (-dsn/-cn/-an/-ak/-drg) were assigned to 'workspace_region' due to a copy-paste error, leaving the actual variables unbound and raising NameError at Datastore registration. Each option now stores into its own variable. Added the missing Datastore import, fixed the same indentation bug, and corrected the usage message that incorrectly referenced aml_creation.py. --- .ci/scripts/aml_attach_blob.py | 58 ++++++++++++++++++---------------- .ci/scripts/aml_creation.py | 34 ++++++++------------ 2 files changed, 44 insertions(+), 48 deletions(-) diff --git a/.ci/scripts/aml_attach_blob.py b/.ci/scripts/aml_attach_blob.py index 2bd2b0c..5ce388f 100644 --- a/.ci/scripts/aml_attach_blob.py +++ b/.ci/scripts/aml_attach_blob.py @@ -1,7 +1,7 @@ #!/usr/bin/python import azureml.core -from azureml.core import Workspace +from azureml.core import Workspace, Datastore from dotenv import set_key, get_key, find_dotenv from pathlib import Path from AIHelpers.utilities import get_auth @@ -13,11 +13,11 @@ def main(argv): opts, args = getopt.getopt(argv,"hs:rg:wn:wr:dsn:cn:an:ak:drg:", ["subscription_id=","resource_group=","workspace_name=", "workspace_region=","blob_datastore_name=","container_name=","account_name=","account_key=","datastore_rg="]) except getopt.GetoptError: - print 'aml_creation.py -s -rg -wn -wr ' + print 'aml_attach_blob.py -s -rg -wn -wr -dsn -cn -an -ak -drg ' sys.exit(2) for opt, arg in opts: if opt == '-h': - print 'aml_creation.py -s -rg -wn -wr ' + print 'aml_attach_blob.py -s -rg -wn -wr -dsn -cn -an -ak -drg ' sys.exit() elif opt in ("-s", "--subscription_id"): subscription_id = arg @@ -28,36 +28,38 @@ def main(argv): elif opt in ("-wr", "--workspace_region"): workspace_region = arg elif opt in ("-dsn", "--blob_datastore_name"): - workspace_region = arg + blob_datastore_name = arg elif opt in ("-cn", "--container_name"): - workspace_region = arg + container_name = arg elif opt in ("-an", "--account_name"): - workspace_region = arg + account_name = arg elif opt in ("-ak", "--account_key"): - workspace_region = arg + account_key = arg elif opt in ("-drg", "--datastore_rg"): - workspace_region = arg - - env_path = find_dotenv() - if env_path == "": - Path(".env").touch() - env_path = find_dotenv() + datastore_rg = arg + + env_path = find_dotenv() + if env_path == "": + Path(".env").touch() + env_path = find_dotenv() - ws = Workspace.create( - name=workspace_name, - subscription_id=subscription_id, - resource_group=resource_group, - location=workspace_region, - create_resource_group=True, - auth=get_auth(env_path), - exist_ok=True, - ) - blob_datastore = Datastore.register_azure_blob_container(workspace=ws, - datastore_name=blob_datastore_name, - container_name=container_name, - account_name=account_name, - account_key=account_key, - resource_group=datastore_rg) + ws = Workspace.create( + name=workspace_name, + subscription_id=subscription_id, + resource_group=resource_group, + location=workspace_region, + create_resource_group=True, + auth=get_auth(env_path), + exist_ok=True, + ) + blob_datastore = Datastore.register_azure_blob_container( + workspace=ws, + datastore_name=blob_datastore_name, + container_name=container_name, + account_name=account_name, + account_key=account_key, + resource_group=datastore_rg, + ) if __name__ == "__main__": print("AML SDK Version:", azureml.core.VERSION) diff --git a/.ci/scripts/aml_creation.py b/.ci/scripts/aml_creation.py index c5bfc46..e3fbed3 100644 --- a/.ci/scripts/aml_creation.py +++ b/.ci/scripts/aml_creation.py @@ -26,28 +26,22 @@ def main(argv): workspace_name = arg elif opt in ("-wr", "--workspace_region"): workspace_region = arg - - env_path = find_dotenv() - if env_path == "": - Path(".env").touch() - env_path = find_dotenv() - ws = Workspace.create( - name=workspace_name, - subscription_id=subscription_id, - resource_group=resource_group, - location=workspace_region, - create_resource_group=True, - auth=get_auth(env_path), - exist_ok=True, - ) + env_path = find_dotenv() + if env_path == "": + Path(".env").touch() + env_path = find_dotenv() + + ws = Workspace.create( + name=workspace_name, + subscription_id=subscription_id, + resource_group=resource_group, + location=workspace_region, + create_resource_group=True, + auth=get_auth(env_path), + exist_ok=True, + ) if __name__ == "__main__": print("AML SDK Version:", azureml.core.VERSION) main(sys.argv[1:]) - - # Azure resources - subscription_id = "{{cookiecutter.subscription_id}}" - resource_group = "{{cookiecutter.resource_group}}" - workspace_name = "{{cookiecutter.workspace_name}}" - workspace_region = "{{cookiecutter.workspace_region}}"