MCPcopy Create free account
hub / github.com/aboutcode-org/scancode-toolkit / get_env

Function get_env

src/commoncode/command.py:157–181  ·  view source on GitHub ↗

Return a dictionary of environment variables for command execution with appropriate DY/LD_LIBRARY_PATH path variables. Use the optional `base_vars` environment variables dictionary as a base if provided. Note: if `base_vars` contains DY/LD_LIBRARY_PATH variables these will be overwr

(base_vars=None, lib_dir=None)

Source from the content-addressed store, hash-verified

155
156
157def get_env(base_vars=None, lib_dir=None):
158 """
159 Return a dictionary of environment variables for command execution with
160 appropriate DY/LD_LIBRARY_PATH path variables. Use the optional `base_vars`
161 environment variables dictionary as a base if provided. Note: if `base_vars`
162 contains DY/LD_LIBRARY_PATH variables these will be overwritten. On POSIX,
163 add `lib_dir` as DY/LD_LIBRARY_PATH-like path if provided.
164 """
165 env_vars = {}
166 if base_vars:
167 env_vars.update(base_vars)
168
169 # Create and add LD environment variables
170 if lib_dir and on_posix:
171 new_path = f"{lib_dir}"
172 # on Linux/posix
173 ld_lib_path = os.environ.get(LD_LIBRARY_PATH)
174 env_vars.update({LD_LIBRARY_PATH: update_path_var(ld_lib_path, new_path)})
175 # on Mac, though LD_LIBRARY_PATH should work too
176 dyld_lib_path = os.environ.get(DYLD_LIBRARY_PATH)
177 env_vars.update({DYLD_LIBRARY_PATH: update_path_var(dyld_lib_path, new_path)})
178
179 env_vars = {text.as_unicode(k): text.as_unicode(v) for k, v in env_vars.items()}
180
181 return env_vars
182
183
184def close(proc):

Callers 1

executeFunction · 0.85

Calls 3

update_path_varFunction · 0.85
getMethod · 0.65
updateMethod · 0.45

Tested by

no test coverage detected