-- cgit v1.2.1 From b47956354960dcae6de72300cfa8d9d341d43f2b Mon Sep 17 00:00:00 2001 From: joshpere Date: Thu, 14 Apr 2016 11:59:37 -0700 Subject: Cleanup: Rename local variable for clarity --- tox/venv.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/tox/venv.py b/tox/venv.py index 2e46098..35a50e5 100644 --- a/tox/venv.py +++ b/tox/venv.py @@ -88,29 +88,29 @@ class VirtualEnv(object): 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) + path = None 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 = py.path.local.sysfind(name, paths=[self.envconfig.envbindir]) + if path is not None: + return path + path = py.path.local.sysfind(name) + if path is None: raise tox.exception.InvocationError( "could not find executable %r" % (name,)) - # p is not found in virtualenv script/bin dir + # path is not found in virtualenv script/bin dir if venv: - if not self.is_allowed_external(p): + 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)) + return str(path) # will not be rewritten for reporting def is_allowed_external(self, p): tryadd = [""] -- cgit v1.2.1 From 6d00104096a4986308df8f737460fb9d0716504d Mon Sep 17 00:00:00 2001 From: joshpere Date: Thu, 14 Apr 2016 12:04:20 -0700 Subject: Cleanup: Format comments for easier reading. --- tox/venv.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tox/venv.py b/tox/venv.py index 35a50e5..fb6ed77 100644 --- a/tox/venv.py +++ b/tox/venv.py @@ -79,11 +79,11 @@ class VirtualEnv(object): return "" % (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 -- cgit v1.2.1 From b7339866040d05986ffc5ca2a1c275c9a56fb3fa Mon Sep 17 00:00:00 2001 From: joshpere Date: Thu, 14 Apr 2016 12:15:42 -0700 Subject: Cleanup: Extract function for readability. The _venv_lookup function is now self-descriptive and more self-contained. --- tox/venv.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/tox/venv.py b/tox/venv.py index fb6ed77..c75b75e 100644 --- a/tox/venv.py +++ b/tox/venv.py @@ -91,17 +91,22 @@ class VirtualEnv(object): path = cwd.join(name) if path.check(): return str(path) - path = None + if venv: - path = py.path.local.sysfind(name, paths=[self.envconfig.envbindir]) - if path is not None: - return path - path = py.path.local.sysfind(name) + path = self._venv_lookup(name) + else: + path = py.path.local.sysfind(name) + if path is None: raise tox.exception.InvocationError( "could not find executable %r" % (name,)) - # path is not found in virtualenv script/bin dir - if venv: + + return str(path) # will not be rewritten for reporting + + def _venv_lookup(self, name): + path = py.path.local.sysfind(name, paths=[self.envconfig.envbindir]) + if path is None: + path = py.path.local.sysfind(name) if not self.is_allowed_external(path): self.session.report.warning( "test command found but not installed in testenv\n" @@ -110,7 +115,7 @@ class VirtualEnv(object): "Maybe you forgot to specify a dependency? " "See also the whitelist_externals envconfig setting." % ( path, self.envconfig.envdir)) - return str(path) # will not be rewritten for reporting + return path def is_allowed_external(self, p): tryadd = [""] -- cgit v1.2.1 From a7641bd69c70cf2a98a114ddd8abb09256322789 Mon Sep 17 00:00:00 2001 From: joshpere Date: Thu, 14 Apr 2016 12:18:29 -0700 Subject: Cleanup: Extract duplicate code --- tox/venv.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tox/venv.py b/tox/venv.py index c75b75e..a943ec4 100644 --- a/tox/venv.py +++ b/tox/venv.py @@ -95,7 +95,7 @@ class VirtualEnv(object): if venv: path = self._venv_lookup(name) else: - path = py.path.local.sysfind(name) + path = self._normal_lookup(name) if path is None: raise tox.exception.InvocationError( @@ -106,7 +106,7 @@ class VirtualEnv(object): def _venv_lookup(self, name): path = py.path.local.sysfind(name, paths=[self.envconfig.envbindir]) if path is None: - path = py.path.local.sysfind(name) + path = self._normal_lookup(name) if not self.is_allowed_external(path): self.session.report.warning( "test command found but not installed in testenv\n" @@ -117,6 +117,9 @@ class VirtualEnv(object): path, self.envconfig.envdir)) return path + def _normal_lookup(self, name): + return py.path.local.sysfind(name) + def is_allowed_external(self, p): tryadd = [""] if sys.platform == "win32": -- cgit v1.2.1 From 027201aaecfcc0ad14602bf25b368473306cc33d Mon Sep 17 00:00:00 2001 From: joshpere Date: Thu, 14 Apr 2016 12:32:18 -0700 Subject: Cleanup: Renaming and method extraction. --- tox/venv.py | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/tox/venv.py b/tox/venv.py index a943ec4..f6dabfc 100644 --- a/tox/venv.py +++ b/tox/venv.py @@ -93,7 +93,7 @@ class VirtualEnv(object): return str(path) if venv: - path = self._venv_lookup(name) + path = self._venv_lookup_and_check_external_whitelist(name) else: path = self._normal_lookup(name) @@ -103,22 +103,29 @@ class VirtualEnv(object): return str(path) # will not be rewritten for reporting - def _venv_lookup(self, name): - path = py.path.local.sysfind(name, paths=[self.envconfig.envbindir]) + def _venv_lookup_and_check_external_whitelist(self, name): + path = self._venv_lookup(name) if path is None: path = self._normal_lookup(name) - if not self.is_allowed_external(path): - self.session.report.warning( + 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." % ( path, self.envconfig.envdir)) - return path - - def _normal_lookup(self, name): - return py.path.local.sysfind(name) def is_allowed_external(self, p): tryadd = [""] -- cgit v1.2.1