Bug 1304176 - Document and refactor query_virtualenv_path; r=ted
authorGregory Szorc <gps@mozilla.com>
Tue, 20 Sep 2016 14:59:14 -0700
changeset 315073 d5355738ce1edf58cabee849024c7bd02c641b77
parent 315072 1c0787d40b9722d31c09f243b543c64de78473ec
child 315074 a8254e91e0fed9395c238d5b60867c7907fa261a
push id32537
push usergszorc@mozilla.com
push dateFri, 23 Sep 2016 20:03:51 +0000
treeherderautoland@d5355738ce1e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1304176 - Document and refactor query_virtualenv_path; r=ted We don't need a variable to hold the result. Just use return. The "virtualenv_path" option has a default value, so it should always be set. Add code confirming that. And refactor the code to use less indentation. And remove a branch that can never occur since the virtualenv path is guaranteed to be defined. MozReview-Commit-ID: DZ6LnlxZJFj
--- a/testing/mozharness/mozharness/base/python.py
+++ b/testing/mozharness/mozharness/base/python.py
@@ -108,43 +108,44 @@ class VirtualenvMixin(object):
         See the documentation for install_module for how the arguments are
         self._virtualenv_modules.append((name, url, method, requirements,
                                          optional, two_pass, editable))
     def query_virtualenv_path(self):
-        c = self.config
+        """Determine the absolute path to the virtualenv."""
         dirs = self.query_abs_dirs()
-        virtualenv = None
         if 'abs_virtualenv_dir' in dirs:
-            virtualenv = dirs['abs_virtualenv_dir']
-        elif c.get('virtualenv_path'):
-            if os.path.isabs(c['virtualenv_path']):
-                virtualenv = c['virtualenv_path']
-            else:
-                virtualenv = os.path.join(dirs['abs_work_dir'],
-                                          c['virtualenv_path'])
-        return virtualenv
+            return dirs['abs_virtualenv_dir']
+        p = self.config['virtualenv_path']
+        if not p:
+            self.fatal('virtualenv_path config option not set; '
+                       'this should never happen')
+        if os.path.isabs(p):
+            return p
+        else:
+            return os.path.join(dirs['abs_work_dir'], p)
     def query_python_path(self, binary="python"):
         """Return the path of a binary inside the virtualenv, if
         c['virtualenv_path'] is set; otherwise return the binary name.
         Otherwise return None
         if binary not in self.python_paths:
             bin_dir = 'bin'
             if self._is_windows():
                 bin_dir = 'Scripts'
             virtualenv_path = self.query_virtualenv_path()
-            if virtualenv_path:
-                self.python_paths[binary] = os.path.abspath(os.path.join(virtualenv_path, bin_dir, binary))
-            else:
-                self.python_paths[binary] = self.query_exe(binary)
+            self.python_paths[binary] = os.path.abspath(os.path.join(virtualenv_path, bin_dir, binary))
         return self.python_paths[binary]
     def query_python_site_packages_path(self):
         if self.site_packages_path:
             return self.site_packages_path
         python = self.query_python_path()
         self.site_packages_path = self.get_output_from_command(
             [python, '-c',