def health_check(prefix: Prefix, language_version: str) -> str | None: directory = helpers.environment_dir(ENVIRONMENT_DIR, language_version) envdir = prefix.path(directory) pyvenv_cfg = os.path.join(envdir, 'pyvenv.cfg') # created with "old" virtualenv if not os.path.exists(pyvenv_cfg): return 'pyvenv.cfg does not exist (old virtualenv?)' exe_name = win_exe('python') py_exe = prefix.path(bin_dir(envdir), exe_name) cfg = _read_pyvenv_cfg(pyvenv_cfg) if 'version_info' not in cfg: return "created virtualenv's pyvenv.cfg is missing `version_info`" # always use uncached lookup here in case we replaced an unhealthy env virtualenv_version = _version_info.__wrapped__(py_exe) if virtualenv_version != cfg['version_info']: return (f'virtualenv python version did not match created version:\n' f'- actual version: {virtualenv_version}\n' f'- expected version: {cfg["version_info"]}\n') # made with an older version of virtualenv? skip `base-executable` check if 'base-executable' not in cfg: return None base_exe_version = _version_info(cfg['base-executable']) if base_exe_version != cfg['version_info']: return ( f'base executable python version does not match created version:\n' f'- base-executable version: {base_exe_version}\n' f'- expected version: {cfg["version_info"]}\n') else: return None
def test_install_rbenv_with_version(tempdir_factory): prefix = Prefix(tempdir_factory.get()) _install_rbenv(prefix, version='1.9.3p547') # Should be able to activate and use rbenv install cmd_output( 'bash', '-c', '. {} && rbenv install --help'.format( pipes.quote(prefix.path('rbenv-1.9.3p547', 'bin', 'activate')), ), )
def test_install_rbenv(tempdir_factory): prefix = Prefix(tempdir_factory.get()) _install_rbenv(prefix) # Should have created rbenv directory assert os.path.exists(prefix.path('rbenv-default')) # We should have created our `activate` script activate_path = prefix.path('rbenv-default', 'bin', 'activate') assert os.path.exists(activate_path) # Should be able to activate using our script and access rbenv cmd_output( 'bash', '-c', '. {} && rbenv --help'.format( pipes.quote(prefix.path('rbenv-default', 'bin', 'activate')), ), )
def test_path_multiple_args(): instance = Prefix('foo') ret = instance.path('bar', 'baz') assert ret == os.path.join('foo', 'bar', 'baz')
def test_path(prefix, path_end, expected_output): instance = Prefix(prefix) ret = instance.path(path_end) assert ret == expected_output