From 0414380dec2104dedc163e7489f445621ef0e5f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Tomulik?= Date: Wed, 7 Nov 2018 01:55:58 +0100 Subject: corrections after bdbaddog's code review --- doc/user/misc.xml | 2 +- src/engine/SCons/Platform/VE.py | 136 ---------- src/engine/SCons/Platform/VETests.py | 299 --------------------- src/engine/SCons/Platform/posix.py | 4 +- src/engine/SCons/Platform/virtualenv.py | 120 +++++++++ src/engine/SCons/Platform/virtualenvTests.py | 243 +++++++++++++++++ src/engine/SCons/Platform/win32.py | 4 +- src/engine/SCons/Script/Main.py | 8 +- src/engine/SCons/Script/SConsOptions.py | 4 +- src/engine/SCons/Script/__init__.py | 4 +- src/engine/SCons/Util.py | 26 ++ src/engine/SCons/UtilTests.py | 58 ++++ .../activated/option/enable-virtualenv.py | 14 +- .../activated/option/ignore-virtualenv.py | 12 +- .../activated/virtualenv_activated_python.py | 12 +- .../activated/virtualenv_detect_virtualenv.py | 8 +- .../always/virtualenv_global_function.py | 4 +- .../regularenv/virtualenv_detect_regularenv.py | 8 +- .../unactivated/virtualenv_unactivated_python.py | 12 +- 19 files changed, 495 insertions(+), 483 deletions(-) delete mode 100644 src/engine/SCons/Platform/VE.py delete mode 100644 src/engine/SCons/Platform/VETests.py create mode 100644 src/engine/SCons/Platform/virtualenv.py create mode 100644 src/engine/SCons/Platform/virtualenvTests.py diff --git a/doc/user/misc.xml b/doc/user/misc.xml index a5092d0..a595e59 100644 --- a/doc/user/misc.xml +++ b/doc/user/misc.xml @@ -654,7 +654,7 @@ env.Command('directory_build_info', - This issue may be overcame by using --enable-virtualenv + This issue may be overcome by using --enable-virtualenv option. The option automatically imports virtualenv-related environment variables to all created construction environment env['ENV'], and modifies SCons PATH appropriately to prefer virtualenv's executables. diff --git a/src/engine/SCons/Platform/VE.py b/src/engine/SCons/Platform/VE.py deleted file mode 100644 index f7aa80c..0000000 --- a/src/engine/SCons/Platform/VE.py +++ /dev/null @@ -1,136 +0,0 @@ -"""SCons.Platform.VE - -Support for virtualenv. -""" - -# -# __COPYRIGHT__ -# -# Permission is hereby granted, free of charge, to any person obtaining -# a copy of this software and associated documentation files (the -# "Software"), to deal in the Software without restriction, including -# without limitation the rights to use, copy, modify, merge, publish, -# distribute, sublicense, and/or sell copies of the Software, and to -# permit persons to whom the Software is furnished to do so, subject to -# the following conditions: -# -# The above copyright notice and this permission notice shall be included -# in all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY -# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE -# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -# - -__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" - -import os -import sys -import SCons.Util - - -def _get_bool_envvar(name, default=False): - try: - var = os.environ[name] - except KeyError: - return default - try: - return bool(int(var)) - except ValueError: - if str(var).lower() in ('true', 'yes', 'y', 'on'): - return True - elif str(var).lower() in ('false', 'no', 'n', 'off'): - return False - else: - return default - - -virtualenv_enabled_by_default = False - - -def _enable_virtualenv_default(): - return _get_bool_envvar('SCONS_ENABLE_VIRTUALENV', virtualenv_enabled_by_default) - - -def _ignore_virtualenv_default(): - return _get_bool_envvar('SCONS_IGNORE_VIRTUALENV', False) - - -enable_virtualenv = _enable_virtualenv_default() -ignore_virtualenv = _ignore_virtualenv_default() -virtualenv_variables = ['VIRTUAL_ENV', 'PIPENV_ACTIVE'] - - -def _running_in_virtualenv(): - """Returns True, if scons is executed within a virtualenv""" - # see https://stackoverflow.com/a/42580137 - return (hasattr(sys, 'real_prefix') or - (hasattr(sys, 'base_prefix') and sys.base_prefix != sys.prefix)) - - -def _is_path_in(path, base): - """Returns true, if **path** is located under the **base** directory.""" - if not path or not base: # empty path may happen, base too - return False - rp = os.path.relpath(path, base) - return ((not rp.startswith(os.path.pardir)) and (not rp == os.path.curdir)) - - -def _inject_venv_variables(env): - if 'ENV' not in env: - env['ENV'] = {} - ENV = env['ENV'] - for name in virtualenv_variables: - try: - ENV[name] = os.environ[name] - except KeyError: - pass - -def _inject_venv_path(env, path_list=None): - """Modify environment such that SCons will take into account its virtualenv - when running external tools.""" - if path_list is None: - path_list = os.getenv('PATH') - env.PrependENVPath('PATH', select_paths_in_venv(path_list)) - - -def select_paths_in_venv(path_list): - """Returns a list of paths from **path_list** which are under virtualenv's - home directory.""" - if SCons.Util.is_String(path_list): - path_list = path_list.split(os.path.pathsep) - # Find in path_list the paths under the virtualenv's home - return [path for path in path_list if IsInVirtualenv(path)] - - -def ImportVirtualenv(env): - """Copies virtualenv-related environment variables from OS environment - to ``env['ENV']`` and prepends virtualenv's PATH to ``env['ENV']['PATH']``. - """ - _inject_venv_variables(env) - _inject_venv_path(env) - - -def Virtualenv(): - """Returns path to the virtualenv home if scons is executing within a - virtualenv or None, if not.""" - if _running_in_virtualenv(): - return sys.prefix - return None - - -def IsInVirtualenv(path): - """Returns True, if **path** is under virtualenv's home directory. If not, - or if we don't use virtualenv, returns False.""" - return _is_path_in(path, Virtualenv()) - - -# Local Variables: -# tab-width:4 -# indent-tabs-mode:nil -# End: -# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/src/engine/SCons/Platform/VETests.py b/src/engine/SCons/Platform/VETests.py deleted file mode 100644 index 8fd94af..0000000 --- a/src/engine/SCons/Platform/VETests.py +++ /dev/null @@ -1,299 +0,0 @@ -# -# __COPYRIGHT__ -# -# Permission is hereby granted, free of charge, to any person obtaining -# a copy of this software and associated documentation files (the -# "Software"), to deal in the Software without restriction, including -# without limitation the rights to use, copy, modify, merge, publish, -# distribute, sublicense, and/or sell copies of the Software, and to -# permit persons to whom the Software is furnished to do so, subject to -# the following conditions: -# -# The above copyright notice and this permission notice shall be included -# in all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY -# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE -# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -# - -__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" - -import SCons.compat - -import collections -import unittest -import os -import sys - -import SCons.Platform.VE -import SCons.Util - -class Environment(collections.UserDict): - def Detect(self, cmd): - return cmd - - def AppendENVPath(self, key, value): - if SCons.Util.is_List(value): - value = os.path.pathsep.join(value) - if 'ENV' not in self: - self['ENV'] = {} - current = self['ENV'].get(key) - if not current: - self['ENV'][key] = value - else: - self['ENV'][key] = os.path.pathsep.join([current, value]) - - def PrependENVPath(self, key, value): - if SCons.Util.is_List(value): - value = os.path.pathsep.join(value) - if 'ENV' not in self: - self['ENV'] = {} - current = self['ENV'].get(key) - if not current: - self['ENV'][key] = value - else: - self['ENV'][key] = os.path.pathsep.join([value, current]) - -class SysPrefixes(object): - """Used to temporarily mock sys.prefix, sys.real_prefix and sys.base_prefix""" - def __init__(self, prefix, real_prefix=None, base_prefix=None): - self._prefix = prefix - self._real_prefix = real_prefix - self._base_prefix = base_prefix - - def start(self): - self._store() - sys.prefix = self._prefix - if self._real_prefix is None: - if hasattr(sys, 'real_prefix'): - del sys.real_prefix - else: - sys.real_prefix = self._real_prefix - if self._base_prefix is None: - if hasattr(sys, 'base_prefix'): - del sys.base_prefix - else: - sys.base_prefix = self._base_prefix - - def stop(self): - self._restore() - - def __enter__(self): - self.start() - attrs = ('prefix', 'real_prefix', 'base_prefix') - return {k: getattr(sys, k) for k in attrs if hasattr(sys, k)} - - def __exit__(self, *args): - self.stop() - - def _store(self): - s = dict() - if hasattr(sys, 'real_prefix'): - s['real_prefix'] = sys.real_prefix - if hasattr(sys, 'base_prefix'): - s['base_prefix'] = sys.base_prefix - s['prefix'] = sys.prefix - self._stored = s - - def _restore(self): - s = self._stored - if 'real_prefix' in s: - sys.real_prefix = s['real_prefix'] - if 'base_prefix' in s: - sys.base_prefix = s['base_prefix'] - if 'prefix' in s: - sys.prefix = s['prefix'] - del self._stored - -class OsEnviron(object): - """Used to temporarily mock os.environ""" - def __init__(self, environ): - self._environ = environ - - def start(self): - self._stored = os.environ - os.environ = self._environ - - def stop(self): - os.environ = self._stored - del self._stored - - def __enter__(self): - self.start() - return os.environ - - def __exit__(self, *args): - self.stop() - -def _p(p): - """Converts path string **p** from posix format to os-specific format.""" - drive = [] - if p.startswith('/') and sys.platform == 'win32': - drive = ['C:'] - pieces = p.split('/') - return os.path.sep.join(drive + pieces) - -class _get_bool_envvar_TestCase(unittest.TestCase): - def test_missing(self): - with OsEnviron(dict()): - var = SCons.Platform.VE._get_bool_envvar('FOO') - assert var is False, "var should be False, not %s" % repr(var) - with OsEnviron({'FOO': '1'}): - var = SCons.Platform.VE._get_bool_envvar('BAR') - assert var is False, "var should be False, not %s" % repr(var) - - def test_true(self): - for foo in [ 'TRUE', 'True', 'true', - 'YES', 'Yes', 'yes', - 'Y', 'y', - 'ON', 'On', 'on', - '1', '20', '-1']: - with OsEnviron({'FOO': foo}): - var = SCons.Platform.VE._get_bool_envvar('FOO') - assert var is True, 'var should be True, not %s' % repr(var) - - def test_false(self): - for foo in [ 'FALSE', 'False', 'false', - 'NO', 'No', 'no', - 'N', 'n', - 'OFF', 'Off', 'off', - '0']: - with OsEnviron({'FOO': foo}): - var = SCons.Platform.VE._get_bool_envvar('FOO', True) - assert var is False, 'var should be True, not %s' % repr(var) - - def test_default(self): - with OsEnviron({'FOO': 'other'}): - var = SCons.Platform.VE._get_bool_envvar('FOO', True) - assert var is True, 'var should be True, not %s' % repr(var) - var = SCons.Platform.VE._get_bool_envvar('FOO', False) - assert var is False, 'var should be False, not %s' % repr(var) - - -class _is_path_in_TestCase(unittest.TestCase): - def test_false(self): - for args in [ ('',''), - ('', _p('/foo/bar')), - (_p('/foo/bar'), ''), - (_p('/foo/bar'), _p('/foo/bar')), - (_p('/foo/bar'), _p('/foo/bar/geez')), - (_p('/'), _p('/foo')), - (_p('foo'), _p('foo/bar')) ]: - assert SCons.Platform.VE._is_path_in(*args) is False, "_is_path_in(%r, %r) should be False" % args - - def test__true(self): - for args in [ (_p('/foo'), _p('/')), - (_p('/foo/bar'), _p('/foo')), - (_p('/foo/bar/geez'), _p('/foo/bar')), - (_p('/foo//bar//geez'), _p('/foo/bar')), - (_p('/foo/bar/geez'), _p('/foo//bar')), - (_p('/foo/bar/geez'), _p('//foo//bar')) ]: - assert SCons.Platform.VE._is_path_in(*args) is True, "_is_path_in(%r, %r) should be True" % args - -class IsInVirtualenvTestCase(unittest.TestCase): - def test_false(self): - # "without wirtualenv" - always false - with SysPrefixes(_p('/prefix')): - for p in [ _p(''), - _p('/foo'), - _p('/prefix'), - _p('/prefix/foo') ]: - assert SCons.Platform.VE.IsInVirtualenv(p) is False, "IsInVirtualenv(%r) should be False" % p - - # "with virtualenv" - with SysPrefixes(_p('/virtualenv/prefix'), real_prefix=_p('/real/prefix')): - for p in [ _p(''), - _p('/real/prefix/foo'), - _p('/virtualenv/prefix'), - _p('/virtualenv/prefix/bar/..'), - _p('/virtualenv/prefix/bar/../../bleah'), - _p('/virtualenv/bleah') ]: - assert SCons.Platform.VE.IsInVirtualenv(p) is False, "IsInVirtualenv(%r) should be False" % p - - # "with venv" - with SysPrefixes(_p('/virtualenv/prefix'), base_prefix=_p('/base/prefix')): - for p in [ _p(''), - _p('/base/prefix/foo'), - _p('/virtualenv/prefix'), - _p('/virtualenv/prefix/bar/..'), - _p('/virtualenv/prefix/bar/../../bleah'), - _p('/virtualenv/bleah') ]: - assert SCons.Platform.VE.IsInVirtualenv(p) is False, "IsInVirtualenv(%r) should be False" % p - - def test_true(self): - # "with virtualenv" - with SysPrefixes(_p('/virtualenv/prefix'), real_prefix=_p('/real/prefix')): - for p in [ _p('/virtualenv/prefix/foo'), - _p('/virtualenv/prefix/foo/bar') ]: - assert SCons.Platform.VE.IsInVirtualenv(p) is True, "IsInVirtualenv(%r) should be True" % p - - # "with venv" - with SysPrefixes(_p('/virtualenv/prefix'), base_prefix=_p('/base/prefix')): - for p in [ _p('/virtualenv/prefix/foo'), - _p('/virtualenv/prefix/foo/bar') ]: - assert SCons.Platform.VE.IsInVirtualenv(p) is True, "IsInVirtualenv(%r) should be True" % p - -class _inject_venv_pathTestCase(unittest.TestCase): - def path_list(self): - return [ - _p('/virtualenv/prefix/bin'), - _p('/virtualenv/prefix'), - _p('/virtualenv/prefix/../bar'), - _p('/home/user/.local/bin'), - _p('/usr/bin'), - _p('/opt/bin') - ] - def test_with_path_string(self): - env = Environment() - path_string = os.path.pathsep.join(self.path_list()) - with SysPrefixes(_p('/virtualenv/prefix'), real_prefix=_p('/real/prefix')): - SCons.Platform.VE._inject_venv_path(env, path_string) - assert env['ENV']['PATH'] == _p('/virtualenv/prefix/bin'), env['ENV']['PATH'] - - def test_with_path_list(self): - env = Environment() - with SysPrefixes(_p('/virtualenv/prefix'), real_prefix=_p('/real/prefix')): - SCons.Platform.VE._inject_venv_path(env, self.path_list()) - assert env['ENV']['PATH'] == _p('/virtualenv/prefix/bin'), env['ENV']['PATH'] - -class VirtualenvTestCase(unittest.TestCase): - def test_none(self): - def _msg(given): - return "Virtualenv() should be None, not %s" % repr(given) - - with SysPrefixes(_p('/prefix')): - ve = SCons.Platform.VE.Virtualenv() - assert ve is None , _msg(ve) - with SysPrefixes(_p('/base/prefix'), base_prefix=_p('/base/prefix')): - ve = SCons.Platform.VE.Virtualenv() - assert ve is None, _msg(ve) - - def test_not_none(self): - def _msg(expected, given): - return "Virtualenv() should == %r, not %s" % (_p(expected), repr(given)) - - with SysPrefixes(_p('/virtualenv/prefix'), real_prefix=_p('/real/prefix')): - ve = SCons.Platform.VE.Virtualenv() - assert ve == _p('/virtualenv/prefix'), _msg('/virtualenv/prefix', ve) - with SysPrefixes(_p('/same/prefix'), real_prefix=_p('/same/prefix')): - ve = SCons.Platform.VE.Virtualenv() - assert ve == _p('/same/prefix'), _msg('/same/prefix', ve) - with SysPrefixes(_p('/virtualenv/prefix'), base_prefix=_p('/base/prefix')): - ve = SCons.Platform.VE.Virtualenv() - assert ve == _p('/virtualenv/prefix'), _msg('/virtualenv/prefix', ve) - - -if __name__ == "__main__": - unittest.main() - - -# Local Variables: -# tab-width:4 -# indent-tabs-mode:nil -# End: -# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/src/engine/SCons/Platform/posix.py b/src/engine/SCons/Platform/posix.py index fb57521..ad4e859 100644 --- a/src/engine/SCons/Platform/posix.py +++ b/src/engine/SCons/Platform/posix.py @@ -41,8 +41,8 @@ import select import SCons.Util from SCons.Platform import TempFileMunge -from SCons.Platform.VE import ImportVirtualenv -from SCons.Platform.VE import ignore_virtualenv, enable_virtualenv +from SCons.Platform.virtualenv import ImportVirtualenv +from SCons.Platform.virtualenv import ignore_virtualenv, enable_virtualenv exitvalmap = { 2 : 127, diff --git a/src/engine/SCons/Platform/virtualenv.py b/src/engine/SCons/Platform/virtualenv.py new file mode 100644 index 0000000..03fb486 --- /dev/null +++ b/src/engine/SCons/Platform/virtualenv.py @@ -0,0 +1,120 @@ +"""SCons.Platform.virtualenv + +Support for virtualenv. +""" + +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +import os +import sys +import SCons.Util + + +virtualenv_enabled_by_default = False + + +def _enable_virtualenv_default(): + return SCons.Util.get_bool_envvar('SCONS_ENABLE_VIRTUALENV', virtualenv_enabled_by_default) + + +def _ignore_virtualenv_default(): + return SCons.Util.get_bool_envvar('SCONS_IGNORE_VIRTUALENV', False) + + +enable_virtualenv = _enable_virtualenv_default() +ignore_virtualenv = _ignore_virtualenv_default() +virtualenv_variables = ['VIRTUAL_ENV', 'PIPENV_ACTIVE'] + + +def _running_in_virtualenv(): + """Returns True, if scons is executed within a virtualenv""" + # see https://stackoverflow.com/a/42580137 + return (hasattr(sys, 'real_prefix') or + (hasattr(sys, 'base_prefix') and sys.base_prefix != sys.prefix)) + + +def _is_path_in(path, base): + """Returns true, if **path** is located under the **base** directory.""" + if not path or not base: # empty path may happen, base too + return False + rp = os.path.relpath(path, base) + return ((not rp.startswith(os.path.pardir)) and (not rp == os.path.curdir)) + + +def _inject_venv_variables(env): + if 'ENV' not in env: + env['ENV'] = {} + ENV = env['ENV'] + for name in virtualenv_variables: + try: + ENV[name] = os.environ[name] + except KeyError: + pass + +def _inject_venv_path(env, path_list=None): + """Modify environment such that SCons will take into account its virtualenv + when running external tools.""" + if path_list is None: + path_list = os.getenv('PATH') + env.PrependENVPath('PATH', select_paths_in_venv(path_list)) + + +def select_paths_in_venv(path_list): + """Returns a list of paths from **path_list** which are under virtualenv's + home directory.""" + if SCons.Util.is_String(path_list): + path_list = path_list.split(os.path.pathsep) + # Find in path_list the paths under the virtualenv's home + return [path for path in path_list if IsInVirtualenv(path)] + + +def ImportVirtualenv(env): + """Copies virtualenv-related environment variables from OS environment + to ``env['ENV']`` and prepends virtualenv's PATH to ``env['ENV']['PATH']``. + """ + _inject_venv_variables(env) + _inject_venv_path(env) + + +def Virtualenv(): + """Returns path to the virtualenv home if scons is executing within a + virtualenv or None, if not.""" + if _running_in_virtualenv(): + return sys.prefix + return None + + +def IsInVirtualenv(path): + """Returns True, if **path** is under virtualenv's home directory. If not, + or if we don't use virtualenv, returns False.""" + return _is_path_in(path, Virtualenv()) + + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/src/engine/SCons/Platform/virtualenvTests.py b/src/engine/SCons/Platform/virtualenvTests.py new file mode 100644 index 0000000..02b37ab --- /dev/null +++ b/src/engine/SCons/Platform/virtualenvTests.py @@ -0,0 +1,243 @@ +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +import SCons.compat + +import collections +import unittest +import os +import sys + +import SCons.Platform.virtualenv +import SCons.Util + +class Environment(collections.UserDict): + def Detect(self, cmd): + return cmd + + def AppendENVPath(self, key, value): + if SCons.Util.is_List(value): + value = os.path.pathsep.join(value) + if 'ENV' not in self: + self['ENV'] = {} + current = self['ENV'].get(key) + if not current: + self['ENV'][key] = value + else: + self['ENV'][key] = os.path.pathsep.join([current, value]) + + def PrependENVPath(self, key, value): + if SCons.Util.is_List(value): + value = os.path.pathsep.join(value) + if 'ENV' not in self: + self['ENV'] = {} + current = self['ENV'].get(key) + if not current: + self['ENV'][key] = value + else: + self['ENV'][key] = os.path.pathsep.join([value, current]) + +class SysPrefixes(object): + """Used to temporarily mock sys.prefix, sys.real_prefix and sys.base_prefix""" + def __init__(self, prefix, real_prefix=None, base_prefix=None): + self._prefix = prefix + self._real_prefix = real_prefix + self._base_prefix = base_prefix + + def start(self): + self._store() + sys.prefix = self._prefix + if self._real_prefix is None: + if hasattr(sys, 'real_prefix'): + del sys.real_prefix + else: + sys.real_prefix = self._real_prefix + if self._base_prefix is None: + if hasattr(sys, 'base_prefix'): + del sys.base_prefix + else: + sys.base_prefix = self._base_prefix + + def stop(self): + self._restore() + + def __enter__(self): + self.start() + attrs = ('prefix', 'real_prefix', 'base_prefix') + return {k: getattr(sys, k) for k in attrs if hasattr(sys, k)} + + def __exit__(self, *args): + self.stop() + + def _store(self): + s = dict() + if hasattr(sys, 'real_prefix'): + s['real_prefix'] = sys.real_prefix + if hasattr(sys, 'base_prefix'): + s['base_prefix'] = sys.base_prefix + s['prefix'] = sys.prefix + self._stored = s + + def _restore(self): + s = self._stored + if 'real_prefix' in s: + sys.real_prefix = s['real_prefix'] + if 'base_prefix' in s: + sys.base_prefix = s['base_prefix'] + if 'prefix' in s: + sys.prefix = s['prefix'] + del self._stored + +def _p(p): + """Converts path string **p** from posix format to os-specific format.""" + drive = [] + if p.startswith('/') and sys.platform == 'win32': + drive = ['C:'] + pieces = p.split('/') + return os.path.sep.join(drive + pieces) + + +class _is_path_in_TestCase(unittest.TestCase): + def test_false(self): + for args in [ ('',''), + ('', _p('/foo/bar')), + (_p('/foo/bar'), ''), + (_p('/foo/bar'), _p('/foo/bar')), + (_p('/foo/bar'), _p('/foo/bar/geez')), + (_p('/'), _p('/foo')), + (_p('foo'), _p('foo/bar')) ]: + assert SCons.Platform.virtualenv._is_path_in(*args) is False, "_is_path_in(%r, %r) should be False" % args + + def test__true(self): + for args in [ (_p('/foo'), _p('/')), + (_p('/foo/bar'), _p('/foo')), + (_p('/foo/bar/geez'), _p('/foo/bar')), + (_p('/foo//bar//geez'), _p('/foo/bar')), + (_p('/foo/bar/geez'), _p('/foo//bar')), + (_p('/foo/bar/geez'), _p('//foo//bar')) ]: + assert SCons.Platform.virtualenv._is_path_in(*args) is True, "_is_path_in(%r, %r) should be True" % args + +class IsInVirtualenvTestCase(unittest.TestCase): + def test_false(self): + # "without wirtualenv" - always false + with SysPrefixes(_p('/prefix')): + for p in [ _p(''), + _p('/foo'), + _p('/prefix'), + _p('/prefix/foo') ]: + assert SCons.Platform.virtualenv.IsInVirtualenv(p) is False, "IsInVirtualenv(%r) should be False" % p + + # "with virtualenv" + with SysPrefixes(_p('/virtualenv/prefix'), real_prefix=_p('/real/prefix')): + for p in [ _p(''), + _p('/real/prefix/foo'), + _p('/virtualenv/prefix'), + _p('/virtualenv/prefix/bar/..'), + _p('/virtualenv/prefix/bar/../../bleah'), + _p('/virtualenv/bleah') ]: + assert SCons.Platform.virtualenv.IsInVirtualenv(p) is False, "IsInVirtualenv(%r) should be False" % p + + # "with venv" + with SysPrefixes(_p('/virtualenv/prefix'), base_prefix=_p('/base/prefix')): + for p in [ _p(''), + _p('/base/prefix/foo'), + _p('/virtualenv/prefix'), + _p('/virtualenv/prefix/bar/..'), + _p('/virtualenv/prefix/bar/../../bleah'), + _p('/virtualenv/bleah') ]: + assert SCons.Platform.virtualenv.IsInVirtualenv(p) is False, "IsInVirtualenv(%r) should be False" % p + + def test_true(self): + # "with virtualenv" + with SysPrefixes(_p('/virtualenv/prefix'), real_prefix=_p('/real/prefix')): + for p in [ _p('/virtualenv/prefix/foo'), + _p('/virtualenv/prefix/foo/bar') ]: + assert SCons.Platform.virtualenv.IsInVirtualenv(p) is True, "IsInVirtualenv(%r) should be True" % p + + # "with venv" + with SysPrefixes(_p('/virtualenv/prefix'), base_prefix=_p('/base/prefix')): + for p in [ _p('/virtualenv/prefix/foo'), + _p('/virtualenv/prefix/foo/bar') ]: + assert SCons.Platform.virtualenv.IsInVirtualenv(p) is True, "IsInVirtualenv(%r) should be True" % p + +class _inject_venv_pathTestCase(unittest.TestCase): + def path_list(self): + return [ + _p('/virtualenv/prefix/bin'), + _p('/virtualenv/prefix'), + _p('/virtualenv/prefix/../bar'), + _p('/home/user/.local/bin'), + _p('/usr/bin'), + _p('/opt/bin') + ] + def test_with_path_string(self): + env = Environment() + path_string = os.path.pathsep.join(self.path_list()) + with SysPrefixes(_p('/virtualenv/prefix'), real_prefix=_p('/real/prefix')): + SCons.Platform.virtualenv._inject_venv_path(env, path_string) + assert env['ENV']['PATH'] == _p('/virtualenv/prefix/bin'), env['ENV']['PATH'] + + def test_with_path_list(self): + env = Environment() + with SysPrefixes(_p('/virtualenv/prefix'), real_prefix=_p('/real/prefix')): + SCons.Platform.virtualenv._inject_venv_path(env, self.path_list()) + assert env['ENV']['PATH'] == _p('/virtualenv/prefix/bin'), env['ENV']['PATH'] + +class VirtualenvTestCase(unittest.TestCase): + def test_none(self): + def _msg(given): + return "Virtualenv() should be None, not %s" % repr(given) + + with SysPrefixes(_p('/prefix')): + ve = SCons.Platform.virtualenv.Virtualenv() + assert ve is None , _msg(ve) + with SysPrefixes(_p('/base/prefix'), base_prefix=_p('/base/prefix')): + ve = SCons.Platform.virtualenv.Virtualenv() + assert ve is None, _msg(ve) + + def test_not_none(self): + def _msg(expected, given): + return "Virtualenv() should == %r, not %s" % (_p(expected), repr(given)) + + with SysPrefixes(_p('/virtualenv/prefix'), real_prefix=_p('/real/prefix')): + ve = SCons.Platform.virtualenv.Virtualenv() + assert ve == _p('/virtualenv/prefix'), _msg('/virtualenv/prefix', ve) + with SysPrefixes(_p('/same/prefix'), real_prefix=_p('/same/prefix')): + ve = SCons.Platform.virtualenv.Virtualenv() + assert ve == _p('/same/prefix'), _msg('/same/prefix', ve) + with SysPrefixes(_p('/virtualenv/prefix'), base_prefix=_p('/base/prefix')): + ve = SCons.Platform.virtualenv.Virtualenv() + assert ve == _p('/virtualenv/prefix'), _msg('/virtualenv/prefix', ve) + + +if __name__ == "__main__": + unittest.main() + + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/src/engine/SCons/Platform/win32.py b/src/engine/SCons/Platform/win32.py index 0cd8399..3b76208 100644 --- a/src/engine/SCons/Platform/win32.py +++ b/src/engine/SCons/Platform/win32.py @@ -39,8 +39,8 @@ import tempfile from SCons.Platform.posix import exitvalmap from SCons.Platform import TempFileMunge -from SCons.Platform.VE import ImportVirtualenv -from SCons.Platform.VE import ignore_virtualenv, enable_virtualenv +from SCons.Platform.virtualenv import ImportVirtualenv +from SCons.Platform.virtualenv import ignore_virtualenv, enable_virtualenv import SCons.Util try: diff --git a/src/engine/SCons/Script/Main.py b/src/engine/SCons/Script/Main.py index daa6be8..2c59808 100644 --- a/src/engine/SCons/Script/Main.py +++ b/src/engine/SCons/Script/Main.py @@ -59,7 +59,7 @@ import SCons.Job import SCons.Node import SCons.Node.FS import SCons.Platform -import SCons.Platform.VE +import SCons.Platform.virtualenv import SCons.SConf import SCons.Script import SCons.Taskmaster @@ -864,12 +864,12 @@ def _main(parser): for warning_type, message in delayed_warnings: SCons.Warnings.warn(warning_type, message) - if not SCons.Platform.VE.virtualenv_enabled_by_default: + if not SCons.Platform.virtualenv.virtualenv_enabled_by_default: if options.enable_virtualenv: - SCons.Platform.VE.enable_virtualenv = True + SCons.Platform.virtualenv.enable_virtualenv = True if options.ignore_virtualenv: - SCons.Platform.VE.ignore_virtualenv = True + SCons.Platform.virtualenv.ignore_virtualenv = True if options.diskcheck: SCons.Node.FS.set_diskcheck(options.diskcheck) diff --git a/src/engine/SCons/Script/SConsOptions.py b/src/engine/SCons/Script/SConsOptions.py index a18c6b9..37dd644 100644 --- a/src/engine/SCons/Script/SConsOptions.py +++ b/src/engine/SCons/Script/SConsOptions.py @@ -38,7 +38,7 @@ except ImportError: _ = gettext import SCons.Node.FS -import SCons.Platform.VE +import SCons.Platform.virtualenv import SCons.Warnings OptionValueError = optparse.OptionValueError @@ -707,7 +707,7 @@ def Parser(version): action="callback", callback=opt_duplicate, help=opt_duplicate_help) - if not SCons.Platform.VE.virtualenv_enabled_by_default: + if not SCons.Platform.virtualenv.virtualenv_enabled_by_default: op.add_option('--enable-virtualenv', dest="enable_virtualenv", action="store_true", diff --git a/src/engine/SCons/Script/__init__.py b/src/engine/SCons/Script/__init__.py index ee3a191..d602507 100644 --- a/src/engine/SCons/Script/__init__.py +++ b/src/engine/SCons/Script/__init__.py @@ -82,7 +82,7 @@ import SCons.Builder import SCons.Environment import SCons.Node.FS import SCons.Platform -import SCons.Platform.VE +import SCons.Platform.virtualenv import SCons.Scanner import SCons.SConf import SCons.Subst @@ -150,7 +150,7 @@ Environment = SCons.Environment.Environment #OptParser = SCons.SConsOptions.OptParser FindPathDirs = SCons.Scanner.FindPathDirs Platform = SCons.Platform.Platform -Virtualenv = SCons.Platform.VE.Virtualenv +Virtualenv = SCons.Platform.virtualenv.Virtualenv Return = _SConscript.Return Scanner = SCons.Scanner.Base Tool = SCons.Tool.Tool diff --git a/src/engine/SCons/Util.py b/src/engine/SCons/Util.py index 6643b72..4588955 100644 --- a/src/engine/SCons/Util.py +++ b/src/engine/SCons/Util.py @@ -1597,6 +1597,32 @@ def cmp(a, b): return (a > b) - (a < b) +def get_bool_envvar(name, default=False): + """ + Get a value of OS environment variable converting it to boolean. + + - FOO=1, FOO=123, FOO=true, FOO=yes, FOO=y, FOO=on are examples of ``True`` + values. + - FOO=0, FOO=false, FOO=no, FOO=n, FOO=off are examples of ``False`` + values. + + If a variable can't be converted to a boolean, default value is returned + (``False`` by default) + """ + try: + var = os.environ[name] + except KeyError: + return default + try: + return bool(int(var)) + except ValueError: + if str(var).lower() in ('true', 'yes', 'y', 'on'): + return True + elif str(var).lower() in ('false', 'no', 'n', 'off'): + return False + else: + return default + # Local Variables: # tab-width:4 # indent-tabs-mode:nil diff --git a/src/engine/SCons/UtilTests.py b/src/engine/SCons/UtilTests.py index 209c60f..6067c98 100644 --- a/src/engine/SCons/UtilTests.py +++ b/src/engine/SCons/UtilTests.py @@ -884,6 +884,64 @@ class flattenTestCase(unittest.TestCase): self.assertEqual(sorted(result),[1,2,3]) +class OsEnviron(object): + """Used to temporarily mock os.environ""" + def __init__(self, environ): + self._environ = environ + + def start(self): + self._stored = os.environ + os.environ = self._environ + + def stop(self): + os.environ = self._stored + del self._stored + + def __enter__(self): + self.start() + return os.environ + + def __exit__(self, *args): + self.stop() + + +class get_bool_envvarTestCase(unittest.TestCase): + def test_missing(self): + with OsEnviron(dict()): + var = get_bool_envvar('FOO') + assert var is False, "var should be False, not %s" % repr(var) + with OsEnviron({'FOO': '1'}): + var = get_bool_envvar('BAR') + assert var is False, "var should be False, not %s" % repr(var) + + def test_true(self): + for foo in [ 'TRUE', 'True', 'true', + 'YES', 'Yes', 'yes', + 'Y', 'y', + 'ON', 'On', 'on', + '1', '20', '-1']: + with OsEnviron({'FOO': foo}): + var = get_bool_envvar('FOO') + assert var is True, 'var should be True, not %s' % repr(var) + + def test_false(self): + for foo in [ 'FALSE', 'False', 'false', + 'NO', 'No', 'no', + 'N', 'n', + 'OFF', 'Off', 'off', + '0']: + with OsEnviron({'FOO': foo}): + var = get_bool_envvar('FOO', True) + assert var is False, 'var should be True, not %s' % repr(var) + + def test_default(self): + with OsEnviron({'FOO': 'other'}): + var = get_bool_envvar('FOO', True) + assert var is True, 'var should be True, not %s' % repr(var) + var = get_bool_envvar('FOO', False) + assert var is False, 'var should be False, not %s' % repr(var) + + if __name__ == "__main__": unittest.main() diff --git a/test/virtualenv/activated/option/enable-virtualenv.py b/test/virtualenv/activated/option/enable-virtualenv.py index dc3fa76..a5ceecc 100644 --- a/test/virtualenv/activated/option/enable-virtualenv.py +++ b/test/virtualenv/activated/option/enable-virtualenv.py @@ -29,25 +29,25 @@ Ensure that the --enable-virtualenv flag works. """ import TestSCons -import SCons.Platform.VE +import SCons.Platform.virtualenv import sys import os import re test = TestSCons.TestSCons() -if SCons.Platform.VE.virtualenv_enabled_by_default: +if SCons.Platform.virtualenv.virtualenv_enabled_by_default: test.skip_test("Virtualenv support enabled by default, the option --enable-virtualenv is unavailable, skipping\n") -if not SCons.Platform.VE.Virtualenv(): +if not SCons.Platform.virtualenv.Virtualenv(): test.skip_test("No virtualenv detected, skipping\n") -if not SCons.Platform.VE.select_paths_in_venv(os.getenv('PATH','')): +if not SCons.Platform.virtualenv.select_paths_in_venv(os.getenv('PATH','')): test.skip_test("Virtualenv detected but looks like unactivated, skipping\n") test.write('SConstruct', """ import sys -import SCons.Platform.VE +import SCons.Platform.virtualenv env = DefaultEnvironment(tools=[]) print("sys.executable: %r" % sys.executable) print("env.WhereIs('python'): %r" % env.WhereIs('python')) @@ -77,9 +77,9 @@ can't determine env.WhereIs('python') from stdout: python = eval(m.group('py')) -test.fail_test(not SCons.Platform.VE.IsInVirtualenv(interpreter), +test.fail_test(not SCons.Platform.virtualenv.IsInVirtualenv(interpreter), message="sys.executable points outside of virtualenv") -test.fail_test(not SCons.Platform.VE.IsInVirtualenv(python), +test.fail_test(not SCons.Platform.virtualenv.IsInVirtualenv(python), message="env.WhereIs('python') points to virtualenv") test.pass_test() diff --git a/test/virtualenv/activated/option/ignore-virtualenv.py b/test/virtualenv/activated/option/ignore-virtualenv.py index 05b462d..ac6f945 100644 --- a/test/virtualenv/activated/option/ignore-virtualenv.py +++ b/test/virtualenv/activated/option/ignore-virtualenv.py @@ -29,22 +29,22 @@ Ensure that the --ignore-virtualenv flag works. """ import TestSCons -import SCons.Platform.VE +import SCons.Platform.virtualenv import sys import os import re test = TestSCons.TestSCons() -if not SCons.Platform.VE.Virtualenv(): +if not SCons.Platform.virtualenv.Virtualenv(): test.skip_test("No virtualenv detected, skipping\n") -if not SCons.Platform.VE.select_paths_in_venv(os.getenv('PATH','')): +if not SCons.Platform.virtualenv.select_paths_in_venv(os.getenv('PATH','')): test.skip_test("Virtualenv detected but looks like unactivated, skipping\n") test.write('SConstruct', """ import sys -import SCons.Platform.VE +import SCons.Platform.virtualenv env = DefaultEnvironment(tools=[]) print("sys.executable: %s" % repr(sys.executable)) print("env.WhereIs('python'): %s" % repr(env.WhereIs('python'))) @@ -76,9 +76,9 @@ can't determine env.WhereIs('python') from stdout: python = eval(m.group('py')) -test.fail_test(not SCons.Platform.VE.IsInVirtualenv(interpreter), +test.fail_test(not SCons.Platform.virtualenv.IsInVirtualenv(interpreter), message="sys.executable points outside of virtualenv") -test.fail_test(SCons.Platform.VE.IsInVirtualenv(python), +test.fail_test(SCons.Platform.virtualenv.IsInVirtualenv(python), message="env.WhereIs('python') points to virtualenv") test.pass_test() diff --git a/test/virtualenv/activated/virtualenv_activated_python.py b/test/virtualenv/activated/virtualenv_activated_python.py index 3f591d6..c673ae1 100644 --- a/test/virtualenv/activated/virtualenv_activated_python.py +++ b/test/virtualenv/activated/virtualenv_activated_python.py @@ -32,17 +32,17 @@ environment or in unactivated virtualenv. """ import TestSCons -import SCons.Platform.VE +import SCons.Platform.virtualenv import sys import os import re test = TestSCons.TestSCons() -if not SCons.Platform.VE.Virtualenv(): +if not SCons.Platform.virtualenv.Virtualenv(): test.skip_test("No virtualenv detected, skipping\n") -if not SCons.Platform.VE.select_paths_in_venv(os.getenv('PATH')): +if not SCons.Platform.virtualenv.select_paths_in_venv(os.getenv('PATH')): test.skip_test("Virtualenv detected but looks like unactivated, skipping\n") @@ -53,7 +53,7 @@ print("sys.executable: %s" % repr(sys.executable)) print("env.WhereIs('python'): %s" % repr(env.WhereIs('python'))) """) -if SCons.Platform.VE.virtualenv_enabled_by_default: +if SCons.Platform.virtualenv.virtualenv_enabled_by_default: test.run(['-Q']) else: test.run(['-Q', '--enable-virtualenv']) @@ -82,9 +82,9 @@ can't determine env.WhereIs('python') from stdout: python = eval(m.group('py')) # runing in activated virtualenv (after "activate") - PATH includes virtualenv's bin directory -test.fail_test(not SCons.Platform.VE.IsInVirtualenv(interpreter), +test.fail_test(not SCons.Platform.virtualenv.IsInVirtualenv(interpreter), message="sys.executable points outside of virtualenv") -test.fail_test(not SCons.Platform.VE.IsInVirtualenv(python), +test.fail_test(not SCons.Platform.virtualenv.IsInVirtualenv(python), message="env.WhereIs('python') points outside of virtualenv") test.pass_test() diff --git a/test/virtualenv/activated/virtualenv_detect_virtualenv.py b/test/virtualenv/activated/virtualenv_detect_virtualenv.py index 0eba385..2c00793 100644 --- a/test/virtualenv/activated/virtualenv_detect_virtualenv.py +++ b/test/virtualenv/activated/virtualenv_detect_virtualenv.py @@ -25,16 +25,16 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" """ -Check if SCons.Platform.VE.Virtualenv() works in SConscripts. +Check if SCons.Platform.virtualenv.Virtualenv() works in SConscripts. """ import TestSCons -import SCons.Platform.VE +import SCons.Platform.virtualenv import sys test = TestSCons.TestSCons() -ve = SCons.Platform.VE.Virtualenv() +ve = SCons.Platform.virtualenv.Virtualenv() if not ve: test.skip_test("Virtualenv is not active, skipping\n") @@ -42,7 +42,7 @@ test.write('SConstruct', """ print("virtualenv: %r" % Virtualenv()) """) -if SCons.Platform.VE.virtualenv_enabled_by_default: +if SCons.Platform.virtualenv.virtualenv_enabled_by_default: test.run(['-Q']) else: test.run(['-Q', '--enable-virtualenv']) diff --git a/test/virtualenv/always/virtualenv_global_function.py b/test/virtualenv/always/virtualenv_global_function.py index 18f93f8..8f2c291 100644 --- a/test/virtualenv/always/virtualenv_global_function.py +++ b/test/virtualenv/always/virtualenv_global_function.py @@ -31,7 +31,7 @@ contains the virtualenv's bin path). """ import TestSCons -import SCons.Platform.VE +import SCons.Platform.virtualenv import re test = TestSCons.TestSCons() @@ -53,7 +53,7 @@ can't determine Virtualenv() result from stdout: """ % s) scons_ve = m.group('ve') -our_ve = "%r" % SCons.Platform.VE.Virtualenv() +our_ve = "%r" % SCons.Platform.virtualenv.Virtualenv() # runing in activated virtualenv (after "activate") - PATH includes virtualenv's bin directory test.fail_test(scons_ve != our_ve, diff --git a/test/virtualenv/regularenv/virtualenv_detect_regularenv.py b/test/virtualenv/regularenv/virtualenv_detect_regularenv.py index e5dbc61..57a0d4f 100644 --- a/test/virtualenv/regularenv/virtualenv_detect_regularenv.py +++ b/test/virtualenv/regularenv/virtualenv_detect_regularenv.py @@ -25,23 +25,23 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" """ -Check if SCons.Platform.VE.Virtualenv() works in SConscript. +Check if SCons.Platform.virtualenv.Virtualenv() works in SConscript. """ import TestSCons -import SCons.Platform.VE +import SCons.Platform.virtualenv import sys test = TestSCons.TestSCons() -if SCons.Platform.VE.Virtualenv(): +if SCons.Platform.virtualenv.Virtualenv(): test.skip_test("Virtualenv is active, skipping\n") test.write('SConstruct', """ print("virtualenv: %r" % Virtualenv()) """) -if SCons.Platform.VE.virtualenv_enabled_by_default: +if SCons.Platform.virtualenv.virtualenv_enabled_by_default: test.run(['-Q']) else: test.run(['-Q', '--enable-virtualenv']) diff --git a/test/virtualenv/unactivated/virtualenv_unactivated_python.py b/test/virtualenv/unactivated/virtualenv_unactivated_python.py index a087318..a4dc240 100644 --- a/test/virtualenv/unactivated/virtualenv_unactivated_python.py +++ b/test/virtualenv/unactivated/virtualenv_unactivated_python.py @@ -32,17 +32,17 @@ a regular environment or in an activated virtualenv. """ import TestSCons -import SCons.Platform.VE +import SCons.Platform.virtualenv import sys import os import re test = TestSCons.TestSCons() -if not SCons.Platform.VE.Virtualenv(): +if not SCons.Platform.virtualenv.Virtualenv(): test.skip_test("No virtualenv detected, skipping\n") -if SCons.Platform.VE.select_paths_in_venv(os.getenv('PATH')): +if SCons.Platform.virtualenv.select_paths_in_venv(os.getenv('PATH')): test.skip_test("Virtualenv detected and it looks like activated, skipping\n") test.write('SConstruct', """ @@ -52,7 +52,7 @@ print("sys.executable: %s" % repr(sys.executable)) print("env.WhereIs('python'): %s" % repr(env.WhereIs('python'))) """) -if SCons.Platform.VE.virtualenv_enabled_by_default: +if SCons.Platform.virtualenv.virtualenv_enabled_by_default: test.run(['-Q']) else: test.run(['-Q', '--enable-virtualenv']) @@ -81,9 +81,9 @@ can't determine env.WhereIs('python') from stdout: python = eval(m.group('py')) # running without activating virtualenv (by just /path/to/virtualenv/bin/python runtest.py ...). -test.fail_test(not SCons.Platform.VE.IsInVirtualenv(interpreter), +test.fail_test(not SCons.Platform.virtualenv.IsInVirtualenv(interpreter), message="sys.executable points outside of virtualenv") -test.fail_test(SCons.Platform.VE.IsInVirtualenv(python), +test.fail_test(SCons.Platform.virtualenv.IsInVirtualenv(python), message="env.WhereIs('python') points to virtualenv") test.pass_test() -- cgit v0.12