-
Notifications
You must be signed in to change notification settings - Fork 0
Add method to convert set options dictionary to string format for Docker Buildx Bake #361
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 | ||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -202,6 +202,24 @@ def remove(self): | |||||||||||||||||||||||||||||||||||||||
| """Delete the bake plan file if it exists.""" | ||||||||||||||||||||||||||||||||||||||||
| self.bake_file.unlink(missing_ok=True) | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| @staticmethod | ||||||||||||||||||||||||||||||||||||||||
| def _set_opts_dict_to_str(set_opts: dict[str, Any]) -> dict[str, str]: | ||||||||||||||||||||||||||||||||||||||||
| """Convert a dictionary of set options to a comma-delimited, key=value string format for Docker Buildx Bake. | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| :param set_opts: A dictionary of set options to convert. | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| :return: A dictionary of set options with string values. | ||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||
| for opt, data in set_opts.items(): | ||||||||||||||||||||||||||||||||||||||||
| if isinstance(data, list): | ||||||||||||||||||||||||||||||||||||||||
| set_opts[opt] = ",".join(data) | ||||||||||||||||||||||||||||||||||||||||
| elif isinstance(data, dict): | ||||||||||||||||||||||||||||||||||||||||
| set_opts[opt] = ",".join(f"{k}={v}" for k, v in data.items()) | ||||||||||||||||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||||||||||||||||
| set_opts[opt] = str(data) | ||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+215
to
+219
|
||||||||||||||||||||||||||||||||||||||||
| set_opts[opt] = ",".join(data) | |
| elif isinstance(data, dict): | |
| set_opts[opt] = ",".join(f"{k}={v}" for k, v in data.items()) | |
| else: | |
| set_opts[opt] = str(data) | |
| set_opts[opt] = ",".join( | |
| str(v).lower() if isinstance(v, bool) else str(v) for v in data | |
| ) | |
| elif isinstance(data, dict): | |
| set_opts[opt] = ",".join( | |
| f"{k}={str(v).lower() if isinstance(v, bool) else str(v)}" | |
| for k, v in data.items() | |
| ) | |
| else: | |
| set_opts[opt] = str(data).lower() if isinstance(data, bool) else str(data) |
Copilot
AI
Feb 20, 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 method mutates the input dictionary directly by modifying set_opts in place. This can lead to unexpected side effects if the caller retains a reference to the original dictionary. Consider creating a new dictionary instead of modifying the input. For example, you could initialize a new dictionary result = {} and populate it in the loop, then return result instead of set_opts.
| for opt, data in set_opts.items(): | |
| if isinstance(data, list): | |
| set_opts[opt] = ",".join(data) | |
| elif isinstance(data, dict): | |
| set_opts[opt] = ",".join(f"{k}={v}" for k, v in data.items()) | |
| else: | |
| set_opts[opt] = str(data) | |
| return set_opts | |
| result: dict[str, str] = {} | |
| for opt, data in set_opts.items(): | |
| if isinstance(data, list): | |
| result[opt] = ",".join(data) | |
| elif isinstance(data, dict): | |
| result[opt] = ",".join(f"{k}={v}" for k, v in data.items()) | |
| else: | |
| result[opt] = str(data) | |
| return result |
Copilot
AI
Feb 20, 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 new _set_opts_dict_to_str method lacks test coverage. Given that the repository has comprehensive test coverage for similar methods (as seen in test_bake.py with tests for other BakePlan methods), consider adding tests to verify the correct conversion of different data types (lists, dicts, strings, numbers, booleans) to their string representations. This is especially important since this method handles the critical task of formatting parameters for Docker Buildx Bake.
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
joinoperation assumes all list items are strings. If the list contains non-string types (e.g., numbers, booleans), this will raise a TypeError. Consider converting list items to strings:",".join(str(item) for item in data). Note that boolean values should be lowercased for Docker compatibility, so you may need",".join(str(item).lower() if isinstance(item, bool) else str(item) for item in data).