6923: Improve Arvados SDK version logging in Crunch run script.
authorBrett Smith <brett@curoverse.com>
Mon, 9 Nov 2015 15:13:21 +0000 (10:13 -0500)
committerBrett Smith <brett@curoverse.com>
Wed, 18 Nov 2015 22:58:54 +0000 (17:58 -0500)
* Use a mechanism that works in a wider variety of containers.  This
  only depends on Python itself and setuptools.  It won't generate
  spurious warnings by calling dpkg-query on Red Hat containers.
* Don't log the version when we successfully set up the specified
  arvados_sdk_version.  The version will only be '0.1' in this case,
  and that's not helpful.

sdk/cli/bin/crunch-job

index 28da66d0ca74296ef8475a5d96c0cb6fb3d41764..a7f06028e58bb7f442e0217ee8878ae9d2bac2d5 100755 (executable)
@@ -2169,10 +2169,11 @@ if (@ARGV) {
     $Log->("Built Python SDK virtualenv");
   }
 
-  my $pip_bin = "pip";
+  my @pysdk_version_cmd = ("python", "-c",
+    "from pkg_resources import get_distribution as get; print get('arvados-python-client').version");
   if ($venv_built) {
     $Log->("Running in Python SDK virtualenv");
-    $pip_bin = "$venv_dir/bin/pip";
+    @pysdk_version_cmd = ();
     my $orig_argv = join(" ", map { quotemeta($_); } @ARGV);
     @ARGV = ("/bin/sh", "-ec",
              ". \Q$venv_dir/bin/activate\E; exec $orig_argv");
@@ -2181,14 +2182,18 @@ if (@ARGV) {
            "\$PATH. Can't install Python SDK.");
   }
 
-  my $pkgs = `(\Q$pip_bin\E freeze 2>/dev/null | grep arvados) || dpkg-query --show '*arvados*'`;
-  if ($pkgs) {
-    $Log->("Using Arvados SDK:");
-    foreach my $line (split /\n/, $pkgs) {
-      $Log->($line);
+  if (@pysdk_version_cmd) {
+    open(my $pysdk_version_pipe, "-|", @pysdk_version_cmd);
+    my $pysdk_version = <$pysdk_version_pipe>;
+    close($pysdk_version_pipe);
+    if ($? == 0) {
+      chomp($pysdk_version);
+      $Log->("Using Arvados SDK version $pysdk_version");
+    } else {
+      # A lot could've gone wrong here, but pretty much all of it means that
+      # Python won't be able to load the Arvados SDK.
+      $Log->("Warning: Arvados SDK not found");
     }
-  } else {
-    $Log->("Arvados SDK packages not found");
   }
 
   while (my ($sdk_dir, $sdk_envkey) = each(%SDK_ENVVARS)) {