Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

import --fetch-jars #162

Merged
merged 18 commits into from
Jul 9, 2020
Merged

import --fetch-jars #162

merged 18 commits into from
Jul 9, 2020

Conversation

manics
Copy link
Member

@manics manics commented Jan 8, 2020

Thought I'd see how difficult it is to automatically fetch the jars....

$ rm -rf ~/omero/jars/

$ omero import test.fake
Downloading https://downloads.openmicroscopy.org/omero/latest/OMERO.java.zip

... import as normal...

Closes #161

@manics
Copy link
Member Author

manics commented Jan 9, 2020

--exclude

For 5.6.1

@joshmoore
Copy link
Member

Two pretty self-unsimilar options come to mind:

  • a more maven-like strategy (see jgo)
  • doing this without a flag (but perhaps a warning) to a temporary location; a flag could make it permanent: import --fetch-jars=$LOCATION

@manics
Copy link
Member Author

manics commented Jan 9, 2020

OMERO.java is a 125 MB download, I don't think we should download that automatically

@joshmoore
Copy link
Member

I'd bet most users would prefer for us to just do it, though maybe not repeatedly.

@manics
Copy link
Member Author

manics commented Mar 10, 2020

Hard-coding the OMERO.java version could potentially be avoided by fetching the server version:

        c = self.ctx.conn(args)
        version = c.sf.getConfigService().getVersion()

Though this assumes OMERO.java version == OMERO.server version. It also requires the logic from https://github.com/ome/omego/blob/v0.7.0/omego/artifacts.py#L391 to figure out the build number.

@joshmoore
Copy link
Member

cc: @sbesson

I'm still for having this somewhat transport rather than a solely being a new argument that needs calling.

@manics
Copy link
Member Author

manics commented Jun 3, 2020

To make this more maintainable we could:

  • Move the omego artifacts plugin to a new omero cli plugin e.g. package-download
  • Use that plugin/library to download the OMERO client jars for the latest version (or perhaps the latest major version matching the OMERO-py version?)

@manics manics force-pushed the import-fetch-jars branch 2 times, most recently from cbe1ca8 to d988b3f Compare June 30, 2020 08:16
@manics
Copy link
Member Author

manics commented Jun 30, 2020

As requested I've made it automatically download the jars if required, the latest https://downloads.openmicroscopy.org/omero/latest/OMERO.java.zip will be fetched.

If you want to force a re-download, update or download a different version of the jars pass a version to the --fetch-jars argument:

$ rm -rf ~/omero/jars
$ omero import test.fake
Downloading https://downloads.openmicroscopy.org/omero/latest/OMERO.java.zip

<import as normal>

$ cat ~/omero/jars/OMERO.java.txt
OMERO.java-5.6.1-ice36-b225
$ omero import --fetch-jars 5.5
Downloading https://downloads.openmicroscopy.org/omero/5.5/OMERO.java.zip

$ cat ~/omero/jars/OMERO.java.txt
OMERO.java-5.5.1-ice36-b122
$ omero import --fetch-jars latest
Downloading https://downloads.openmicroscopy.org/omero/latest/OMERO.java.zip

$ cat ~/omero/jars/OMERO.java.txt
OMERO.java-5.6.1-ice36-b225

The available version strings are whatever https://downloads.openmicroscopy.org/omero/{version}/OMERO.java.zip redirects are in place on our downloads server.

@manics
Copy link
Member Author

manics commented Jun 30, 2020

(Forgot to push the last commit before commenting)

src/omero/plugins/import.py Outdated Show resolved Hide resolved
src/omero/plugins/import.py Outdated Show resolved Hide resolved
src/omero/plugins/import.py Outdated Show resolved Hide resolved
Copy link
Member

@joshmoore joshmoore left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the auto-download 👍 The re-fetching based on versions also looks good. Has a jenv/rbenv vibe to it. Only other thought I had was whether or not the choice could be via symlink, but that would be less fun on Windows, I assume.

src/omero/plugins/import.py Outdated Show resolved Hide resolved
@@ -517,6 +542,43 @@ def importer(self, args):
else:
self.do_import(command_args, xargs)

def _userdir_jars(self, parentonly=False):
user_jars = get_omero_userdir() / 'jars'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No objections to this unless we foresee moving away from ~/omero soonish. If so, then perhaps something like user_cache_dir()/omero would be safer (so people don't have to re-download).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a fair point, but I think having two different dirs for storing user state is worse than re-downloading. If there's a concrete suggestion for the location of user_cache_dir() shouldn't we modify get_omero_userdir() instead?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My proposal for moving forward would be to place an omero subdirectories into existing directories like .config, .cache. If that's controversial at all, let's not block this PR.

@manics
Copy link
Member Author

manics commented Jul 1, 2020

I had to mess around with the Ice build due to openssl issues. What I think is happening is that https://github.com/ome/zeroc-ice-py-manylinux/releases/download/0.2.0/zeroc_ice-3.6.5-cp36-cp36m-manylinux2010_x86_64.whl included a bundled openssl library which is somehow incompatible with Travis python.

https://github.com/ome/zeroc-ice-ubuntu1804/releases/download/0.3.0/zeroc_ice-3.6.5-cp36-cp36m-linux_x86_64.whl doesn't work, presumably because Travis Python 3.6 is different from the Ubuntu system Python 3.6.

A possible way around this is to build wheels specific to Travis, but for now I've changed this to use the default source package.

Note the reason https requests are being made is that although most tests in https://github.com/ome/omero-py/blob/master/test/unit/clitest/test_import.py that require the jars are disabled with @pytest.mark.skipif(OMERODIR is False, reason="Needs client dir") some of them aren't marked:

help_arguments = ("-h", "--javahelp", "--java-help", "--advanced-help")

and are instead allowed to return a non-zero exit code if the jars are missing:
@pytest.mark.parametrize('help_argument', help_arguments)
def testHelp(self, help_argument):
"""Test help arguments"""
self.args += [help_argument]
self.cli.invoke(self.args)

$ omero import --advanced-help
Error: Could not find or load main class ome.formats.importer.cli.CommandLineImporter

With this PR the jars are now automatically downloaded.

If you're wondering whether the other import tests marked @pytest.mark.skipif(OMERODIR is False, reason="Needs client dir") should now pass, some of them do, but some of them are broken, suggesting we never run these unit tests with OMERODIR defined.

@manics
Copy link
Member Author

manics commented Jul 1, 2020

See #231 (which includes the commits from this PR) for the fixed import tests. I can merge that PR into this one if you think it's appropriate.

@joshmoore
Copy link
Member

I can merge that PR into this one if you think it's appropriate.

👍

Only other comment at this stage is whether or not omero import could print out the used version.

@manics
Copy link
Member Author

manics commented Jul 2, 2020

I've:

Copy link
Member

@joshmoore joshmoore left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good. Two small code issues. The only other thing I notice is that when using the downloaded files that debugging is skewed since logback-cli.xml is missing (perhaps related to some of your test issues?)

Options I can think of:

  • move logback-cli.xml to one of the jars
  • download it separately
  • bundle it into python (?!)

if not jars_dir.exists():
jars_dir.mkdir()
with urlopen(omero_java_zip) as resp:
with ZipFile(BytesIO(resp.read())) as zipfile:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may fall more under #217, but some feedback of the download progress at least in an interactive terminal will probably prevent consternation.

Copy link
Member Author

@manics manics Jul 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could look into TQDM https://github.com/tqdm/tqdm

But that's another dependency- should we split omero-cli out of omero-py to avoid installing UI dependencies before going further?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I imagine that's one we put on the backburner.

src/omero/plugins/import.py Outdated Show resolved Hide resolved
Print out OMERO.java version if using auto-downloaded jars
@manics
Copy link
Member Author

manics commented Jul 2, 2020

logback-cli.xml: I think it would make sense for it to be part of the OMERO.java zip, I don't know whether it's better to be inside a jar or outside. Since this PR now distinguishes between the downloaded OMERO.java and the default lib/client it should be easy to adjust the logback path depending on where the jars are found.

@joshmoore
Copy link
Member

Ok. So if we update https://github.com/ome/openmicroscopy/blob/develop/build.xml#L302 we'll get logback-cli.xml into that directory and things should just magically start working... (Worth getting that location set now?)

Otherwise, 👍

@manics
Copy link
Member Author

manics commented Jul 2, 2020

After inserting an extra print to check:

$ git diff
diff --git a/src/omero/plugins/import.py b/src/omero/plugins/import.py
index d23312c1..c890f928 100644
--- a/src/omero/plugins/import.py
+++ b/src/omero/plugins/import.py
@@ -530,6 +530,7 @@ class ImportControl(BaseControl):
                     103, "No JAR files found under '%s'" % client_dir)

         logback = "-Dlogback.configurationFile=%s" % xml_file
+        print(logback)
         return classpath, logback

     def importer(self, args):
$ OMERO_USERDIR=/tmp/xx omero import --advanced-help
Using OMERO.java-5.6.1-ice36-b225
-Dlogback.configurationFile=/tmp/xx/jars/OMERO.java-5.6.1-ice36-b225/libs/logback-cli.xml
...
$ OMERODIR=/openmicroscopy/dist/ omero import --advanced-help
-Dlogback.configurationFile=/openmicroscopy/dist/etc/logback-cli.xml
...

Copy link
Member

@sbesson sbesson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested using a fresh omero-py virtual environment

$ venv/bin/omero import test.fake -f
Downloading https://downloads.openmicroscopy.org/omero/latest/OMERO.java.zip
Using OMERO.java-5.6.1-ice36-b225
...
$ rm -rf ~/omero/jars/
$ venv/bin/omero import test.fake -f
Downloading https://downloads.openmicroscopy.org/omero/latest/OMERO.java.zip
Using OMERO.java-5.6.1-ice36-b225
...
$ rm -rf ~/omero/jars/
$ venv/bin/omero import --fetch-jars 5.6
Downloading https://downloads.openmicroscopy.org/omero/5.6/OMERO.java.zip
$ venv/bin/omero import test.fake -f
Using OMERO.java-5.6.1-ice36-b225
...
$ venv/bin/omero import --fetch-jars 5.4
Downloading https://downloads.openmicroscopy.org/omero/5.4/OMERO.java.zip
$ venv/bin/omero import test.fake -f
Using OMERO.java-5.4.10-ice36-b105
...

The feature is very useful and the newly introduced API makes sense.

Are we considering a release omero-py 5.8.0 with this PR included? Shoudl this coordinated with the upcoming release of OMERO.java including the logging configuration file?

src/omero/plugins/import.py Outdated Show resolved Hide resolved
src/omero/plugins/import.py Outdated Show resolved Hide resolved
src/omero/plugins/import.py Show resolved Hide resolved
Co-authored-by: Sébastien Besson <seb.besson@gmail.com>
@manics manics closed this Jul 8, 2020
@manics manics reopened this Jul 8, 2020
@joshmoore
Copy link
Member

Thanks again, @manics. I think this is going to make things much nicer for people since the move to OMERODIR. Merging.

(I'd add that as it gets usage there could well be feature requests for the likes of --list-jars, --del-jars=$OLD_VERSION, etc. which may even be best-placed in its own plugin.)

@joshmoore joshmoore merged commit 36b3d6c into ome:master Jul 9, 2020
@manics manics deleted the import-fetch-jars branch July 9, 2020 13:19
@sbesson
Copy link
Member

sbesson commented Jul 9, 2020

Should we release the current state of master as omero-py 5.8.0 or would you like to include #233 ?

@manics
Copy link
Member Author

manics commented Jul 9, 2020

It'd be nice to include #233, but that may need futher discussions, so I wouldn't say it's a blocker. Feel free to push to it if you want.

PRs merged since 5.7.1:

Using https://gist.github.com/manics/383b4481e1c3a193d224016b01a5d52a
GH_TOKEN=$(git config github.token) GH_REPO=omero-py ../generate_release_notes/generate_release_notes.py v5.7.1 master --version v5.8.0

  • import --fetch-jars (#162)
  • fix logging attribute error (#226)
  • Add PyYAML as a dependency of omero-py (#228)
  • bin/omero entrypoint (#229)
  • hql.py: when querying masks, filter bytes field (#230)

#226 is the only bug fix so if that's not urgent I think we can wait a bit.

return None, omero_java_txt

def download_omero_java(self, version):
omero_java_zip = OMERO_JAVA_ZIP.format(version=version)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It occurs to me for the testing of ome/openmicroscopy#6255 that version should likely have been used directly if it started with http(s)://

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see: #303

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

omero import needs to check for OMERODIR
4 participants