refactor(dashboard-api): extract pure settings helpers into settings.py#1059
refactor(dashboard-api): extract pure settings helpers into settings.py#1059boffin-dmytro wants to merge 3 commits intoLight-Heart-Labs:mainfrom
Conversation
|
Follow-up from today's merge pass: I updated this branch onto current Current Ruff failures are all fixable cleanup items:
Once those imports are trimmed and Ruff is green, this should be ready for a normal refactor review again. |
Lightheartdevs
left a comment
There was a problem hiding this comment.
Verified as a pure refactor: extracts _ENV_*_RE/_SETTINGS_*_KEYS/_MANUAL_RESTART_KEYS constants and ~14 helpers (_strip_env_quotes, _parse_env_text, _compute_env_apply_plan, etc.) from main.py into a new settings.py module. Import contract preserved. Net deletion in main.py matches additions in settings.py. Ship after rebase + API tests.
Lightheartdevs
left a comment
There was a problem hiding this comment.
This refactor is a reasonable cleanup, but it is not mergeable while the Python lint job is red.
I reproduced the CI failure locally with the same selector:
python -m ruff check dream-server/ --select E,F,W --ignore E501,E701,E731,E741,E402Ruff reports 13 fixable F401 errors: unused settings imports in extensions/services/dashboard-api/main.py plus an unused json import in the new settings.py. Please prune those imports (or run Ruff with --fix and review the result), then rerun the API/lint checks. Since this is meant to be a behavior-preserving extraction, keeping CI green is the bar before merge.
|
Fixed — removed the 12 unused imports from |
Summary
main.pywas ~1478 lines (~3× the 500-line guideline). This PR extracts 9 env-related constants and 14 pure leaf functions into a newsettings.pymodule, reducingmain.pyto ~1170 lines (~21% reduction)._resolve_install_root,_resolve_runtime_env_path, or_resolve_template_pathremain inmain.pyso that monkeypatches intest_settings_env.pycontinue to intercept them correctly (Python resolves names at the module where they are defined, not the caller's module).What moved to
settings.py9 constants:
_ENV_ASSIGNMENT_RE,_ENV_COMMENTED_ASSIGNMENT_RE,_SENSITIVE_ENV_KEY_RE,_SETTINGS_APPLY_ALLOWED_SERVICES,_LLAMA_APPLY_KEYS,_OPEN_WEBUI_APPLY_KEYS,_TOKEN_SPY_APPLY_KEYS,_PRIVACY_SHIELD_APPLY_KEYS,_MANUAL_RESTART_KEYS14 functions:
_strip_env_quotes,_parse_env_text,_read_env_map_from_path,_normalize_bool,_humanize_env_key,_is_secret_field,_slugify,_build_env_fields,_validate_env_values,_serialize_form_values,_match_apply_service,_build_apply_summary,_compute_env_apply_plan,_check_host_agent_availableTest plan
tests/test_settings_env.py— all 16 tests pass unchangedpython3 -c "import settings"— imports cleanly