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 25 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
36 changes: 36 additions & 0 deletions devtools/debug_parameterization.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# 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._parameterization._validate_parameter_file import validate_parameter_file

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

# 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,
# Uncomment to include target environment in validation
# environment=environment,
# Uncomment to provide alternative parameter file name
# parameter_file_name="alternative_name_parameter.yml",
# Uncomment to use SPN auth
# token_credential=token_credential,
# Uncomment to set log level to DEBUG
# set_log_level=True,
)
23 changes: 20 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._parameterization._parameterization_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,21 @@ 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
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
41 changes: 41 additions & 0 deletions src/fabric_cicd/_parameterization/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

"""Provides tools for validating a Parameter.yml file."""

import logging
import sys

from fabric_cicd._common._logging import configure_logger, exception_handler
from fabric_cicd._parameterization._parameter_validation import ParameterValidation

logger = logging.getLogger(__name__)


def change_log_level(level: str = "DEBUG") -> None:
"""
Sets the log level for all loggers within the fabric_cicd package. Currently only supports DEBUG.

Args:
level: The logging level to set (e.g., DEBUG).

Examples:
Basic usage
>>> from fabric_cicd import change_log_level
>>> change_log_level("DEBUG")
"""
if level.upper() == "DEBUG":
configure_logger(logging.DEBUG)
logger.info("Changed log level to DEBUG")
else:
logger.warning(f"Log level '{level}' not supported. Only DEBUG is supported at this time. No changes made.")


configure_logger()
sys.excepthook = exception_handler


__all__ = [
"ParameterValidation",
"change_log_level",
]
Loading