monashmicroimaging / podocytes

GNU General Public License v3.0
2 stars 3 forks source link

Bundle loci_tools.jar into the app build #11

Closed GenevieveBuckley closed 5 years ago

GenevieveBuckley commented 6 years ago

This download seems to happen every time the app is run. Perhaps there's a way we can bundle it into the app build so this doesn't occur.

/var/folders/gz/6f0v_zhs09x38mb4td_h6py80000gn/T/_MEIiWNUSs/pims/bioformats.py:53: UserWarning: loci_tools.jar not found, downloading
GenevieveBuckley commented 6 years ago

It looks like there are two problems here:

  1. Including loci_tools.jar in the bundled app pyinstaller creates, and
  2. Teaching pims how to find loci_tools.jar in that particular location.

I think this issue should be a relatively high priority, because without a fix users can't run the app if they're offline. For this reason I'm gonna call it a bug - we should be able to support offline use.

Problem 1 is fairly easy to fix - you can add the jar as a data file to datas in the spec file. Relevant stackoverflow.

Problem 2 is harder - see comment below.

Here's the traceback if you try to start Podo when offline:

2018-06-06 13:41:25,623 Podocyte automated analysis program
2018-06-06 13:41:25,624 06-Jun-2018_13-41PM
2018-06-06 13:41:25,625 Processing file: /Users/genevieb/Desktop/test_podo/little_input/51559.lif
[23833] Failed to execute script launch-gui
/var/folders/gz/6f0v_zhs09x38mb4td_h6py80000gn/T/_MEIG2l5tq/pims/bioformats.py:53: UserWarning: loci_tools.jar not found, downloading
/var/folders/gz/6f0v_zhs09x38mb4td_h6py80000gn/T/_MEIG2l5tq/pims/api.py:191: UserWarning: <class 'pims.bioformats.BioformatsReader'> errored: <urlopen error [Errno 8] nodename nor servname provided, or not known>
Traceback (most recent call last):
  File "bin/launch-gui.py", line 3, in <module>
  File "site-packages/gooey/python_bindings/gooey_decorator.py", line 89, in <lambda>
  File "podocytes/main.py", line 98, in main
  File "site-packages/pims/api.py", line 193, in open
pims.api.UnknownFormatError: All handlers returned exceptions:
<class 'pims.bioformats.BioformatsReader'> errored: <urlopen error [Errno 8] nodename nor servname provided, or not known>

06-Jun-2018_13-41PM
GenevieveBuckley commented 6 years ago

Pims bioformats.py looks in several locations to find loci_tools.jar before downloading a copy if it can't find it locally. Search locations are:

  1. pims package location
  2. PROGRAMDATA/pims/loci_tools.jar os.path.join(os.environ['PROGRAMDATA'], 'pims')
  3. LOCALAPPDATA/pims/loci_tools.jar os.path.join(os.environ['LOCALAPPDATA'], 'pims')
  4. APPDATA/pims/loci_tools.jar os.path.join(os.environ['APPDATA'], 'pims')
  5. /etc/loci_tools.jar os.path.join(os.path.expanduser('~'), '.config', 'pims')
  6. ~/.config/pims/loci_tools.jar None of these options include "the current directory" or "the current app bundle". Maybe adding something like that would work for us?

If pims does not find loci_tools.jar in any of these places, it'll download it from: url = ('http://downloads.openmicroscopy.org/bio-formats/' + version + '/artifacts/loci_tools.jar') where version='5.7.0'

Additionally, it may be worth bundling a newer version of loci_tools.jar (pims default is to download v 5.7.0 but more recently available is v5.8.2 see here for the latest).

GenevieveBuckley commented 6 years ago

Advice from pims developers:

https://github.com/soft-matter/pims/issues/299#issuecomment-401460062

If you like to bundle pims and bioformats in a single package, you can do so by putting loci_tools.jar right next to bioformats.py. That is the first place the program looks. So you do not need to modify any functions. Including binary files inside a python distriubtion can be done using a MANIFEST.in file, like so: https://github.com/soft-matter/pims/blob/master/MANIFEST.in Thanks for the heads up about the version, I could find a stable solution to get the latest version number automatically so we are stuck with bumping it every now and then. You could call the pims.bioformats._download_jar(version=xxx) if you want to have a different version.

GenevieveBuckley commented 5 years ago

cc @jni