refactor(tuning/state): rename cavityops modules to tune_status, simplify paths#230
Merged
lisazacarias merged 8 commits intoslaclab:mainfrom Apr 4, 2026
Conversation
…lify paths - Rename cavityops_poll.py → tune_status_poll.py, query_db.py → tune_status_query.py - Add sc-tune-status-poll and sc-tune-status-query console scripts; keep sc-cavityops-poll and sc-cavityops-query as backward-compatible aliases - Default artifact names: tune_status.sqlite, tune_status.json, tune_status_poll.log - Derive DEFAULT_LOG_PATH from TUNE_LOG_DIR (tune_utils) as single source of truth - Simplify _platform_default_paths to 3-tuple (drop redundant log_path computation) - Add build_cavity_pv_base/prefix/pv() helpers to linac_utils; use in cavity.py and tune_status_poll - Replace subprocess/caget with PVBatch.get_values() in tune_status_poll - Add shared connect_db(), build_state_logger(), batched() utilities in common.py - Fix BASE_LOG_DIR on macOS: ~/logs → ~/logfiles
There was a problem hiding this comment.
Pull request overview
Refactors the tuning “cavityops” state tooling into a clearer tune_status_* naming scheme, adds/aliases console scripts, and centralizes shared path/logging/DB utilities for polling + querying tuning state.
Changes:
- Introduces
sc-tune-status-poll/sc-tune-status-queryCLIs (with legacysc-cavityops-*aliases) and documents usage. - Adds shared helpers (
common.py) for default paths, DB connections, batching, and logger construction. - Adds PV string builder helpers in
linac_utilsand updates cavity PV prefix construction.
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/utils/sc_linac/test_linac_utils.py | Adds unit tests for new cavity PV builder helpers. |
| tests/test_integration.py | Extends CLI --help smoke coverage for new/aliased poller command(s). |
| tests/conftest.py | Updates expected console-script list for entrypoint validation tests. |
| tests/applications/tuning/state/test_query_db.py | Adds test coverage for SQLite query output formatting. |
| tests/applications/tuning/state/test_common.py | Adds tests for platform defaults and path resolution utilities. |
| tests/applications/tuning/state/test_cavityops_poll.py | Adds poller behavior tests (parsing + DB/JSON writing + PVBatch usage). |
| src/sc_linac_physics/utils/sc_linac/linac_utils.py | Adds build_cavity_pv_* helpers. |
| src/sc_linac_physics/utils/sc_linac/cavity.py | Uses shared PV prefix builder + fixes TYPE_CHECKING imports. |
| src/sc_linac_physics/utils/logger.py | Adjusts macOS base log directory path. |
| src/sc_linac_physics/applications/tuning/state/common.py | New shared path/logging/DB/batching utilities for state tools. |
| src/sc_linac_physics/applications/tuning/state/tune_status_poll.py | New poller CLI using PVBatch + shared common utilities. |
| src/sc_linac_physics/applications/tuning/state/tune_status_query.py | New query CLI (interactive + one-shot SQL). |
| src/sc_linac_physics/applications/tuning/state/cavityops_poll.py | Adds legacy-named poller module (currently duplicates tune_status_poll). |
| src/sc_linac_physics/applications/tuning/state/init.py | Exposes state submodules at package level. |
| pyproject.toml | Registers new console scripts and backward-compatible aliases. |
| README.md | Documents new tune-status polling/query CLIs and legacy aliases. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
…ops aliases - remove sc-cavityops-poll and sc-cavityops-query console-script aliases - delete all remaining cavityops references from code, tests, and README - rename test_cavityops_poll.py to test_tune_status_poll.py - make legacy cavityops poller path a tune-status-only implementation path - keep poll/query CLI behavior improvements (lazy state imports, query exit codes, clearer deprecated args handling)
Consolidate duplicate state modules and create utils/platform_paths.py as single source of truth for OS detection. Wire all tuning/state CLIs through shared utils.custom_logger. Remove cavityops aliases.
Move tune_status.json to base_dir/json/ to organize output files alongside databases/ and logfiles/ directories. Add get_json_dir() helper to platform_paths.
hmarts9
approved these changes
Apr 4, 2026
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.
Add tune status polling and query CLI tools for cavity tuning state persistence
This PR adds new command-line tools to poll and query cavity tuning configuration and detuning data, with platform-aware path resolution and comprehensive test coverage.
New Features
CLI Tools:
sc-tune-status-poll- PollsTUNE_CONFIGandDF_COLDPVs for all cavities and persists:sc-tune-status-query- Interactive and one-shot SQL query tool for the tune status databaseInfrastructure:
platform_paths.pyutility module with platform-aware path helpers (is_linux(),is_macos(),get_srf_base_dir(), etc.)linac_utils.py(build_cavity_pv(),build_cavity_pv_base(),build_cavity_pv_prefix())TUNE_CONFIGandDF_COLD/home/physics/srf, macOS:~/)Refactoring
platform.system()checks with sharedplatform_pathsutilitiesget_log_base_dir()Cavityclass to use shared PV builder functionscavity.pyto use fully-qualified module pathsTesting