-
Notifications
You must be signed in to change notification settings - Fork 229
examples-automation, special handling for azure-resourcemanager at tsp #13447
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -177,10 +177,10 @@ def process_java_example(filepath: str) -> List[JavaExample]: | |||||||||||||||||||||
| lines = f.readlines() | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| class_name = filename.split(".")[0] | ||||||||||||||||||||||
| return process_java_example_content(lines, class_name) | ||||||||||||||||||||||
| return process_java_example_content(lines, class_name, filepath) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| def process_java_example_content(lines: List[str], class_name: str) -> List[JavaExample]: | ||||||||||||||||||||||
| def process_java_example_content(lines: List[str], class_name: str, filepath: str = None) -> List[JavaExample]: | ||||||||||||||||||||||
| java_examples = [] | ||||||||||||||||||||||
| if is_aggregated_java_example(lines): | ||||||||||||||||||||||
| aggregated_java_example = break_down_aggregated_java_example(lines) | ||||||||||||||||||||||
|
|
@@ -199,8 +199,20 @@ def process_java_example_content(lines: List[str], class_name: str) -> List[Java | |||||||||||||||||||||
| example_dir, example_filename = path.split(example_filepath) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| try: | ||||||||||||||||||||||
| sdk_package_path_updated = sdk_package_path | ||||||||||||||||||||||
| if filepath and sdk_package_path.endswith("/resourcemanager/azure-resourcemanager"): | ||||||||||||||||||||||
| # special handling for libs included in azure-resourcemanager, as samples in it are copied | ||||||||||||||||||||||
| # from other packages. | ||||||||||||||||||||||
| # this behavior can change, if in automation we no longer do such copy. | ||||||||||||||||||||||
|
Comment on lines
+204
to
+206
|
||||||||||||||||||||||
| # special handling for libs included in azure-resourcemanager, as samples in it are copied | |
| # from other packages. | |
| # this behavior can change, if in automation we no longer do such copy. | |
| # Special handling for libs included in azure-resourcemanager, as samples in it are currently | |
| # copied from other resource-manager packages. We remap sdk_package_path to the original | |
| # per-service package so that example lookup works correctly. | |
| # If the automation is updated so that samples are no longer copied into | |
| # azure-resourcemanager (for example, they are generated and validated in-place for each | |
| # azure-resourcemanager-* package), this remapping will no longer be necessary and | |
| # sdk_package_path can be used directly here. |
Copilot
AI
Jan 22, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The path split logic assumes a specific directory structure depth. Using split("/")[-3] is fragile and may fail if the filepath structure changes or has a different depth. Consider using a more robust approach to extract the package name, such as parsing the package declaration from the Java file or using a regex pattern to extract the service name from a known base path.
Copilot
AI
Jan 22, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rstrip operation with a path string is incorrect. The rstrip method removes characters from a set, not a substring. For example, if sdk_package_path is "/path/to/resourcemanager/azure-resourcemanager", this will remove any trailing 'r', 'e', 'g', 'a', 'n', 'a', 'm', 'e', 'c', 'u', 'o', 's', 'e', 'r', '-', 'e', 'r', 'u', 'z', 'a', or '/' characters, not the exact substring. Use removesuffix (Python 3.9+) or string slicing instead.
| sdk_package_path_updated = path.join( | |
| sdk_package_path.rstrip("/resourcemanager/azure-resourcemanager"), | |
| suffix = "/resourcemanager/azure-resourcemanager" | |
| base_sdk_package_path = sdk_package_path[: -len(suffix)] | |
| sdk_package_path_updated = path.join( | |
| base_sdk_package_path, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The filepath should be validated before extracting the package name. If the filepath is None or doesn't contain enough path segments, this will fail with an unclear IndexError. Consider adding a check to ensure the filepath matches the expected structure.