Bug 1304176 - Document and refactor query_virtualenv_path; r?ted draft
authorGregory Szorc <gps@mozilla.com>
Tue, 20 Sep 2016 14:59:14 -0700
changeset 417184 006b205c5e8f8c5b2398115feb362ba77a096d88
parent 417183 93562be5a75bc8d0994bcc068dfa2f3584c4c636
child 532047 9114055caf2ba952a10fe6850fbe21edae5039be
push id30356
push userbmo:gps@mozilla.com
push dateFri, 23 Sep 2016 19:11:51 +0000
reviewersted
bugs1304176
milestone52.0a1
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
testing/mozharness/mozharness/base/python.py
--- 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
         applied.
         """
         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',