Skip to content

refactor(tuning/state): rename cavityops modules to tune_status, simplify paths#230

Merged
lisazacarias merged 8 commits intoslaclab:mainfrom
lisazacarias:refactor/tune-status-state-modules
Apr 4, 2026
Merged

refactor(tuning/state): rename cavityops modules to tune_status, simplify paths#230
lisazacarias merged 8 commits intoslaclab:mainfrom
lisazacarias:refactor/tune-status-state-modules

Conversation

@lisazacarias
Copy link
Copy Markdown
Collaborator

@lisazacarias lisazacarias commented Mar 14, 2026

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 - Polls TUNE_CONFIG and DF_COLD PVs for all cavities and persists:
    • Current state snapshot (SQLite + JSON)
    • Version history tracking (records changes over time)
    • Supports configurable paths, batch sizes, and timeouts
  • sc-tune-status-query - Interactive and one-shot SQL query tool for the tune status database
    • REPL mode for exploratory queries
    • One-shot mode for scripting/automation

Infrastructure:

  • Added platform_paths.py utility module with platform-aware path helpers (is_linux(), is_macos(), get_srf_base_dir(), etc.)
  • Added shared PV name builder functions in linac_utils.py (build_cavity_pv(), build_cavity_pv_base(), build_cavity_pv_prefix())
  • Database schema with current state + version history tables for both TUNE_CONFIG and DF_COLD
  • Platform-aware defaults (Linux: /home/physics/srf, macOS: ~/)

Refactoring

  • Replaced inline platform.system() checks with shared platform_paths utilities
  • Migrated logger path resolution to use get_log_base_dir()
  • Updated Cavity class to use shared PV builder functions
  • Fixed TYPE_CHECKING imports in cavity.py to use fully-qualified module paths

Testing

  • 400+ lines of comprehensive test coverage including:
    • Platform path resolution for Linux/macOS
    • Database initialization and versioning logic
    • Query tool formatting and error handling
    • PV polling with mocked EPICS reads
    • CLI argument parsing
  • Updated integration tests to include new CLI entry points

…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
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-query CLIs (with legacy sc-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_utils and 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.

Comment thread src/sc_linac_physics/applications/tuning/state/tune_status_poll.py Outdated
Comment thread src/sc_linac_physics/applications/tuning/state/cavityops_poll.py Outdated
Comment thread src/sc_linac_physics/applications/tuning/state/__init__.py Outdated
Comment thread src/sc_linac_physics/applications/tuning/state/tune_status_query.py Outdated
Comment thread tests/conftest.py Outdated
Comment thread tests/test_integration.py Outdated
…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.
@lisazacarias lisazacarias requested a review from a team March 16, 2026 20:32
@lisazacarias lisazacarias marked this pull request as ready for review March 16, 2026 20:33
@lisazacarias lisazacarias enabled auto-merge (squash) March 16, 2026 20:33
@lisazacarias lisazacarias merged commit 47a286c into slaclab:main Apr 4, 2026
3 checks passed
@lisazacarias lisazacarias deleted the refactor/tune-status-state-modules branch April 6, 2026 19:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants