-
Notifications
You must be signed in to change notification settings - Fork 270
Fix quadlet handling of duplicate options #1442
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
Conversation
Reviewer's GuideReplace the ConfigParser-based IniFile with a custom UnitFile to support duplicate options, update Quadlet methods to use UnitFile, and enhance tests with new input flags, mocks, and data cases. Sequence Diagram: Handling Duplicate Options with UnitFilesequenceDiagram
participant Q as Quadlet
participant UF as UnitFile
participant FS as FileSystem
Q->>UF: new UnitFile("service.container")
Q->>UF: add("ExampleSection", "MyKey", "value1")
Q->>UF: add("ExampleSection", "MyKey", "value2") # Duplicate key added
Q->>UF: write("/path/to/quadlets")
activate UF
UF->>FS: open("/path/to/quadlets/service.container", "w")
activate FS
FS-->>UF: file_handle
deactivate FS
UF->>UF: _write(file_handle) # Internal call to format output
UF->>FS: write_line(file_handle, "[ExampleSection]")
activate FS; deactivate FS
UF->>FS: write_line(file_handle, "MyKey=value1")
activate FS; deactivate FS
UF->>FS: write_line(file_handle, "MyKey=value2") # Duplicate key written
activate FS; deactivate FS
UF->>FS: write_line(file_handle, "\n")
activate FS; deactivate FS
UF->>FS: close(file_handle)
activate FS; deactivate FS
deactivate UF
Class Diagram: Refactoring IniFile to UnitFile for Quadlet ConfigurationclassDiagram
direction LR
class IniFile {
<<Replaced>>
+filename: str
-config: ConfigParser
+__init__(filename: str)
+add(section: str, key: str, value: str) void
+write(dirpath: str) void
}
class UnitFile {
<<New>>
+filename: str
-sections: dict
+__init__(filename: str)
+add(section: str, key: str, value: str) void
+write(dirpath: str) void
-_write(f: FileHandle) void
}
class Quadlet {
+model: str
+chat_template: str
+image: str
+args: object
+exec_args: list
+name: str
+rag: str
+rag_name: str
+__init__(model, chat_template, image, args, exec_args)
+kube() UnitFile
+generate() list~UnitFile~
-_gen_chat_template_volume(quadlet_file: UnitFile) void
-_gen_env(quadlet_file: UnitFile) void
-_gen_image(name, image) UnitFile
-_gen_name(quadlet_file: UnitFile) void
-_gen_model_volume(quadlet_file: UnitFile) list~UnitFile~
-_gen_port(quadlet_file: UnitFile) void
-_gen_rag_volume(quadlet_file: UnitFile) list~UnitFile~
}
Quadlet ..> UnitFile : Uses
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
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.
Hey @olliewalsh - I've reviewed your changes and found some issues that need to be addressed.
Blocking issues:
- Recursive call to write causes infinite recursion (link)
General comments:
- Avoid using mutable default arguments (e.g. env=[], exec_args=[], args=Args()) – use None and assign new lists/instances inside the constructor to prevent shared state.
- Replace print statements in Quadlet methods with a proper logging framework to avoid side-effects and allow configurable log levels.
- The need to call UnitFile._write in tests suggests the public write API could be refactored to accept file-like objects directly, removing reliance on the private method.
Here's what I looked at during the review
- 🔴 General issues: 1 blocking issue
- 🟢 Security: all looks good
- 🟡 Testing: 1 issue found
- 🟢 Complexity: all looks good
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
487bcf2 to
be2fc17
Compare
Re-implement without relying on ConfigParser which does not support duplicate options. Extend unit test coverage for this and correct the existing test data. Signed-off-by: Oliver Walsh <[email protected]>
be2fc17 to
82c45f2
Compare
|
@sourcery-ai review |
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.
Hey @olliewalsh - I've reviewed your changes and they look great!
Here's what I looked at during the review
- 🟡 General issues: 1 issue found
- 🟢 Security: all looks good
- 🟡 Testing: 1 issue found
- 🟢 Complexity: all looks good
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
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.
LGTM
Re-implement without relying on ConfigParser which does not support duplicate options.
Extend unit test coverage for this and correct the existing test data.
Summary by Sourcery
Re-implement quadlet file generation to support duplicate options by replacing the ConfigParser-based IniFile with a custom UnitFile, update Quadlet methods to use UnitFile, and extend unit tests to cover new model and chat-template scenarios with proper file-existence simulation.
Bug Fixes:
Enhancements:
Tests: