Skip to content

Commit

Permalink
improved error handling of WEBBPSF_EXT_PATH
Browse files Browse the repository at this point in the history
  • Loading branch information
JarronL committed Sep 3, 2024
1 parent aca3e5b commit 3a28b67
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
8 changes: 6 additions & 2 deletions webbpsf_ext/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,21 @@ class Conf(_config.ConfigNamespace):
data_path = tempfile.gettempdir()
else:
data_path = os.getenv('WEBBPSF_EXT_PATH')
if data_path is None:
if (data_path is None) or (data_path == ''):
print("WARNING: Environment variable $WEBBPSF_EXT_PATH is not set!")
import webbpsf
data_path = webbpsf.utils.get_webbpsf_data_path()
print(" Setting WEBBPSF_EXT_PATH to WEBBPSF_PATH directory:")
print(f" {data_path}")

if (data_path is None) or (data_path == ''):
raise IOError(f"WEBBPSF_EXT_PATH ({data_path}) is not a valid path! Have you set WEBBPSF_EXT_PATH environment variable?")

if not os.path.isdir(data_path):
try:
os.makedirs(data_path)
except:
raise IOError(f"WEBBPSF_EXT_PATH ({data_path}) is not a valid directory path!")
raise IOError(f"WEBBPSF_EXT_PATH ({data_path}) cannot be created!")

if '/' not in data_path[-1]:
# Make sure there is a '/' at the end of the path name
Expand Down
8 changes: 7 additions & 1 deletion webbpsf_ext/webbpsf_ext_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2026,7 +2026,13 @@ def _gen_save_dir(self):
If the directory doesn't exist, try to create it.
"""
if self._save_dir is None:
base_dir = Path(conf.WEBBPSF_EXT_PATH) / 'psf_coeffs/'
wext_data_dir = conf.WEBBPSF_EXT_PATH
if (wext_data_dir is None) or (wext_data_dir == '/'):
wext_data_dir = os.getenv('WEBBPSF_EXT_PATH')
if (wext_data_dir is None) or (wext_data_dir == ''):
raise IOError(f"WEBBPSF_EXT_PATH ({wext_data_dir}) is not a valid directory path!")

base_dir = Path(wext_data_dir) / 'psf_coeffs/'
# Name to save array of oversampled coefficients
inst_name = self.name
save_dir = base_dir / f'{inst_name}/'
Expand Down

0 comments on commit 3a28b67

Please sign in to comment.