fixed cache dir bug - #452
Conversation
Changed cache_dir to default to str(pooch.os_cache("layup")) instead of None in LayupObservatory. Stops layup_furnish_spiceypy from searching for files in the Sorcha created cache.
|
Don't accept/merge just yet. @mschwamb said there was a different bug before that caused a problem similar to this in orbitfit. I'm going to double-check everything first incase I missed something. |
|
@mschwamb, the fix was in pr #225 but missed the case where cache_dir is left as None. The call for Layup_observatory in orbitfit and predict was changed from: To: This fixed the original bug in the main code, but the unit tests still have the bug as they call There was another fix to a similar issue #286, but the fix was related to the observatory position and didn't change the unit tests calling the Sorcha cache. |
|
I think you might want to make "layup" a global variable at the top of the file so it's clear that this is hardcoded - easier to spot if it needs to be changed. |
mschwamb
left a comment
There was a problem hiding this comment.
see other comment about changes
|
|
||
| # default Cache directory name where the layup auxiliary files are stored when layup bootstrap is ran | ||
| # eg on Mac ~/Library/Caches/layup | ||
| cache_dir_name = "layup" |
There was a problem hiding this comment.
Can you make it all caps - so that the style is the same throughout layup see
Line 21 in ed1579a
There was a problem hiding this comment.
No problem will do.
matthewholman
left a comment
There was a problem hiding this comment.
This doesn't fix #451 on the paths that matter.
Changing the default only helps callers that omit the argument. All three production callers pass it explicitly, and their own defaults are None:
predict.py:438,orbitfit.py:1502,orbitfit.py:1555
So layup.predict(data, obscode, times) still sends None through to layup_furnish_spiceypy, which hands it to Sorcha as ar_data_file_path=None — the search #451 reports. tests/layup/test_predict.py:480 passes cache_dir=None explicitly too.
The evidence is one line above a caller:
kernels_loc = str(pooch.os_cache("layup")) if cache_dir is None else str(cache_dir) # orbitfit.py:1554
observatory = LayupObservatory(cache_dir=cache_dir) # 1555Also, a default argument is evaluated once at import, so this freezes the cache path at module load — awkward for tests and for #448.
Suggested instead:
def __init__(self, cache_dir=None):
if cache_dir is None:
cache_dir = str(pooch.os_cache("layup"))
self.cache_dir = cache_dir
layup_furnish_spiceypy(cache_dir)This covers explicit None, evaluates per call, matches the idiom used elsewhere (including line 434 of this file), and fixes self.cache_dir, which feeds the Horizons state cache and is currently stored as None.
A test asserting predict(..., cache_dir=None) furnishes from the layup cache would catch the regression.
mschwamb
left a comment
There was a problem hiding this comment.
See the detailed review from Matt
Fixes #451 .
Changed cache_dir to default to str(pooch.os_cache("layup")) instead of None in LayupObservatory. Stops layup_furnish_spiceypy from searching for files in the Sorcha created cache.
Review Checklist for Source Code Changes