def list_envs(ctx, param, value): if not value or ctx.resilient_parsing: return venvs = get_available_venvs() if venvs: echo_success('Virtual environments found in `{}`:\n'.format( get_venv_dir())) for venv_name, venv_dir in venvs: with venv(venv_dir): echo_success('{} ->'.format(venv_name)) if value == 1: echo_info(' Version: {}'.format(get_python_version())) elif value == 2: echo_info(' Version: {}'.format(get_python_version())) echo_info(' Implementation: {}'.format( get_python_implementation())) else: echo_info(' Version: {}'.format(get_python_version())) echo_info(' Implementation: {}'.format( get_python_implementation())) echo_info(' Local packages: {}'.format(', '.join( sorted(get_editable_packages())))) # I don't want to move users' virtual environments # temporarily for tests as one may be in use. else: # no cov echo_failure('No virtual environments found in `{}`. To create ' 'one do `hatch env NAME`.'.format(get_venv_dir())) ctx.exit()
def list_envs(ctx, param, value): if not value or ctx.resilient_parsing: return venvs = get_available_venvs() if venvs: click.echo('Virtual environments found in `{}`:\n'.format(VENV_DIR)) for venv_name, venv_dir in venvs: with venv(venv_dir): click.echo( '{} ->\n' ' Version: {}\n' ' Implementation: {}'.format( venv_name, get_python_version(), get_python_implementation() ) ) # I don't want to move users' virtual environments # temporarily for tests as one may be in use. else: # no cov click.echo('No virtual environments found in `{}`. To create ' 'one do `hatch env NAME`.'.format(VENV_DIR)) ctx.exit()
def test_list_success(): with temp_chdir(): runner = CliRunner() env_name1 = os.urandom(10).hex() while os.path.exists(os.path.join(VENV_DIR, env_name1)): # no cov env_name1 = os.urandom(10).hex() env_name2 = '' try: runner.invoke(hatch, ['env', env_name1]) env_name2 = os.urandom(10).hex() while os.path.exists(os.path.join(VENV_DIR, env_name2)): # no cov env_name2 = os.urandom(10).hex() os.makedirs(os.path.join(VENV_DIR, env_name2)) result = runner.invoke(hatch, ['env', '-l']) finally: remove_path(os.path.join(VENV_DIR, env_name1)) remove_path(os.path.join(VENV_DIR, env_name2)) assert result.exit_code == 0 assert ('{} ->\n' ' Version: {}\n' ' Implementation: {}'.format( env_name1, get_python_version(), get_python_implementation())) in result.output
def test_all_packages_none(): with temp_chdir() as d: venv_dir = os.path.join(d, 'venv') create_venv(venv_dir) with venv(venv_dir): runner = CliRunner() result = runner.invoke(hatch, ['update', '-nd', '--all']) if get_python_implementation() in {'PyPy'}: # no cov assert result.exit_code == 0 else: assert result.exit_code == 1 assert 'No packages installed.' in result.output
def test_list_success_2(): with temp_chdir(): runner = CliRunner() env_name = get_new_venv_name() try: runner.invoke(hatch, ['env', env_name]) result = runner.invoke(hatch, ['env', '-ll']) finally: remove_path(os.path.join(VENV_DIR, env_name)) assert result.exit_code == 0 assert ('{} ->\n' ' Version: {}\n' ' Implementation: {}'.format( env_name, get_python_version(), get_python_implementation())) in result.output
def test_list_success_3(): with temp_chdir(): runner = CliRunner() runner.invoke(hatch, ['init', 'ok', '-ne']) env_name = get_new_venv_name() venv_dir = os.path.join(get_venv_dir(), env_name) try: runner.invoke(hatch, ['env', env_name]) wait_until(is_venv, venv_dir) runner.invoke(hatch, ['install', '-l', '-e', env_name]) result = runner.invoke(hatch, ['env', '-lll']) finally: remove_path(os.path.join(get_venv_dir(), env_name)) assert result.exit_code == 0 assert ('{} ->\n' ' Version: {}\n' ' Implementation: {}\n' ' Local packages: {}'.format(env_name, get_python_version(), get_python_implementation(), 'ok')) in result.output
def test_list_success_3(): with temp_chdir(): runner = CliRunner() runner.invoke(hatch, ['init', 'ok']) env_name = os.urandom(10).hex() while os.path.exists(os.path.join(VENV_DIR, env_name)): # no cov env_name = os.urandom(10).hex() try: runner.invoke(hatch, ['env', env_name]) runner.invoke(hatch, ['install', '-l', '-e', env_name]) result = runner.invoke(hatch, ['env', '-lll']) finally: remove_path(os.path.join(VENV_DIR, env_name)) assert result.exit_code == 0 assert ('{} ->\n' ' Version: {}\n' ' Implementation: {}\n' ' Local packages: {}'.format(env_name, get_python_version(), get_python_implementation(), 'ok')) in result.output