Commit b3ff8fa
refactor(core): use generic package mapping for optional dependency checks (#25)
* Initial plan
* fix(core): add 'ag_ui' to optional dependency error check
Add "ag_ui" to the error message checking logic in __getattr__ to properly
handle import errors when ag-ui-protocol is not installed. This ensures users
get helpful error messages when trying to use AGUIProtocolHandler or other
AG-UI related components without the server optional dependencies installed.
Addresses feedback from PR #23 review comment.
Co-authored-by: OhYee <[email protected]>
* refactor(core): use generic package mapping for optional dependency checks
Refactor the import error handling to use a more maintainable and scalable
approach with a package mapping structure instead of hardcoded string checks.
Changes:
- Added _OPTIONAL_PACKAGES list with (import_name, install_name) tuples
- Refactored __getattr__ to iterate through the package mapping
- Now easier to add new optional dependencies in the future
- All three server optional dependencies (fastapi, uvicorn, ag_ui) registered
This makes the codebase more maintainable when adding new optional
dependencies in the future.
Addresses feedback from @OhYee on PR #23.
Co-authored-by: OhYee <[email protected]>
* fix(core): restore specificity in error message and add clarifying comment
Address code review feedback:
- Restored "server" context in error message for better clarity
- Added comment clarifying that all entries are for server-related dependencies
- Maintains generic approach while preserving helpful context for users
This ensures users get clear, specific error messages while keeping the code
maintainable for future extensions.
Co-authored-by: OhYee <[email protected]>
* refactor(core): use constant for server install command to reduce duplication
Extract the repeated install command string into a constant _SERVER_INSTALL_CMD
to make the code more maintainable and easier to update in the future.
This addresses code review feedback about reducing duplication in the package
mapping structure.
Co-authored-by: OhYee <[email protected]>
* refactor(core): group packages by install command in _OPTIONAL_PACKAGES
Refactor _OPTIONAL_PACKAGES from a list of tuples to a dictionary that groups
packages by their installation command. This provides better organization when
multiple packages share the same installation command.
Changes:
- Changed from list of (package, install_cmd) tuples to dict of {install_cmd: [packages]}
- Removed _SERVER_INSTALL_CMD constant (now a dict key)
- Updated iteration logic to handle nested structure
- All three server packages (fastapi, uvicorn, ag_ui) grouped together
Benefits:
- Clearer relationship: install command -> packages it provides
- More compact when packages share the same install command
- Easier to see all packages for a given installation
- Scalable for future optional dependency groups
Addresses feedback from @OhYee about merging packages with the same command.
Co-authored-by: OhYee <[email protected]>
---------
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: OhYee <[email protected]>1 parent 9aa51c8 commit b3ff8fa
1 file changed
+16
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
289 | 289 | | |
290 | 290 | | |
291 | 291 | | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
292 | 299 | | |
293 | 300 | | |
294 | 301 | | |
| |||
303 | 310 | | |
304 | 311 | | |
305 | 312 | | |
306 | | - | |
307 | | - | |
308 | | - | |
309 | | - | |
310 | | - | |
311 | | - | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
312 | 322 | | |
313 | 323 | | |
314 | 324 | | |
| |||
0 commit comments