Skip to content

Commit edf1164

Browse files
[bct] Support versioned modules (Azure#37100)
* support versioned modules * feedback --------- Co-authored-by: Catalina Peralta <[email protected]>
1 parent c10facd commit edf1164

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

scripts/breaking_changes_checker/detect_breaking_changes.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,9 @@ def get_overload_data(node: ast.ClassDef, cls_methods: Dict) -> None:
350350
public_func_nodes = [func for func in func_nodes if not func.name.startswith("_") or func.name.startswith("__init__")]
351351
# Check for method overloads on a class
352352
for func in public_func_nodes:
353+
if func.name not in cls_methods:
354+
_LOGGER.debug(f"Skipping overloads check for method {func.name}.")
355+
continue
353356
if "overloads" not in cls_methods[func.name]:
354357
cls_methods[func.name]["overloads"] = []
355358
is_async = False
@@ -437,6 +440,11 @@ def test_compare_reports(pkg_dir: str, changelog: bool, source_report: str = "st
437440
stable = json.load(fd)
438441
with open(os.path.join(pkg_dir, target_report), "r") as fd:
439442
current = json.load(fd)
443+
444+
if "azure-mgmt-" in package_name:
445+
stable = report_azure_mgmt_versioned_module(stable)
446+
current = report_azure_mgmt_versioned_module(current)
447+
440448
diff = jsondiff.diff(stable, current)
441449
checker = BreakingChangesTracker(
442450
stable,
@@ -469,6 +477,30 @@ def remove_json_files(pkg_dir: str) -> None:
469477
_LOGGER.info("cleaning up")
470478

471479

480+
def report_azure_mgmt_versioned_module(code_report):
481+
482+
def parse_module_name(module):
483+
split_module = module.split(".")
484+
# Azure mgmt packages are typically in the form of: azure.mgmt.<service>
485+
# If the module has a version, it will be in the form of: azure.mgmt.<service>.<version> or azure.mgmt.<service>.<version>.<submodule>
486+
if len(split_module) >= 4:
487+
for i in range(3, len(split_module)):
488+
if re.search(r"v\d{4}_\d{2}_\d{2}", split_module[i]):
489+
split_module.pop(i)
490+
break
491+
return ".".join(split_module)
492+
493+
sorted_modules = sorted(code_report.keys())
494+
merged_report = {}
495+
for module in sorted_modules:
496+
non_version_module_name = parse_module_name(module)
497+
if non_version_module_name not in merged_report:
498+
merged_report[non_version_module_name] = code_report[module]
499+
continue
500+
merged_report[non_version_module_name].update(code_report[module])
501+
return merged_report
502+
503+
472504
def main(
473505
package_name: str,
474506
target_module: str,

0 commit comments

Comments
 (0)