pcdshub / lightpath

LCLS Lightpath Module
https://pcdshub.github.io/lightpath
Other
4 stars 9 forks source link

BUG: entrypoint should not return LightApp object #164

Closed tangkong closed 1 year ago

tangkong commented 1 year ago

Zach saw strange printouts that were a bit obscure. At the end of execution the LightApp object would be printed

<lightpath.ui.gui.LightApp object at 0x7fb92a00a280>

Ken noted that this was likely caused by a misconfiguration of the entrypoints.

$ python
Python 3.9.13 | packaged by conda-forge | (main, May 27 2022, 17:00:52)
[Clang 13.0.1 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.exit("puzzling printout")
puzzling printout

More tersely:

$ python -c "import sys; sys.exit('test')"; echo $?
test
1

And the lightpath script has:

if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
    sys.exit(load_entry_point('lightpath', 'console_scripts', 'lightpath')())

Thus the return value from the entrypoint gets set as the argument to sys.exit. If it's not numeric, its string representation gets dumped to standard output and the process returns exit code 1.

Removing the return from the entrypoint function should resolve this.

_Originally posted by @klauer in https://github.com/pcdshub/lightpath/pull/162#discussion_r984771966_