Refactor claude#11
Open
Trophime wants to merge 51 commits into
Open
Conversation
Splits the 684-line single-function cli.py into a structured package: - cli/__init__.py: Slim entry point with main() (~50 lines) - cli/context.py: CLIContext dataclass managing session and config - cli/base.py: BaseCommand ABC with shared helper methods - cli/parser.py: Argument parser factory - cli/commands/: Individual command handlers (list, view, create, delete, setup, run, compute, process), each independently testable Also adds tests/cli/ with unit and integration tests (10 tests, all passing), and updates pyproject.toml to include the new sub-packages. No breaking changes: CLI interface remains identical. https://claude.ai/code/session_01RGS93ciEnBTDhyxMw7yTaj
Type hints and docstrings: - cli/__init__.py: argv typed as Optional[List[str]] - cli/context.py: __enter__ -> CLIContext, __exit__ parameter types + -> None - cli/base.py: OBJECT_TYPES constant (List[str]) - All configure_parser() methods: added Args: docstring section - compute.py private methods: typed obj as Dict[str, Any] - setup.py/run.py: typed local variables with Dict/List/Optional Code quality fixes: - base.py: extract OBJECT_TYPES constant; replaces 4 copy-pasted lists - view.py: remove redundant get_object_list() call (saved 1 extra API hit) - compute.py: use validate_resource_type() + get_object_by_name() from base; removes 3 redundant get_object_list()+manual-check+get_object() patterns - create.py: move 5 creator imports to module level (out of execute hot-path) - list.py: fix len([*ids]) -> len(ids); remove unnecessary dict unpack - setup.py: fix available_models logic bug (iterated all methods but filtered by args.method, making all entries identical); now builds a flat list for args.method only - run.py: remove unused server get_object() call https://claude.ai/code/session_01RGS93ciEnBTDhyxMw7yTaj
- Project structure: replace cli.py entry with the new cli/ package tree, showing all sub-modules and the two-tier tests/ layout - Testing section: distinguish CLI unit tests (no server needed, tests/cli/) from API integration tests (require live MagnetDB); add mock-based example https://claude.ai/code/session_01RGS93ciEnBTDhyxMw7yTaj
Converting cli.py to a cli/ package broke the python -m invocation because packages require __main__.py to be directly executable. https://claude.ai/code/session_01RGS93ciEnBTDhyxMw7yTaj
Claude/refactor cli prompts n5tli
Mark CLI refactoring, error handling, and Debian packaging as completed. Update project structure in main prompt to show cli/ package. Mark type hints as in-progress (CLI done, domain modules remaining). Update next steps to focus on remaining Tier 1 (type hints completion) and Tier 2 (test suite, logging, config management) items. https://claude.ai/code/session_016kf2gmqoDip7B6ussq3N9A
MagnetDB API returns FK fields as nested objects, e.g.:
{"material": {"id": 5, "name": "copper", ...}}
Add utils.get_fk_id(obj, field) to safely extract an FK id from
any of the three forms it can appear in: nested dict, plain int,
or None.
Update part.create() so that when the material field is already an
API-response dict (contains "id"), the id is used directly instead
of triggering an extra name lookup.
https://claude.ai/code/session_01CtcWGzTxG1pqfs5X97YAxy
…b1oD Update prompt statuses to reflect completed improvements
…i into refactor-claude
Fix get_fk_id to check {field}_id first (Django serializes FK fields as
material_id integer, not a nested dict).
Add get_parts_for_magnet() to utils.py: calls GET /api/magnets/{id}/parts
and handles both bare Part arrays and MagnetPart join-row arrays.
Add examples/demo_magnet_parts.py: given a magnet name, fetches all
associated parts via get_parts_for_magnet, resolves each part's material
name via get_fk_id + get_object, and displays the result as a rich table.
https://claude.ai/code/session_01CtcWGzTxG1pqfs5X97YAxy
CLIContext previously set verify=False whenever --https was used, generating an InsecureRequestWarning on every request. Fix: verify defaults to True (use system CAs); opt-out via no_verify=True. Add --no-verify flag to all three demo scripts (demo_part_history, demo_part_site_records, demo_magnet_parts) and CLIContext. The flag sets session.verify=False and silences the urllib3 InsecureRequestWarning only when explicitly requested, which is the right behaviour for dev environments with self-signed certificates. https://claude.ai/code/session_01CtcWGzTxG1pqfs5X97YAxy
…gnetDB/python_magnetapi into claude/handle-foreignkey-fields-ZDujw
…ZDujw Handle ForeignKey fields returned as nested dicts by get_object
…ZDujw Claude/handle foreignkey fields z dujw
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.
No description provided.