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
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',