mperrin / webbpsf

James Webb Space Telescope PSF simulation tool - NOTE THIS VERSION OF REPO IS SUPERCEDED BY spacetelescope/webbpsf
BSD 3-Clause "New" or "Revised" License
16 stars 15 forks source link

Warn users about missing data or using WFIRSTImager #49

Closed josePhoenix closed 9 years ago

josePhoenix commented 9 years ago

Last two changes pre-release: add disclaimer to WFIRST classes, improve user experience in the absence of WEBBPSF_DATA cc @mperrin @cslocum

mperrin commented 9 years ago

Hmm, so I went ahead and merged this. But now I see that it has the side effect of suppressing the exception in whatever program or module is trying to import webbpsf. Wouldn't it be better to pass the exception up higher so that the program that just tried the import knows it cannot continue?

I guess I don't understand entirely the motivation for calling traceback.print_exc() in this context instead of just letting the exception percolate upwards?

Example:

mperrin@peregrine ~ > unsetenv WEBBPSF_PATH
mperrin@peregrine ~ > ipython
Python 2.7.8 (default, Oct  7 2014, 15:36:11)
...

In [1]: try:
   ...:     import webbpsf
   ...:     print "OK"
   ...: except:
   ...:     print "Not OK :-("
   ...:
WebbPSF log messages of level INFO and above will be shown.
WebbPSF log outputs will be directed to the screen.
Traceback (most recent call last):
  File "/Users/mperrin/Dropbox (Personal)/Documents/software/webbpsf/webbpsf/__init__.py", line 93, in <module>
    utils.get_webbpsf_data_path()
  File "/Users/mperrin/Dropbox (Personal)/Documents/software/webbpsf/webbpsf/utils.py", line 143, in get_webbpsf_data_path
    raise EnvironmentError("Environment variable $WEBBPSF_PATH is not set!")
EnvironmentError: Environment variable $WEBBPSF_PATH is not set!

 *********  ERROR  ******  ERROR  ******  ERROR  ******  ERROR  *************
 *                                                                          *
 *  WebbPSF requires several data files to operate.                         *
 *  These files could not be located automatically at this                  *
 *  time. Please download them to a location of your                        *
 *  choosing and either                                                     *
 *   - set the environment variable $WEBBPSF_PATH to point there, or        *
 *   - set the WEBBPSF_PATH variable in your webbpsf.cfg config file        *
 *     (probably in ~/.astropy/config/ or similar location)                 *
 *                                                                          *
 *  See http://pythonhosted.org/webbpsf/installation.html, under            *
 *  "Installing the Required Data Files", for more details.                 *
 *  WebbPSF will not be able to function properly until this has been done. *
 *                                                                          *
 ****************************************************************************
OK

Note that the import case in the try was successful, as indicated by the print OK.

josePhoenix commented 9 years ago

Oh, whoops. I noticed Christine didn't read the notice and gravitated straight to the traceback, so I figured I'd reorder them. But, that has the unintended consequence you identified!

Better fix that.

On Feb 19, 2015, at 6:03 PM, Marshall Perrin notifications@github.com wrote:

Hmm, so I went ahead and merged this. But now I see that it has the side effect of suppressing the exception in whatever program or module is trying to import webbpsf. Wouldn't it be better to pass the exception up higher so that the program that just tried the import knows it cannot continue?

I guess I don't understand entirely the motivation for calling traceback.print_exc() in this context instead of just letting the exception percolate upwards?

Example:

mperrin@peregrine ~ > unsetenv WEBBPSF_PATH mperrin@peregrine ~ > ipython Python 2.7.8 (default, Oct 7 2014, 15:36:11) ...

In [1]: try: ...: import webbpsf ...: print "OK" ...: except: ...: print "Not OK :-(" ...: WebbPSF log messages of level INFO and above will be shown. WebbPSF log outputs will be directed to the screen. Traceback (most recent call last): File "/Users/mperrin/Dropbox (Personal)/Documents/software/webbpsf/webbpsf/init.py", line 93, in utils.get_webbpsf_data_path() File "/Users/mperrin/Dropbox (Personal)/Documents/software/webbpsf/webbpsf/utils.py", line 143, in get_webbpsf_data_path raise EnvironmentError("Environment variable $WEBBPSF_PATH is not set!") EnvironmentError: Environment variable $WEBBPSF_PATH is not set!

***** ERROR ** ERROR ** ERROR ** ERROR *****

  • *
  • WebbPSF requires several data files to operate. *
  • These files could not be located automatically at this *
  • time. Please download them to a location of your *
  • choosing and either *
    • set the environment variable $WEBBPSF_PATH to point there, or *
    • set the WEBBPSF_PATH variable in your webbpsf.cfg config file *
  • (probably in ~/.astropy/config/ or similar location) *
  • *
  • See http://pythonhosted.org/webbpsf/installation.html, under *
  • "Installing the Required Data Files", for more details. *
  • WebbPSF will not be able to function properly until this has been done. *
  • *

    OK

Note that the import case in the try was successful, as indicated by the print OK.

— Reply to this email directly or view it on GitHub.

josePhoenix commented 9 years ago

Also, apparently GitHub emails are arriving delayed by an hour.