1 """SCons.Platform.virtualenv
2
3 Support for virtualenv.
4 """
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 __revision__ = "src/engine/SCons/Platform/virtualenv.py 3a41ed6b288cee8d085373ad7fa02894e1903864 2019-01-23 17:30:35 bdeegan"
30
31 import os
32 import sys
33 import SCons.Util
34
35
36 virtualenv_enabled_by_default = False
37
38
41
42
44 return SCons.Util.get_os_env_bool('SCONS_IGNORE_VIRTUALENV', False)
45
46
47 enable_virtualenv = _enable_virtualenv_default()
48 ignore_virtualenv = _ignore_virtualenv_default()
49 virtualenv_variables = ['VIRTUAL_ENV', 'PIPENV_ACTIVE']
50
51
53 """Returns True, if scons is executed within a virtualenv"""
54
55 return (hasattr(sys, 'real_prefix') or
56 (hasattr(sys, 'base_prefix') and sys.base_prefix != sys.prefix))
57
58
60 """Returns true, if **path** is located under the **base** directory."""
61 if not path or not base:
62 return False
63 rp = os.path.relpath(path, base)
64 return ((not rp.startswith(os.path.pardir)) and (not rp == os.path.curdir))
65
66
76
78 """Modify environment such that SCons will take into account its virtualenv
79 when running external tools."""
80 if path_list is None:
81 path_list = os.getenv('PATH')
82 env.PrependENVPath('PATH', select_paths_in_venv(path_list))
83
84
86 """Returns a list of paths from **path_list** which are under virtualenv's
87 home directory."""
88 if SCons.Util.is_String(path_list):
89 path_list = path_list.split(os.path.pathsep)
90
91 return [path for path in path_list if IsInVirtualenv(path)]
92
93
100
101
103 """Returns path to the virtualenv home if scons is executing within a
104 virtualenv or None, if not."""
105 if _running_in_virtualenv():
106 return sys.prefix
107 return None
108
109
111 """Returns True, if **path** is under virtualenv's home directory. If not,
112 or if we don't use virtualenv, returns False."""
113 return _is_path_in(path, Virtualenv())
114
115
116
117
118
119
120
121