Skip to content

Resolves #113 Refactor Parameterization #128

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 38 commits into from
Mar 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
e913686
update replace parameter method draft
Feb 26, 2025
98377e3
fix logging
Feb 26, 2025
d74d957
sample parameterization
Feb 26, 2025
6eb2b72
updates to methods and parameterization
Feb 26, 2025
bee9eba
n/a
Feb 27, 2025
56eb2f7
addtional refactors
Feb 28, 2025
046da75
remove redundant bool reference
Feb 28, 2025
2881d85
sample file
Feb 28, 2025
93544a6
more updates
Mar 3, 2025
2c229ab
parameter validation class
Mar 4, 2025
21a1cb7
new changes
Mar 7, 2025
9fc345d
more changes
Mar 7, 2025
12f01ec
unit tests
Mar 7, 2025
a6499d9
new changes and unit tests
Mar 10, 2025
57d39af
updates
Mar 13, 2025
d086b08
parameter validation unit tests
Mar 13, 2025
f4a3ca2
cleanup
Mar 13, 2025
d57031e
add validation step to fabric workspace
Mar 13, 2025
4c43d67
changes
Mar 18, 2025
ee33121
update unit tests
Mar 18, 2025
88c290d
add comment
Mar 18, 2025
c754379
fix grammer
Mar 18, 2025
d0ef403
fix comment
Mar 18, 2025
2474313
add comment
Mar 18, 2025
cd2e824
simplify struc check
Mar 18, 2025
8676ea5
Merge branch 'main' into refactor_parameterization
shirasassoon Mar 18, 2025
acab011
lint fixes
Mar 18, 2025
966f06e
add utf-8 handling in yaml read
Mar 18, 2025
11e21c4
changes
Mar 19, 2025
80b0eb9
Merge branch 'main' into refactor_parameterization
shirasassoon Mar 19, 2025
6ea7871
update replace_parameters
Mar 19, 2025
f9817ca
implement constants
Mar 19, 2025
b6e993e
refactored parameter class
Mar 20, 2025
b8dcd14
implement feedback
Mar 24, 2025
74f132f
update comments
Mar 24, 2025
3135839
update parameter file sample
Mar 24, 2025
e0d4efb
remove space
Mar 24, 2025
cf05b4b
Merge branch 'main' into refactor_parameterization
shirasassoon Mar 24, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions devtools/debug_parameterization.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

# The following is intended for developers of fabric-cicd to debug parameter.yml file locally against the github repo

import sys
from pathlib import Path

from azure.identity import ClientSecretCredential

from fabric_cicd import change_log_level
from fabric_cicd._parameter._utils import validate_parameter_file
from fabric_cicd.constants import PARAMETER_FILE_NAME

root_directory = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(root_directory / "src"))

# Uncomment to enable debug
# change_log_level()

# In this example, the parameter.yml file sits within the root/sample/workspace directory
repository_directory = str(root_directory / "sample" / "workspace")

# Explicitly define valid item types
item_type_in_scope = ["DataPipeline", "Notebook", "Environment", "SemanticModel", "Report"]

# Set target environment
environment = "PPE"

validate_parameter_file(
repository_directory=repository_directory,
item_type_in_scope=item_type_in_scope,
# Comment to exclude target environment in validation
environment=environment,
# Uncomment to pass in an alternative parameter file name
# Assign to the constant in constants.py or pass in a string directly
# parameter_file_name=PARAMETER_FILE_NAME,
# Uncomment to use SPN auth
# token_credential=token_credential,
)
54 changes: 46 additions & 8 deletions sample/workspace/parameter.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,53 @@
find_replace:
# SQL Connection Guid
"db52be81-c2b2-4261-84fa-840c67f4bbd0":
# Lakehouse Connection Guid
- find_value: "db52be81-c2b2-4261-84fa-840c67f4bbd0"
replace_value:
PPE: "81bbb339-8d0b-46e8-bfa6-289a159c0733"
PROD: "5d6a1b16-447f-464a-b959-45d0fed35ca0"
# Optional fields:
item_type: "Notebook"
item_name: ["Hello World", "Hello World Subfolder"]
file_path:
- "/Hello World.Notebook/notebook-content.py"
- "\\subfolder\\Hello World Subfolder.Notebook/notebook-content.py"

spark_pool:
# CapacityPool_Large
"72c68dbc-0775-4d59-909d-a47896f4573b":
type: "Capacity"
name: "CapacityPool_Large"
- instance_pool_id: "72c68dbc-0775-4d59-909d-a47896f4573b"
replace_value:
PPE:
type: "Capacity"
name: "CapacityPool_Large_PPE"
PROD:
type: "Capacity"
name: "CapacityPool_Large_PROD"
# Optional field:
item_name: "World"
# CapacityPool_Medium
- instance_pool_id: "e7b8f1c4-4a6e-4b8b-9b2e-8f1e5d6a9c3d"
replace_value:
PPE:
type: "Workspace"
name: "WorkspacePool_Medium"
PROD:
type: "Workspace"
name: "WorkspacePool_Medium"
# Optional field:
item_name:

# Legacy structure
#find_replace:
# SQL Connection Guid
#"db52be81-c2b2-4261-84fa-840c67f4bbd0":
#PPE: "81bbb339-8d0b-46e8-bfa6-289a159c0733"
#PROD: "5d6a1b16-447f-464a-b959-45d0fed35ca0"

#spark_pool:
# CapacityPool_Large
#"72c68dbc-0775-4d59-909d-a47896f4573b":
#type: "Capacity"
#name: "CapacityPool_Large"
# CapacityPool_Medium
"e7b8f1c4-4a6e-4b8b-9b2e-8f1e5d6a9c3d":
type: "Workspace"
name: "WorkspacePool_Medium"
#"e7b8f1c4-4a6e-4b8b-9b2e-8f1e5d6a9c3d":
#type: "Workspace"
#name: "WorkspacePool_Medium"
4 changes: 4 additions & 0 deletions src/fabric_cicd/_common/_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,7 @@ class ItemDependencyError(BaseCustomError):

class FileTypeError(BaseCustomError):
pass


class ParameterFileError(BaseCustomError):
pass
24 changes: 21 additions & 3 deletions src/fabric_cicd/_items/_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

from fabric_cicd import FabricWorkspace
from fabric_cicd._common._fabric_endpoint import handle_retry
from fabric_cicd._parameter._utils import check_parameter_structure

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -60,7 +61,7 @@ def _publish_environment_metadata(fabric_workspace_obj: FabricWorkspace, item_na
_check_environment_publish_state(fabric_workspace_obj, item_guid, initial_check=True)

# Update compute settings
_update_compute_settings(fabric_workspace_obj, item_path, item_guid)
_update_compute_settings(fabric_workspace_obj, item_path, item_guid, item_name)

repo_library_files = _get_repo_libraries(item_path)

Expand Down Expand Up @@ -128,14 +129,17 @@ def _check_environment_publish_state(
iteration += 1


def _update_compute_settings(fabric_workspace_obj: FabricWorkspace, item_path: Path, item_guid: str) -> None:
def _update_compute_settings(
fabric_workspace_obj: FabricWorkspace, item_path: Path, item_guid: str, item_name: str
) -> None:
"""
Update spark compute settings.

Args:
fabric_workspace_obj: The FabricWorkspace object.
item_path: The path to the environment item.
item_guid: The GUID of the environment item.
item_name: Name of the environment item.
"""
# Read compute settings from YAML file
with Path.open(Path(item_path, "Setting", "Sparkcompute.yml"), "r+", encoding="utf-8") as f:
Expand All @@ -145,8 +149,22 @@ def _update_compute_settings(fabric_workspace_obj: FabricWorkspace, item_path: P
if "instance_pool_id" in yaml_body:
pool_id = yaml_body["instance_pool_id"]
if "spark_pool" in fabric_workspace_obj.environment_parameter:
structure_type = check_parameter_structure(fabric_workspace_obj.environment_parameter, "spark_pool")
parameter_dict = fabric_workspace_obj.environment_parameter["spark_pool"]
if pool_id in parameter_dict:
# Handle new parameter file format
if structure_type == "new":
for key in parameter_dict:
instance_pool_id = key["instance_pool_id"]
replace_value = key["replace_value"]
input_name = key.get("item_name")
if instance_pool_id == pool_id and (input_name == item_name or not input_name):
# replace any found references with specified environment value
yaml_body["instancePool"] = replace_value[fabric_workspace_obj.environment]
del yaml_body["instance_pool_id"]

# Handle original parameter file format
# TODO: Deprecate old structure handling by April 24, 2025
if structure_type == "old" and pool_id in parameter_dict:
# replace any found references with specified environment value
yaml_body["instancePool"] = parameter_dict[pool_id]
del yaml_body["instance_pool_id"]
Expand Down
3 changes: 3 additions & 0 deletions src/fabric_cicd/_parameter/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

Loading