Skip to content

Commit

Permalink
Merge pull request #1073 from alphasentaurii/force-jwst-default-to-build
Browse files Browse the repository at this point in the history
api/get-default-context-adjustment
  • Loading branch information
alphasentaurii authored Sep 19, 2024
2 parents f9a6a16 + 858e867 commit 55daeeb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ General

- Setting environment variable `CRDS_CONTEXT=latest` automatically sets the effective context to the latest operational context found on the CRDS Server. [#1062]

- `client.api.get_default_context` by default returns build context for jwst, else latest. This can still be overridden by explicitly passing a value into optional arg `state`. [#1069]

11.18.3 (2024-09-03)
====================

Expand Down
26 changes: 13 additions & 13 deletions crds/client/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,31 +346,31 @@ def get_aui_best_references(date, dataset_ids):


@utils.cached
def get_default_context(observatory=None, state="latest"):
def get_default_context(observatory=None, state=None):
"""Return the name of the latest pipeline mapping in use for processing
files for `observatory`.
"""
if state == "build":
observatory = get_default_observatory() if observatory is None else observatory
if state == "build" or (observatory == "jwst" and state not in ["edit", "latest"]):
return get_build_context(observatory=observatory)
return str(S.get_default_context(observatory, state))


def get_build_context(observatory=None):
"""If available, return the name of the build context pipeline mapping in use for processing
files for `observatory`. Initially only planned use is for jwst but other mission
calibration pipeline sw is included as a template. If no match found, returns latest
(formerly operational) context.
calibration pipeline sw is included as a template. If exact match is not found, an attempt to
find next closest (previous) patch version is made. Ultimate fallback is to the latest
(formerly 'operational') context.
"""
if observatory is None:
try:
observatory = str(S).split("=")[1].split("-")[0].split("/")[-1]
except ServiceError:
observatory = os.environ.get('CRDS_SERVER_URL', '').split("-")[0].split("/")[-1]
observatory = get_default_observatory() if observatory is None else observatory
calver = get_cal_version(observatory)
if calver:
return str(S.get_build_context(observatory, calver))
else:
return get_default_context(observatory=observatory, state='latest')
try:
return str(S.get_build_context(observatory, calver))
except ServiceError:
log.warning("Server build context could not be identified. Using 'latest' instead.")
return get_default_context(observatory, "latest")


@utils.cached
Expand Down Expand Up @@ -615,7 +615,7 @@ def get_default_observatory():
4. jwst
"""
obs = config.OBSERVATORY.get()
if obs != "none":
if obs not in ["none", "", None]:
return obs
return observatory_from_string(get_crds_server()) or \
get_server_observatory() or \
Expand Down
2 changes: 1 addition & 1 deletion crds/core/cmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def observatory(self):
return self.set_server("roman")

obs = config.OBSERVATORY.get()
if obs != "none":
if obs not in ["none", "", None]:
return self.set_server(obs.lower())

url = os.environ.get("CRDS_SERVER_URL", None)
Expand Down

0 comments on commit 55daeeb

Please sign in to comment.