From b09c82f54b106469732ba674df4c0b8b3c69c28e Mon Sep 17 00:00:00 2001 From: Nick Murphy Date: Fri, 23 Oct 2026 17:46:52 -0400 Subject: [PATCH] Make read_file and read_file_sc private These functions are internal to the decommutator. Co-Authored-By: Claude Opus 5.5 --- src/pyfaradaycup/decommutator/README.md | 2 +- src/pyfaradaycup/decommutator/ccsds_reader_pipeline.py | 6 ++---- src/pyfaradaycup/decommutator/swp_spc_l0_to_l05.py | 10 +++++----- tests/decommutator/test_ccsds_reader_pipeline.py | 2 +- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/pyfaradaycup/decommutator/README.md b/src/pyfaradaycup/decommutator/README.md index 12c60ec..9536530 100644 --- a/src/pyfaradaycup/decommutator/README.md +++ b/src/pyfaradaycup/decommutator/README.md @@ -68,7 +68,7 @@ Calling the conversion as a function is better suited to Dagster than starting a ### Test the `--spacecraft` option - **Add a test that converts a spacecraft L0 file with `--spacecraft`.** - The only test converts an instrument L0 file, so `read_file_sc`, `_get_layout_sc`, and the code that writes the spacecraft housekeeping CDFs are never run. + The only test converts an instrument L0 file, so `_read_file_sc`, `_get_layout_sc`, and the code that writes the spacecraft housekeeping CDFs are never run. Add a spacecraft L0 file to `tests/data`, along with the expected L1 CDF files, and compare them as the existing test does. Include a file for which the flight software version cannot be found from the packet header, so that the fallback to the file path, and then to the newest definition file, is also tested. diff --git a/src/pyfaradaycup/decommutator/ccsds_reader_pipeline.py b/src/pyfaradaycup/decommutator/ccsds_reader_pipeline.py index bf63dfd..7d5d2b0 100644 --- a/src/pyfaradaycup/decommutator/ccsds_reader_pipeline.py +++ b/src/pyfaradaycup/decommutator/ccsds_reader_pipeline.py @@ -9,8 +9,6 @@ __all__ = [ "apid_obj", - "read_file", - "read_file_sc", ] import datetime @@ -196,7 +194,7 @@ def _wrapper_status( return data -def read_file( # ruff:ignore[C901] +def _read_file( # ruff:ignore[C901] path: str | os.PathLike[str], verbose: bool = False, # ruff:ignore[FBT001, FBT002] gzip: bool = False, # ruff:ignore[FBT001, FBT002] @@ -324,7 +322,7 @@ def read_file( # ruff:ignore[C901] return data -def read_file_sc( # ruff:ignore[C901, PLR0912, PLR0915] +def _read_file_sc( # ruff:ignore[C901, PLR0912, PLR0915] path: str | os.PathLike[str], verbose: bool = False, # ruff:ignore[FBT001, FBT002] ptp: bool = False, # ruff:ignore[FBT001, FBT002] diff --git a/src/pyfaradaycup/decommutator/swp_spc_l0_to_l05.py b/src/pyfaradaycup/decommutator/swp_spc_l0_to_l05.py index d07df0b..4b82ac3 100644 --- a/src/pyfaradaycup/decommutator/swp_spc_l0_to_l05.py +++ b/src/pyfaradaycup/decommutator/swp_spc_l0_to_l05.py @@ -51,8 +51,8 @@ import spiceypy from spacepy import pycdf -import pyfaradaycup.decommutator.ccsds_reader_pipeline as cc from pyfaradaycup._paths import data_dir +from pyfaradaycup.decommutator.ccsds_reader_pipeline import _read_file, _read_file_sc if TYPE_CHECKING: import os @@ -90,9 +90,9 @@ def main( # ruff:ignore[C901, PLR0912, PLR0913, PLR0915, PLR0917] spacecraft : bool, optional If `True`, read spacecraft housekeeping packets with - `~pyfaradaycup.decommutator.ccsds_reader_pipeline.read_file_sc`. + ``_read_file_sc``. If `False`, read SWEAP instrument packets with - `~pyfaradaycup.decommutator.ccsds_reader_pipeline.read_file`. + ``_read_file``. ptp : bool, optional If `True`, the L0 file is a PTP file. Only used when @@ -217,10 +217,10 @@ def main( # ruff:ignore[C901, PLR0912, PLR0913, PLR0915, PLR0917] # Read in the L0 file into a python SPC data structure if spacecraft: _statusmsg("Event = Starting reading file: spacecraft") - l0data = cc.read_file_sc(path=l0file, ptp=ptp, verbose=verbose, gzip=gzip) + l0data = _read_file_sc(path=l0file, ptp=ptp, verbose=verbose, gzip=gzip) else: _statusmsg("Event = Starting reading file: non-spacecraft (instrument)") - l0data = cc.read_file(path=l0file, verbose=verbose, gzip=gzip) + l0data = _read_file(path=l0file, verbose=verbose, gzip=gzip) _statusmsg("Event = Finished reading file") # Loop through the APIDs that we got diff --git a/tests/decommutator/test_ccsds_reader_pipeline.py b/tests/decommutator/test_ccsds_reader_pipeline.py index f6858ce..b688860 100644 --- a/tests/decommutator/test_ccsds_reader_pipeline.py +++ b/tests/decommutator/test_ccsds_reader_pipeline.py @@ -140,7 +140,7 @@ def test_parse_ccsds_head_too_short(length: int) -> None: Test that a header shorter than 10 bytes raises a ValueError. A packet can be cut off at the end of an L0 file. ``_read_bytestr`` - and ``read_file_sc`` catch `ValueError` to skip such a packet, so a + and ``_read_file_sc`` catch `ValueError` to skip such a packet, so a short header must raise `ValueError` rather than another exception or a header with missing fields. """