コード例 #1
0
ファイル: test_install.py プロジェクト: Oofsterer/hatch-1
def test_local_none():
    with temp_chdir() as d:
        runner = CliRunner()
        venv_dir = os.path.join(d, 'venv')
        create_venv(venv_dir)

        with venv(venv_dir):
            result = runner.invoke(hatch, ['install', '-nd'])

        assert result.exit_code != 0
コード例 #2
0
def test_env():
    with temp_chdir():
        runner = CliRunner()

        env_name = get_new_venv_name()
        venv_dir = os.path.join(get_venv_dir(), env_name)
        create_venv(venv_dir)

        try:
            runner.invoke(hatch, ['install', '-e', env_name, 'six'])
            with venv(venv_dir):
                assert 'six' in get_installed_packages()
            result = runner.invoke(hatch, ['uninstall', '-nd', '-y', '-e', env_name, 'six'])
            with venv(venv_dir):
                assert 'six' not in get_installed_packages()
        finally:
            remove_path(venv_dir)

        assert result.exit_code == 0
コード例 #3
0
ファイル: test_venv.py プロジェクト: awesome-python/hatch
def test_venv():
    with temp_chdir() as d:
        d = os.path.join(d, 'test_env')
        create_venv(d)
        global_python = get_python_path()

        with venv(d):
            venv_python = get_python_path()

        assert global_python != venv_python
        assert global_python == get_python_path()
コード例 #4
0
def test_package_not_exist():
    with temp_chdir() as d:
        runner = CliRunner()
        venv_dir = os.path.join(d, 'venv')
        create_venv(venv_dir)

        with venv(venv_dir, evars=ENV_VARS):
            result = runner.invoke(hatch, ['release', PACKAGE_NAME, '-u', USERNAME, '-t'])

        assert result.exit_code == 1
        assert '`{}` is not an editable package.'.format(PACKAGE_NAME) in result.output
コード例 #5
0
ファイル: test_uninstall.py プロジェクト: peblair/hatch
def test_requirements_none():
    with temp_chdir() as d:
        runner = CliRunner()
        venv_dir = os.path.join(d, 'venv')
        create_venv(venv_dir)

        with venv(venv_dir):
            result = runner.invoke(hatch, ['uninstall', '-nd', '-y'])

        assert result.exit_code == 1
        assert 'Unable to locate a requirements file.' in result.output
コード例 #6
0
def test_env():
    with temp_chdir():
        runner = CliRunner()

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

        try:
            with venv(venv_dir):
                install_packages(['requests==2.17.3'])
                initial_version = get_version_as_bytes('requests')
            result = runner.invoke(hatch, ['update', '-e', env_name, '--all'])
            with venv(venv_dir):
                final_version = get_version_as_bytes('requests')
        finally:
            remove_path(venv_dir)

        assert result.exit_code == 0
        assert initial_version < final_version
コード例 #7
0
ファイル: test_build.py プロジェクト: vermuz/hatch
def test_package_not_exist():
    with temp_chdir() as d:
        runner = CliRunner()
        venv_dir = os.path.join(d, 'venv')
        create_venv(venv_dir)

        with venv(venv_dir):
            result = runner.invoke(hatch, ['build', 'ok'])

        assert result.exit_code == 1
        assert '`{}` is not an editable package.'.format('ok') in result.output
コード例 #8
0
def test_local_not_exist():
    with temp_chdir() as d:
        runner = CliRunner()
        venv_dir = os.path.join(d, 'venv')
        create_venv(venv_dir)

        with venv(venv_dir):
            result = runner.invoke(hatch, ['release', '-l'])

        assert result.exit_code == 1
        assert 'There are no local packages available.' in result.output
コード例 #9
0
def test_packages():
    with temp_chdir() as d:
        runner = CliRunner()
        venv_dir = os.path.join(d, 'venv')
        create_venv(venv_dir)

        with venv(venv_dir):
            assert 'six' not in get_installed_packages()
            result = runner.invoke(hatch, ['install', 'six'])
            assert 'six' in get_installed_packages()

        assert result.exit_code == 0
コード例 #10
0
def test_env():
    with temp_chdir():
        runner = CliRunner()

        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()

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

        try:
            with venv(venv_dir):
                assert 'six' not in get_installed_packages()
            result = runner.invoke(hatch, ['install', '-e', env_name, 'six'])
            with venv(venv_dir):
                assert 'six' in get_installed_packages()
        finally:
            remove_path(venv_dir)

        assert result.exit_code == 0
コード例 #11
0
def test_infra_env():
    with temp_chdir():
        runner = CliRunner()

        env_name = get_new_venv_name()
        venv_dir = os.path.join(get_venv_dir(), env_name)
        create_venv(venv_dir)

        try:
            with venv(venv_dir):
                install_packages(['setuptools==36.0.1'])
                initial_version = get_version_as_bytes('setuptools')
            result = runner.invoke(hatch,
                                   ['update', '-e', env_name, '--infra'])
            with venv(venv_dir):
                final_version = get_version_as_bytes('setuptools')
        finally:
            remove_path(venv_dir)

        assert result.exit_code == 0
        assert initial_version < final_version
コード例 #12
0
def uninstall(packages, env_name, global_uninstall, dev, quiet, yes):
    """If the option --env is supplied, the uninstall will be applied using
    that named virtual env. Unless the option --global is selected, the
    uninstall will only affect the current user. Of course, this will have
    no effect if a virtual env is in use. The desired name of the admin
    user can be set with the `_DEFAULT_ADMIN_` environment variable.

    With no packages selected, this will uninstall using a `requirements.txt`
    or a dev version of that in the current directory.
    """
    if not packages:
        reqs = get_requirements_file(os.getcwd(), dev=dev)
        if not reqs:
            click.echo('Unable to locate a requirements file.')
            sys.exit(1)

        packages = ['-r', reqs]

    # Windows' `runas` allows only a single argument for the
    # command so we catch this case and turn our command into
    # a string later.
    windows_admin_command = None

    if yes:  # no cov
        packages = ['-y', *packages]

    if env_name:
        venv_dir = os.path.join(VENV_DIR, env_name)
        if not os.path.exists(venv_dir):
            click.echo('Virtual env named `{}` does not exist.'.format(env_name))
            sys.exit(1)

        with venv(venv_dir):
            command = [get_proper_pip(), 'uninstall', *packages] + (['-q'] if quiet else [])
            result = subprocess.run(command, shell=NEED_SUBPROCESS_SHELL)
    else:
        command = [get_proper_pip(), 'uninstall'] + (['-q'] if quiet else [])

        if not venv_active() and global_uninstall:  # no cov
            if ON_WINDOWS:
                windows_admin_command = get_admin_command()
            else:
                command = get_admin_command() + command

        command.extend(packages)

        if windows_admin_command:  # no cov
            command = windows_admin_command + [' '.join(command)]

        result = subprocess.run(command, shell=NEED_SUBPROCESS_SHELL)

    sys.exit(result.returncode)
コード例 #13
0
def test_get_editable_package_location():
    with temp_chdir() as d:
        runner = CliRunner()
        runner.invoke(hatch, ['new', 'foo', '--basic', '-ne'])
        runner.invoke(hatch, ['new', 'bar', '--basic', '-ne'])

        venv_dir = os.path.join(d, 'venv')
        create_venv(venv_dir)

        with venv(venv_dir):
            install_packages(['-e', os.path.join(d, 'foo')])
            install_packages(['-e', os.path.join(d, 'bar')])
            assert get_editable_package_location('foo') == os.path.join(d, 'foo')
コード例 #14
0
ファイル: test_init.py プロジェクト: peblair/hatch
def test_env():
    with temp_chdir() as d:
        runner = CliRunner()
        result = runner.invoke(hatch, ['init', 'new-project', '--basic'])
        venv_dir = os.path.join(d, 'venv')
        wait_until(is_venv, venv_dir)

        with venv(venv_dir):
            assert 'new-project' in get_editable_packages()

        assert result.exit_code == 0
        assert 'Creating its own virtual env... complete!' in result.output
        assert 'Installing locally in the virtual env... complete!' in result.output
コード例 #15
0
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
コード例 #16
0
def test_infra():
    with temp_chdir() as d:
        runner = CliRunner()
        venv_dir = os.path.join(d, 'venv')
        create_venv(venv_dir)

        with venv(venv_dir):
            install_packages(['setuptools==36.0.1'])
            initial_version = get_version_as_bytes('setuptools')
            result = runner.invoke(hatch, ['update', '-nd', '--infra'])
            final_version = get_version_as_bytes('setuptools')

        assert result.exit_code == 0
        assert initial_version < final_version
コード例 #17
0
def test_local_editable():
    with temp_chdir() as d:
        runner = CliRunner()
        runner.invoke(hatch, ['init', 'ok'])

        venv_dir = os.path.join(d, 'venv')
        create_venv(venv_dir)

        with venv(venv_dir):
            assert 'ok' not in get_editable_packages()
            result = runner.invoke(hatch, ['install', '-l'])
            assert 'ok' in get_editable_packages()

        assert result.exit_code == 0
コード例 #18
0
def test_get_installed_packages_no_editable():
    with temp_chdir() as d:
        runner = CliRunner()
        runner.invoke(hatch, ['init', 'ok', '--basic', '-ne'])

        venv_dir = os.path.join(d, 'venv')
        create_venv(venv_dir)

        with venv(venv_dir):
            install_packages(['six'])
            install_packages(['-e', '.'])
            packages = get_installed_packages(editable=False)
            assert 'six' in packages
            assert 'ok' not in packages
コード例 #19
0
def test_all_packages():
    with temp_chdir() as d:
        venv_dir = os.path.join(d, 'venv')
        create_venv(venv_dir)

        with venv(venv_dir):
            install_packages(['requests==2.17.3'])
            initial_version = get_version_as_bytes('requests')
            runner = CliRunner()
            result = runner.invoke(hatch, ['update', '-nd', '--all'])
            final_version = get_version_as_bytes('requests')

        assert result.exit_code == 0
        assert initial_version < final_version
コード例 #20
0
ファイル: test_release.py プロジェクト: Oofsterer/hatch-1
def test_repository_and_test():
    with temp_chdir() as d:
        runner = CliRunner()
        runner.invoke(hatch, ['new', PACKAGE_NAME, '--basic', '-ne'])
        runner.invoke(hatch, ['build', '-p', PACKAGE_NAME])
        package_dir = os.path.join(d, PACKAGE_NAME)

        venv_dir = os.path.join(d, 'venv')
        create_venv(venv_dir)

        with venv(venv_dir, evars=ENV_VARS):
            install_packages(['-e', package_dir])
            result = runner.invoke(
                hatch,
                ['release', '-l', '-u', USERNAME, '-r', TEST_REPOSITORY, '-t'])

        assert result.exit_code == 1
        assert "Cannot specify both --test and --repo." in result.output

        with venv(venv_dir, evars=ENV_VARS):
            result = runner.invoke(hatch, [
                'release', '-l', '-u', USERNAME, '--repo-url', TEST_REPOSITORY,
                '-t'
            ])

        assert result.exit_code == 1
        assert "Cannot specify both --test and --repo-url." in result.output

        with venv(venv_dir, evars=ENV_VARS):
            result = runner.invoke(hatch, [
                'release', '-l', '-u', USERNAME, '-r', TEST_REPOSITORY, '-ru',
                TEST_REPOSITORY, '-t'
            ])

        assert result.exit_code == 1
        assert "Cannot specify both --test and --repo." in result.output
        assert "Cannot specify both --test and --repo-url." in result.output
コード例 #21
0
def install(packages, env_name, editable, global_install, quiet):
    """If the option --env is supplied, the install will be applied using
    that named virtual env. Unless the option --global is selected, the
    install will only affect the current user. Of course, this will have
    no effect if a virtual env is in use. The desired name of the admin
    user can be set with the `_DEFAULT_ADMIN_` environment variable.

    With no packages selected, this will install using a `setup.py` in the
    current directory.
    """
    packages = packages or ['.']

    # Windows' `runas` allows only a single argument for the
    # command so we catch this case and turn our command into
    # a string later.
    windows_admin_command = None

    if editable:
        packages = ['-e', *packages]

    if env_name:
        venv_dir = os.path.join(VENV_DIR, env_name)
        if not os.path.exists(venv_dir):
            click.echo('Virtual env named `{}` does not exist.'.format(env_name))
            sys.exit(1)

        with venv(venv_dir):
            command = [get_proper_pip(), 'install', *packages] + (['-q'] if quiet else [])
            result = subprocess.run(command, shell=NEED_SUBPROCESS_SHELL)
    else:
        command = [get_proper_pip(), 'install'] + (['-q'] if quiet else [])

        if not venv_active():  # no cov
            if global_install:
                if ON_WINDOWS:
                    windows_admin_command = get_admin_command()
                else:
                    command = get_admin_command() + command
            else:
                command.append('--user')

        command.extend(packages)

        if windows_admin_command:  # no cov
            command = windows_admin_command + [' '.join(command)]

        result = subprocess.run(command, shell=NEED_SUBPROCESS_SHELL)

    sys.exit(result.returncode)
コード例 #22
0
def test_local():
    with temp_chdir() as d:
        runner = CliRunner()
        runner.invoke(hatch, ['new', PACKAGE_NAME, '--basic', '-ne'])
        runner.invoke(hatch, ['build', '-p', PACKAGE_NAME])
        package_dir = os.path.join(d, PACKAGE_NAME)

        venv_dir = os.path.join(d, 'venv')
        create_venv(venv_dir)

        with venv(venv_dir, evars=ENV_VARS):
            install_packages(['-e', package_dir])
            result = runner.invoke(hatch, ['release', '-l', '-u', USERNAME, '-t'])

        assert result.exit_code == 0
コード例 #23
0
ファイル: test_uninstall.py プロジェクト: peblair/hatch
def test_requirements():
    with temp_chdir() as d:
        runner = CliRunner()
        venv_dir = os.path.join(d, 'venv')
        create_venv(venv_dir)
        with open(os.path.join(d, 'requirements.txt'), 'w') as f:
            f.write('six\n')

        with venv(venv_dir):
            runner.invoke(hatch, ['install', '-nd', 'six'])
            assert 'six' in get_installed_packages()
            result = runner.invoke(hatch, ['uninstall', '-nd', '-y'])
            assert 'six' not in get_installed_packages()

        assert result.exit_code == 0
コード例 #24
0
def test_repository_env_vars():
    with temp_chdir() as d:
        runner = CliRunner()
        runner.invoke(hatch, ['new', PACKAGE_NAME, '--basic', '-ne'])
        runner.invoke(hatch, ['build', '-p', PACKAGE_NAME])
        package_dir = os.path.join(d, PACKAGE_NAME)

        venv_dir = os.path.join(d, 'venv')
        create_venv(venv_dir)

        extra_env_vars = {'TWINE_REPOSITORY': TEST_REPOSITORY, 'TWINE_REPOSITORY_URL': TEST_REPOSITORY, **ENV_VARS}
        with venv(venv_dir, evars=extra_env_vars):
            install_packages(['-e', package_dir])
            result = runner.invoke(hatch, ['release', '-l', '-u', USERNAME])

        assert result.exit_code == 0
コード例 #25
0
def test_new_env():
    with temp_chdir():
        runner = CliRunner()
        env_name = get_new_venv_name()
        venv_dir = os.path.join(VENV_DIR, env_name)

        try:
            result = runner.invoke(hatch, ['init', '--basic', 'ok', env_name])
            with venv(venv_dir):
                assert 'ok' in get_editable_packages()
        finally:
            remove_path(venv_dir)

        assert result.exit_code == 0
        assert 'Creating virtual env `{}`...'.format(env_name) in result.output
        assert 'Installing locally in virtual env `{}`...'.format(env_name) in result.output
コード例 #26
0
def test_requirements_dev():
    with temp_chdir() as d:
        with open(os.path.join(d, 'requirements-dev.txt'), 'w') as f:
            f.write('requests==2.18.1\n')

        venv_dir = os.path.join(d, 'venv')
        create_venv(venv_dir)

        with venv(venv_dir):
            install_packages(['requests==2.17.3'])
            initial_version = get_version_as_bytes('requests')
            runner = CliRunner()
            result = runner.invoke(hatch, ['update', '-nd'])
            final_version = get_version_as_bytes('requests')

        assert result.exit_code == 0
        assert initial_version < final_version
コード例 #27
0
ファイル: test_test.py プロジェクト: Oofsterer/hatch-1
def test_local():
    with temp_chdir() as d:
        runner = CliRunner()
        runner.invoke(hatch, ['new', 'ok', '--basic', '-ne'])
        package_dir = os.path.join(d, 'ok')
        create_test_passing(package_dir)

        venv_dir = os.path.join(d, 'venv')
        create_venv(venv_dir)

        with venv(venv_dir):
            install_packages(['-e', package_dir])
            result = runner.invoke(hatch, ['test', '-nd', '-l', '-g'])

        assert result.exit_code == 0
        assert 'Package `ok` has been selected.' in result.output
        assert '1 passed' in result.output
コード例 #28
0
ファイル: test_update.py プロジェクト: dot-Sean/hatch
def test_packages():
    with temp_chdir() as d:
        runner = CliRunner()
        venv_dir = os.path.join(d, 'venv')
        create_venv(venv_dir)

        with venv(venv_dir):
            install_packages(['requests==2.17.3', 'six==1.9.0'])
            initial_version_requests = get_version_as_bytes('requests')
            initial_version_six = get_version_as_bytes('six')
            result = runner.invoke(hatch, ['update', 'six'])
            final_version_requests = get_version_as_bytes('requests')
            final_version_six = get_version_as_bytes('six')

        assert result.exit_code == 0
        assert initial_version_requests == final_version_requests
        assert initial_version_six < final_version_six
コード例 #29
0
ファイル: test_install.py プロジェクト: peblair/hatch
def test_project_not_detected_when_venv_active():
    with temp_chdir() as d:
        runner = CliRunner()
        runner.invoke(hatch, ['init', 'ok', '-ne'])
        runner.invoke(hatch, ['new', 'ko'])
        venv_dir = os.path.join(d, 'ko', 'venv')
        wait_until(is_venv, venv_dir)
        assert os.path.exists(venv_dir)

        with venv(venv_dir):
            result = runner.invoke(hatch, ['install'])
            wait_for_os()
            assert 'ok' in get_installed_packages(editable=False)

        assert result.exit_code == 0
        assert 'A project has been detected!' not in result.output
        assert 'Installing...' in result.output
コード例 #30
0
def test_local_multiple():
    with temp_chdir() as d:
        runner = CliRunner()
        runner.invoke(hatch, ['new', 'ok', '--basic', '-ne'])
        runner.invoke(hatch, ['new', 'ko', '--basic', '-ne'])

        venv_dir = os.path.join(d, 'venv')
        create_venv(venv_dir)

        with venv(venv_dir):
            install_packages(['-e', os.path.join(d, 'ok')])
            install_packages(['-e', os.path.join(d, 'ko')])

            result = runner.invoke(hatch, ['clean', '-l'])

        assert result.exit_code == 1
        assert ('There are multiple local packages available. '
                'Select one with the optional argument.') in result.output