Open
Conversation
- Add format_qty() helper to prevent TypeError on None/string quantities - Replace import os with pathlib.Path.unlink() in cache clear - Remove unnecessary json module re-import in shopping export - Fix misleading secrets/cookidoo.env reference in docs - Lazy-load categories to avoid I/O at module import time
There was a problem hiding this comment.
Pull request overview
This PR improves the robustness and startup behavior of tmx_cli by centralizing quantity formatting, reducing redundant imports, updating documentation, and introducing a cached/lazy category loader to avoid doing category file I/O at module import time.
Changes:
- Added
format_qty()helper and replaced multiple ad-hocqty == int(qty)formatting blocks. - Replaced module-level category globals with a cached
get_categories()accessor and refreshed cache aftercategories sync. - Simplified file deletion (
Path.unlink()), removed an unnecessaryjsonre-import, and correctedlogincredential documentation.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
tmx_cli.py |
Adds format_qty(), introduces cached get_categories(), and simplifies cache clear / shopping export logic. |
references/commands.md |
Updates login credential documentation to match actual CLI behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
722
to
724
| if category: | ||
| cat_id = CATEGORIES.get(category.lower()) | ||
| cat_id = get_categories().get(category.lower()) | ||
| if cat_id: |
| search_parser.add_argument("-d", "--difficulty", choices=["easy", "medium", "advanced"], help="Schwierigkeitsgrad") | ||
| search_parser.add_argument("--tm", choices=["TM5", "TM6", "TM7"], help="Thermomix-Version") | ||
| search_parser.add_argument("-c", "--category", choices=list(CATEGORIES.keys()), help="Kategorie") | ||
| search_parser.add_argument("-c", "--category", choices=list(get_categories().keys()), help="Kategorie") |
Comment on lines
+232
to
+235
| _categories_cache = None | ||
|
|
||
|
|
||
| def get_categories() -> dict: |
Comment on lines
+235
to
+239
| def get_categories() -> dict: | ||
| """Get categories, loading from cache/fallback on first access.""" | ||
| global _categories_cache | ||
| if _categories_cache is None: | ||
| _categories_cache, _ = load_categories() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
format_qty()helper to safely format quantity values, preventingTypeErrorwhenqtyisNone, a string, or other non-numeric type — replaces 7+ rawqty == int(qty)checks spread across the fileimport osinside function incmd_cache_clear; replaceos.remove(path)withpath.unlink()using the already-importedpathlib.Pathimport json as json_moduleincmd_shopping_export—jsonis not shadowed (the format variable isfmt), so the top-level import can be used directlyreferences/commands.mdthat claimed credentials are stored insecrets/cookidoo.env— the code never reads from that file; corrected to reflect actual behavior (interactive prompt or environment variables)get_categories()instead of running file I/O at module import time; adds_categories_cacheand replaces allCATEGORIES/CATEGORY_NAMESglobal referencesTest plan
python3 -c "import tmx_cli"— should complete without file I/O side effects (categories not loaded until first use)tmx search -c hauptgericht—get_categories()called, returns correct category IDtmx recipe show <id>— servings and ingredient quantities display correctly for integer and decimal values, and for recipes where quantity isNoneor""tmx cache clear— cached files deleted without error (noimport osneeded)tmx shopping export --format json— JSON output produced correctly using top-leveljsonmoduletmx categories sync— categories reloaded into_categories_cacheand subsequentget_categories()calls return updated datareferences/commands.mdno longer referencessecrets/cookidoo.env🤖 Generated with Claude Code