summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDanielle Jenkins <d@d6e.io>2016-06-20 18:01:01 +0200
committerDanielle Jenkins <d@d6e.io>2016-06-20 18:01:01 +0200
commit5a733959061ee97a6d24a32d61694a1f4ea9ab5f (patch)
tree9d1da0aeb254422aabdc5889e55c2cd5fe8847ce
parentcef9d6b5edf6c40362b0cf40c81201f7092607c4 (diff)
parent027201aaecfcc0ad14602bf25b368473306cc33d (diff)
downloadtox-5a733959061ee97a6d24a32d61694a1f4ea9ab5f.tar.gz
Merged in jtpereyda/tox/jtpereyda-cleanup (pull request #194)
Cleanup: VirtualEnv.getcommandpath
-rw-r--r--tox/venv.py55
1 files changed, 35 insertions, 20 deletions
diff --git a/tox/venv.py b/tox/venv.py
index 2e46098..f6dabfc 100644
--- a/tox/venv.py
+++ b/tox/venv.py
@@ -79,38 +79,53 @@ class VirtualEnv(object):
return "<VirtualEnv at %r>" % (self.path)
def getcommandpath(self, name, venv=True, cwd=None):
- """ return absolute path (str or localpath) for specified
- command name. If it's a localpath we will rewrite it as
- as a relative path. If venv is True we will check if the
- command is coming from the venv or is whitelisted to come
- from external. """
+ """ Return absolute path (str or localpath) for specified command name.
+ - If it's a local path we will rewrite it as as a relative path.
+ - If venv is True we will check if the command is coming from the venv
+ or is whitelisted to come from external.
+ """
name = str(name)
if os.path.isabs(name):
return name
if os.path.split(name)[0] == ".":
- p = cwd.join(name)
- if p.check():
- return str(p)
- p = None
+ path = cwd.join(name)
+ if path.check():
+ return str(path)
+
if venv:
- p = py.path.local.sysfind(name, paths=[self.envconfig.envbindir])
- if p is not None:
- return p
- p = py.path.local.sysfind(name)
- if p is None:
+ path = self._venv_lookup_and_check_external_whitelist(name)
+ else:
+ path = self._normal_lookup(name)
+
+ if path is None:
raise tox.exception.InvocationError(
"could not find executable %r" % (name,))
- # p is not found in virtualenv script/bin dir
- if venv:
- if not self.is_allowed_external(p):
- self.session.report.warning(
+
+ return str(path) # will not be rewritten for reporting
+
+ def _venv_lookup_and_check_external_whitelist(self, name):
+ path = self._venv_lookup(name)
+ if path is None:
+ path = self._normal_lookup(name)
+ if path is not None:
+ self._check_external_allowed_and_warn(path)
+ return path
+
+ def _venv_lookup(self, name):
+ return py.path.local.sysfind(name, paths=[self.envconfig.envbindir])
+
+ def _normal_lookup(self, name):
+ return py.path.local.sysfind(name)
+
+ def _check_external_allowed_and_warn(self, path):
+ if not self.is_allowed_external(path):
+ self.session.report.warning(
"test command found but not installed in testenv\n"
" cmd: %s\n"
" env: %s\n"
"Maybe you forgot to specify a dependency? "
"See also the whitelist_externals envconfig setting." % (
- p, self.envconfig.envdir))
- return str(p) # will not be rewritten for reporting
+ path, self.envconfig.envdir))
def is_allowed_external(self, p):
tryadd = [""]