Skip to content

Make MSID.content into a property to prevent unnecessary remote access#282

Merged
taldcroft merged 2 commits intomasterfrom
lazy-content-to-limit-remote-access
Jan 7, 2026
Merged

Make MSID.content into a property to prevent unnecessary remote access#282
taldcroft merged 2 commits intomasterfrom
lazy-content-to-limit-remote-access

Conversation

@taldcroft
Copy link
Member

@taldcroft taldcroft commented Oct 31, 2025

Description

Currently if remote access is enabled (which is the default on Windows) then any fetch.MSID call initiates a remote access to get the content dict (map of MSID to content type) from the remote server. This is not needed if the MSID is a computed MSID like orbitephem_stk_x that does not require remote CXC telemetry, or if MAUDE is selected as the data source.

Interface impacts

Testing

Unit tests

  • Mac
(ska3) ➜  cheta git:(lazy-content-to-limit-remote-access) git rev-parse --short HEAD
99fb3dd
(ska3) ➜  cheta git:(lazy-content-to-limit-remote-access) pytest
====================================== test session starts =======================================
platform darwin -- Python 3.12.8, pytest-8.3.4, pluggy-1.5.0
rootdir: /Users/aldcroft/git
configfile: pytest.ini
plugins: anyio-4.7.0, timeout-2.3.1
collected 186 items                                                                              

cheta/tests/test_comps.py ..............s................................................. [ 34%]
.....                                                                                      [ 37%]
cheta/tests/test_data_source.py ...........                                                [ 43%]
cheta/tests/test_fetch.py .................................                                [ 60%]
cheta/tests/test_intervals.py .........................                                    [ 74%]
cheta/tests/test_orbit.py .                                                                [ 74%]
cheta/tests/test_remote_access.py ......                                                   [ 77%]
cheta/tests/test_sync.py ........                                                          [ 82%]
cheta/tests/test_units.py ...........                                                      [ 88%]
cheta/tests/test_units_reversed.py ...........                                             [ 94%]
cheta/tests/test_utils.py ...........                                                      [100%]

=========================== 185 passed, 1 skipped in 152.18s (0:02:32) ===========================

Independent check of unit tests by Jean

  • Linux
(ska3-latest) jeanconn-kady> pytest
================================================================== test session starts ==================================================================
platform linux -- Python 3.12.8, pytest-8.3.4, pluggy-1.5.0
rootdir: /proj/sot/ska/jeanproj/git
configfile: pytest.ini
plugins: anyio-4.7.0, timeout-2.3.1
collected 186 items                                                                                                                                     

cheta/tests/test_comps.py .............ss......................................................                                                   [ 37%]
cheta/tests/test_data_source.py ...........                                                                                                       [ 43%]
cheta/tests/test_fetch.py .................................                                                                                       [ 60%]
cheta/tests/test_intervals.py .........................                                                                                           [ 74%]
cheta/tests/test_orbit.py .                                                                                                                       [ 74%]
cheta/tests/test_remote_access.py ......                                                                                                          [ 77%]
cheta/tests/test_sync.py ........                                                                                                                 [ 82%]
cheta/tests/test_units.py ...........                                                                                                             [ 88%]
cheta/tests/test_units_reversed.py ...........                                                                                                    [ 94%]
cheta/tests/test_utils.py ...........                                                                                                             [100%]

=================================================================== warnings summary ====================================================================
cheta/cheta/tests/test_comps.py: 12 warnings
  /export/jeanconn/miniforge3/envs/ska3-latest/lib/python3.12/site-packages/bs4/builder/_lxml.py:124: DeprecationWarning: The 'strip_cdata' option of HTMLParser() has never done anything and will eventually be removed.
    parser = parser(

cheta/cheta/tests/test_comps.py::test_cmd_states
  /export/jeanconn/miniforge3/envs/ska3-latest/lib/python3.12/site-packages/setuptools_scm/git.py:312: UserWarning: git archive did not support describe output
    warnings.warn("git archive did not support describe output")

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
================================================ 184 passed, 2 skipped, 13 warnings in 147.60s (0:02:27) ================================================
(ska3-latest) jeanconn-kady> git rev-parse HEAD
99fb3dd93156d319053a14e7213b349d04011c8e

Functional tests

This code produces the expected output and does not initiate a remote connection.

import os
os.environ['SKA_ACCESS_REMOTELY'] = 'True'
from cheta import fetch, remote_access
fetch.add_logging_handler()
assert remote_access.access_remotely is True

dat = fetch.Msid("orbitephem_stk_x", "2018:001", "2018:010")

fetch.data_source.set("MAUDE")
dat = fetch.Msid("orbitephem_stk_x", "2018:001", "2018:010")
dat = fetch.Msid("aacccdpt", "2018:001", "2018:010")

Output

_get_data: Getting data for orbitephem_stk_x between 2018:001:00:00:00.000 to 2018:010:00:00:00.000
_get_comp_data: Getting computed values for orbitephem_stk_x
get_ephem_stk_paths: Checking local directory /Users/aldcroft/Documents/MATLAB/FOT_Tools/Ephemeris for STK files
get_ephem_stk_paths: Checking OCCweb directory FOT/mission_planning/Backstop/Ephemeris
get_ephem_stk_paths: Checking OCCweb directory FOT/mission_planning/Backstop/Ephemeris/ArchiveMCC
read_stk_file: Reading cached STK file FOT/mission_planning/Backstop/Ephemeris/ArchiveMCC/Chandra_17337_18154.stk from /Users/aldcroft/.cheta/cache/Chandra_17337_18154.stk.npz
read_stk_file: Reading cached STK file FOT/mission_planning/Backstop/Ephemeris/ArchiveMCC/Chandra_18002_18183.stk from /Users/aldcroft/.cheta/cache/Chandra_18002_18183.stk.npz
_get_data: Getting data for orbitephem_stk_x between 2018:001:00:00:00.000 to 2018:010:00:00:00.000
_get_comp_data: Getting computed values for orbitephem_stk_x
_get_data: Getting data for aacccdpt between 2018:001:00:00:00.000 to 2018:010:00:00:00.000


@property
def content(self) -> str | None:
return content.get(self.MSID) if "cxc" in data_source.sources() else None
Copy link
Contributor

Choose a reason for hiding this comment

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

This makes sense to me, but do we also want to define the content for the stk computed msids? Otherwise we end up trying to do the remote access query again if the user wants a content for the Msid:

In [9]: ephem = fetch.Msid("orbitephem_stk_x", "2025:001", "2025:002")

In [10]: ephem.content
Enter hostname (or IP) of Ska server (enter to cancel):

Copy link
Member Author

Choose a reason for hiding this comment

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

There is no real reason that a user would try getting ephem.content since it is not defined. So probably this would be fixing a problem that does not happen in practice.

@taldcroft taldcroft merged commit 985d756 into master Jan 7, 2026
2 checks passed
@taldcroft taldcroft deleted the lazy-content-to-limit-remote-access branch January 7, 2026 16:00
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.

2 participants