コード例 #1
0
ファイル: env.py プロジェクト: cs4construction/hatch-1
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()
コード例 #2
0
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()
コード例 #3
0
ファイル: test_env.py プロジェクト: vermuz/hatch
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
コード例 #4
0
ファイル: test_init.py プロジェクト: peblair/hatch
def test_pyname():
    with temp_chdir() as d:
        runner = CliRunner()

        env_name = get_new_venv_name()
        venv_dir = os.path.join(VENV_DIR, env_name)

        try:
            with temp_move_path(SETTINGS_FILE, d):
                settings = copy_default_settings()
                settings['pypaths']['python'] = sys.executable
                save_settings(settings)
                result = runner.invoke(hatch, ['init', 'ok', '-py', 'python'])
                venv_dir = os.path.join(d, 'venv')
                global_version = get_python_version()
                wait_until(is_venv, venv_dir)
                with venv(venv_dir):
                    assert get_python_version() == global_version
        finally:
            remove_path(venv_dir)

        assert result.exit_code == 0
コード例 #5
0
ファイル: test_env.py プロジェクト: dot-Sean/hatch
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
コード例 #6
0
ファイル: test_env.py プロジェクト: dot-Sean/hatch
def test_list_success_1():
    with temp_chdir():
        runner = CliRunner()

        env_name1, env_name2 = get_new_venv_name(count=2)
        venv_dir1 = os.path.join(VENV_DIR, env_name1)
        venv_dir2 = os.path.join(VENV_DIR, env_name2)

        try:
            runner.invoke(hatch, ['env', env_name1])
            os.makedirs(venv_dir2)
            result = runner.invoke(hatch, ['env', '-l'])
        finally:
            remove_path(venv_dir1)
            remove_path(venv_dir2)

        assert result.exit_code == 0
        assert ('{} ->\n'
                '  Version: {}'.format(env_name1,
                                       get_python_version())) in result.output
コード例 #7
0
ファイル: test_env.py プロジェクト: yaowenqiang/hatch
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
コード例 #8
0
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