def get_env_patch(venv): # pragma: windows no cover if sys.platform == 'cygwin': # pragma: no cover _, win_venv, _ = cmd_output('cygpath', '-w', venv) install_prefix = r'{}\bin'.format(win_venv.strip()) elif sys.platform == 'win32': # pragma: no cover install_prefix = bin_dir(venv) else: # pragma: windows no cover install_prefix = venv return ( ('NODE_VIRTUAL_ENV', venv), ('NPM_CONFIG_PREFIX', install_prefix), ('npm_config_prefix', install_prefix), ('NODE_PATH', os.path.join(venv, 'lib', 'node_modules')), ('PATH', (bin_dir(venv), os.pathsep, Var('PATH'))), )
def get_env_patch(venv): if sys.platform == 'cygwin': # pragma: no cover _, win_venv, _ = cmd_output('cygpath', '-w', venv) install_prefix = r'{}\bin'.format(win_venv.strip()) elif sys.platform == 'win32': # pragma: no cover install_prefix = bin_dir(venv) else: install_prefix = venv return ( ('NODE_VIRTUAL_ENV', venv), ('NPM_CONFIG_PREFIX', install_prefix), ('npm_config_prefix', install_prefix), ('NODE_PATH', os.path.join(venv, 'lib', 'node_modules')), ('PATH', (bin_dir(venv), os.pathsep, Var('PATH'))), )
def test_unhealthy_then_replaced(python_dir): prefix, tmpdir = python_dir python.install_environment(prefix, C.DEFAULT, ()) # simulate an exe which returns an old version exe_name = win_exe('python') py_exe = prefix.path(python.bin_dir('py_env-default'), exe_name) os.rename(py_exe, f'{py_exe}.tmp') with open(py_exe, 'w') as f: f.write('#!/usr/bin/env bash\necho 1.2.3\n') make_executable(py_exe) # should be unhealthy due to version mismatch ret = python.health_check(prefix, C.DEFAULT) assert ret == ( f'virtualenv python version did not match created version:\n' f'- actual version: 1.2.3\n' f'- expected version: {python._version_info(sys.executable)}\n') # now put the exe back and it should be healthy again os.replace(f'{py_exe}.tmp', py_exe) assert python.health_check(prefix, C.DEFAULT) is None
def get_env_patch(venv: str) -> PatchesT: if sys.platform == 'cygwin': # pragma: no cover _, win_venv, _ = cmd_output('cygpath', '-w', venv) install_prefix = fr'{win_venv.strip()}\bin' lib_dir = 'lib' elif sys.platform == 'win32': # pragma: no cover install_prefix = bin_dir(venv) lib_dir = 'Scripts' else: # pragma: win32 no cover install_prefix = venv lib_dir = 'lib' return ( ('NODE_VIRTUAL_ENV', venv), ('NPM_CONFIG_PREFIX', install_prefix), ('npm_config_prefix', install_prefix), ('NODE_PATH', os.path.join(venv, lib_dir, 'node_modules')), ('PATH', (bin_dir(venv), os.pathsep, Var('PATH'))), )
def get_env_patch(venv: str) -> PatchesT: if sys.platform == "cygwin": # pragma: no cover _, win_venv, _ = cmd_output("cygpath", "-w", venv) install_prefix = fr"{win_venv.strip()}\bin" lib_dir = "lib" elif sys.platform == "win32": # pragma: no cover install_prefix = bin_dir(venv) lib_dir = "Scripts" else: # pragma: win32 no cover install_prefix = venv lib_dir = "lib" return ( ("NODE_VIRTUAL_ENV", venv), ("NPM_CONFIG_PREFIX", install_prefix), ("npm_config_prefix", install_prefix), ("NODE_PATH", os.path.join(venv, lib_dir, "node_modules")), ("PATH", (bin_dir(venv), os.pathsep, Var("PATH"))), )
def test_unhealthy_python_goes_missing(python_dir): prefix, tmpdir = python_dir python.install_environment(prefix, C.DEFAULT, ()) exe_name = 'python' if sys.platform != 'win32' else 'python.exe' py_exe = prefix.path(python.bin_dir('py_env-default'), exe_name) os.remove(py_exe) assert python.healthy(prefix, C.DEFAULT) is False
def test_unhealthy_python_goes_missing(python_dir): prefix, tmpdir = python_dir python.install_environment(prefix, C.DEFAULT, ()) exe_name = win_exe('python') py_exe = prefix.path(python.bin_dir('py_env-default'), exe_name) os.remove(py_exe) ret = python.health_check(prefix, C.DEFAULT) assert ret == ( f'virtualenv python version did not match created version:\n' f'- actual version: <<error retrieving version from {py_exe}>>\n' f'- expected version: {python._version_info(sys.executable)}\n')
def test_unhealthy_then_replaced(python_dir): prefix, tmpdir = python_dir python.install_environment(prefix, C.DEFAULT, ()) # simulate an exe which returns an old version exe_name = 'python.exe' if sys.platform == 'win32' else 'python' py_exe = prefix.path(python.bin_dir('py_env-default'), exe_name) os.rename(py_exe, f'{py_exe}.tmp') with open(py_exe, 'w') as f: f.write('#!/usr/bin/env bash\necho 1.2.3\n') make_executable(py_exe) # should be unhealthy due to version mismatch assert python.healthy(prefix, C.DEFAULT) is False # now put the exe back and it should be healthy again os.replace(f'{py_exe}.tmp', py_exe) assert python.healthy(prefix, C.DEFAULT) is True