From cf43dc23532bec59fe7a21ace2987ded333bc36c Mon Sep 17 00:00:00 2001 From: Andrew Robbertz <24920994+Alrobbertz@users.noreply.github.com> Date: Mon, 24 Aug 2026 11:25:08 -0400 Subject: [PATCH 1/2] Force SWXSOC_MISSION Env Variable & Reconfigure on Package Import --- padre_sharp/__init__.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/padre_sharp/__init__.py b/padre_sharp/__init__.py index 56922ac..5be2cdd 100644 --- a/padre_sharp/__init__.py +++ b/padre_sharp/__init__.py @@ -9,12 +9,15 @@ __version__ = "unknown version" version_tuple = (0, 0, "unknown version") +import swxsoc from padre_sharp.util.config import load_config, print_config from padre_sharp.util.logger import _init_log -# Get SWXSOC_MISSIONS environment variable if it exists or use default for mission -SWXSOC_MISSION = os.getenv("SWXSOC_MISSION", "padre") -os.environ["SWXSOC_MISSION"] = SWXSOC_MISSION +# Force the mission environment variable and reconfigure swxsoc regardless of +# import order (padre_sharp's own config/log below are independent of +# swxsoc's, but other padre_sharp modules read swxsoc.config directly) +os.environ["SWXSOC_MISSION"] = "padre" +swxsoc.reconfigure() # Load user configuration config = load_config() From b452a950b2ec5ca2502031d547fd339b2468152d Mon Sep 17 00:00:00 2001 From: Andrew Robbertz <24920994+Alrobbertz@users.noreply.github.com> Date: Mon, 24 Aug 2026 13:46:13 -0400 Subject: [PATCH 2/2] Formatting --- docs/conf.py | 1 - padre_sharp/__init__.py | 1 + padre_sharp/calibration/calibration.py | 6 ------ padre_sharp/io/file_tools.py | 2 +- padre_sharp/tests/test_calibration.py | 3 +-- padre_sharp/tests/test_util_util.py | 5 +++-- padre_sharp/tests/test_util_validation.py | 15 +++++++-------- padre_sharp/util/config.py | 6 +++--- padre_sharp/util/exceptions.py | 6 +++--- padre_sharp/util/logger.py | 6 +++--- padre_sharp/util/util.py | 5 +---- padre_sharp/util/validation.py | 14 +++++++------- 12 files changed, 30 insertions(+), 40 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 3583b08..3446b00 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # Configuration file for the Sphinx documentation builder. # diff --git a/padre_sharp/__init__.py b/padre_sharp/__init__.py index 5be2cdd..8b0b570 100644 --- a/padre_sharp/__init__.py +++ b/padre_sharp/__init__.py @@ -10,6 +10,7 @@ version_tuple = (0, 0, "unknown version") import swxsoc + from padre_sharp.util.config import load_config, print_config from padre_sharp.util.logger import _init_log diff --git a/padre_sharp/calibration/calibration.py b/padre_sharp/calibration/calibration.py index 6d16628..fc30683 100644 --- a/padre_sharp/calibration/calibration.py +++ b/padre_sharp/calibration/calibration.py @@ -3,13 +3,7 @@ """ from pathlib import Path -import random -import tempfile - -from astropy.time import Time - -from swxsoc.util import util from padre_sharp import log from padre_sharp.util import validation diff --git a/padre_sharp/io/file_tools.py b/padre_sharp/io/file_tools.py index 3f2f943..128c42d 100644 --- a/padre_sharp/io/file_tools.py +++ b/padre_sharp/io/file_tools.py @@ -21,4 +21,4 @@ def read_file(data_filename): Examples -------- """ - return None + return diff --git a/padre_sharp/tests/test_calibration.py b/padre_sharp/tests/test_calibration.py index 3b3e5f3..2f905e7 100644 --- a/padre_sharp/tests/test_calibration.py +++ b/padre_sharp/tests/test_calibration.py @@ -1,6 +1,5 @@ -import pytest -from pathlib import Path import tempfile +from pathlib import Path import padre_sharp.calibration as calib diff --git a/padre_sharp/tests/test_util_util.py b/padre_sharp/tests/test_util_util.py index 7c72dc7..f04122d 100644 --- a/padre_sharp/tests/test_util_util.py +++ b/padre_sharp/tests/test_util_util.py @@ -1,9 +1,10 @@ """Tests for util.py""" -import pytest import re +import pytest from astropy.time import Time + from padre_sharp.util import util time = "2024-04-06T12:06:21" @@ -249,7 +250,7 @@ def test_validate_swxsoc_science_filename( assert match, f"Filename {expected_filename} does not match expected format" # Extract matched groups - mission, instrument, mode, level, test_flag, descriptor, time_str, version, extension = match.groups() + mission, instrument, _, level, test_flag, descriptor, time_str, version, extension = match.groups() # Ensure parsed values align with expected values assert mission == expected_mission, f"Mission mismatch: expected {expected_mission}, got {mission}" diff --git a/padre_sharp/tests/test_util_validation.py b/padre_sharp/tests/test_util_validation.py index 6e28ca7..2bd7672 100644 --- a/padre_sharp/tests/test_util_validation.py +++ b/padre_sharp/tests/test_util_validation.py @@ -1,5 +1,3 @@ -from pathlib import Path - import pytest import padre_sharp @@ -10,13 +8,14 @@ def test_validate_packet_checksums(): # TODO Insert you own test file here - Remove the FileNotFoundError when you have a test file with pytest.raises(FileNotFoundError): test_file = padre_sharp._test_files_directory / "apid160_4packets.bin" - warnings = validation.validate_packet_checksums(test_file) - # assert len(warnings) == 0 + _warnings = validation.validate_packet_checksums(test_file) + # assert len(_warnings) == 0 def test_validate(): # TODO Insert you own test file here - Remove the FileNotFoundError when you have a test file - test_file = padre_sharp._test_files_directory / "apid160_4packets.bin" - warnings = validation.validate(test_file) - assert len(warnings) == 1 - assert "No such file or directory:" in warnings[0] + with pytest.raises(FileNotFoundError): + test_file = padre_sharp._test_files_directory / "apid160_4packets.bin" + _warnings = validation.validate(test_file) + # assert len(_warnings) == 1 + # assert "No such file or directory:" in _warnings[0] diff --git a/padre_sharp/util/config.py b/padre_sharp/util/config.py index dcdf5a2..a75c86f 100644 --- a/padre_sharp/util/config.py +++ b/padre_sharp/util/config.py @@ -5,9 +5,9 @@ licenses/SUNPY.rst """ +import configparser import os import shutil -import configparser from pathlib import Path import padre_sharp @@ -17,7 +17,7 @@ if not os.getenv("LAMBDA_ENVIRONMENT"): from sunpy.extern.appdirs import AppDirs -__all__ = ["load_config", "copy_default_config", "print_config", "CONFIG_DIR"] +__all__ = ["CONFIG_DIR", "copy_default_config", "load_config", "print_config"] # Default directories for Lambda Environment CONFIG_DIR = "/tmp/.config" @@ -134,7 +134,7 @@ def print_config(): print(f" [{section}]") for option in padre_sharp.config.options(section): print(f" {option} = padre_sharp.config.get(section, option)") - print("") + print() def _is_writable_dir(p): diff --git a/padre_sharp/util/exceptions.py b/padre_sharp/util/exceptions.py index 390bc0c..bc2e81c 100644 --- a/padre_sharp/util/exceptions.py +++ b/padre_sharp/util/exceptions.py @@ -11,12 +11,12 @@ import warnings __all__ = [ - "SHARPWarning", - "SHARPUserWarning", "SHARPDeprecationWarning", "SHARPPendingDeprecationWarning", - "warn_user", + "SHARPUserWarning", + "SHARPWarning", "warn_deprecated", + "warn_user", ] diff --git a/padre_sharp/util/logger.py b/padre_sharp/util/logger.py index ed46926..07b375e 100644 --- a/padre_sharp/util/logger.py +++ b/padre_sharp/util/logger.py @@ -1,6 +1,6 @@ +import logging import os import sys -import logging from astropy.logger import AstropyLogger @@ -42,13 +42,13 @@ def _showwarning(self, *args, **kwargs): # find the module object and thus the fully-package-specified module # name. The module.__file__ is the original source file name. mod_name = None - mod_path, ext = os.path.splitext(mod_path) + mod_path, _ext = os.path.splitext(mod_path) for name, mod in list(sys.modules.items()): try: # Believe it or not this can fail in some cases: # https://github.com/astropy/astropy/issues/2671 path = os.path.splitext(getattr(mod, "__file__", ""))[0] - except Exception: + except Exception: # NOQA continue if path == mod_path: mod_name = mod.__name__ diff --git a/padre_sharp/util/util.py b/padre_sharp/util/util.py index 2b6e150..67ada09 100644 --- a/padre_sharp/util/util.py +++ b/padre_sharp/util/util.py @@ -2,12 +2,9 @@ This module provides general utility functions. """ -import os - from astropy.time import Time from swxsoc import config - __all__ = ["create_science_filename"] TIME_FORMAT_L0 = "%Y%j-%H%M%S" @@ -81,7 +78,7 @@ def create_science_filename( # check that version has integers in each part for item in version.split("."): try: - int_value = int(item) + _int_value = int(item) except ValueError: raise ValueError(f"Version, {version}, is not all integers.") diff --git a/padre_sharp/util/validation.py b/padre_sharp/util/validation.py index 7680ca3..2cf1663 100644 --- a/padre_sharp/util/validation.py +++ b/padre_sharp/util/validation.py @@ -2,13 +2,11 @@ This module contains utilities for file and packet validation. """ -from typing import List - import numpy as np from ccsdspy import utils -def validate_packet_checksums(file) -> List[str]: +def validate_packet_checksums(file) -> list[str]: """ Custom Validation Function to check that all packets have contents that match their checksums. This is achieved be a rolling XOR of the packet contents. If the final XOR value is not 0, a warning is issued. @@ -26,12 +24,12 @@ def validate_packet_checksums(file) -> List[str]: packets = utils.split_packet_bytes(file) for i, packet in enumerate(packets): # Convert to an array of u16 integers - packet_arr = np.frombuffer(packet, dtype=np.uint8) + _packet_arr = np.frombuffer(packet, dtype=np.uint8) # Insert your custom checksum validation here # Included is MEDDEA's checksum validation as an example - # checksum_validation = np.bitwise_xor.reduce(packet_arr) + # checksum_validation = np.bitwise_xor.reduce(_packet_arr) checksum_validation = 0 # Make sure the Checksum Validation was correct @@ -46,8 +44,10 @@ def validate_packet_checksums(file) -> List[str]: def validate( - file, valid_apids: List[int] = None, custom_validators: List[callable] = None -) -> List[str]: + file, + valid_apids: list[int] | None = None, + custom_validators: list[callable] | None = None, +) -> list[str]: """ Validate a file containing CCSDS packets and capturing any exceptions or warnings they generate. This function checks: