Esempio n. 1
0
def test_restore_success():
    with temp_chdir() as d:
        runner = CliRunner()

        env_name, fake_name = get_new_venv_name(count=2)
        venv_origin = os.path.join(d, env_name)
        venv_dir = os.path.join(get_venv_dir(), env_name)
        fake_venv = os.path.join(get_venv_dir(), fake_name)

        create_venv(venv_origin)
        copy_path(venv_origin, get_venv_dir())
        os.makedirs(fake_venv)

        try:
            runner.invoke(hatch, ['env', env_name])
            wait_until(is_venv, venv_dir)

            result = runner.invoke(hatch, ['env', '-r'])
            with venv(venv_dir):
                install_packages(['six'])
                installed_packages = get_installed_packages()
        finally:
            remove_path(venv_dir)
            remove_path(fake_venv)

        assert result.exit_code == 0
        assert 'Successfully restored all available virtual envs.' in result.output
        assert 'six' in installed_packages
Esempio n. 2
0
def test_restore_success():
    with temp_chdir() as d:
        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_origin = os.path.join(d, env_name)
        create_venv(venv_origin)

        venv_dir = os.path.join(VENV_DIR, env_name)
        copy_path(venv_origin, VENV_DIR)

        fake_venv = ''

        try:
            runner.invoke(hatch, ['env', env_name])

            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()
            fake_venv = os.path.join(VENV_DIR, env_name)
            os.makedirs(fake_venv)

            result = runner.invoke(hatch, ['env', '-r'])
            with venv(venv_dir):
                install_packages(['six'])
                installed_packages = get_installed_packages()
        finally:
            remove_path(venv_dir)
            remove_path(fake_venv)

        assert result.exit_code == 0
        assert 'Successfully restored all available virtual envs.' in result.output
        assert 'six' in installed_packages
Esempio n. 3
0
def create_package(d, package_name, settings):
    normalized_package_name = normalize_package_name(package_name)
    cli = settings.get('cli')
    basic = settings.get('basic', DEFAULT_SETTINGS['basic'])
    extra_files = []

    author = settings.get('name') or DEFAULT_SETTINGS['name']
    version = settings.get('version') or '0.0.1'
    email = settings.get('email') or DEFAULT_SETTINGS['email']
    description = settings.get('description') or ''
    pyversions = sorted(
        settings.get('pyversions') or DEFAULT_SETTINGS['pyversions'])
    vc_setup = VC_SETUP[settings.get('vc') or DEFAULT_SETTINGS['vc']]
    vc_url = settings.get('vc_url') or DEFAULT_SETTINGS['vc_url']
    package_url = vc_url + '/' + package_name

    readme_format = (settings.get('readme', {}).get('format')
                     or DEFAULT_SETTINGS['readme']['format'])

    licenses = [
        LICENSES[li](author)
        for li in settings.get('licenses') or DEFAULT_SETTINGS['licenses']
    ]

    badges = []
    if not basic:
        for badge_info in settings.get('readme', {}).get('badges', []):
            image = badge_info.pop('image', 'no_image')
            target = badge_info.pop('target', 'no_target')
            alt = badge_info.pop('alt', 'badge')

            badges.append(
                Badge(image.format(package_name), target.format(package_name),
                      alt, badge_info))

    readme = README[readme_format](package_name, pyversions, licenses, badges)

    setup_py = SetupFile(author, email, package_name, pyversions, licenses,
                         readme, package_url, cli)
    projectfile = ProjectFile(package_name, version, author, email,
                              description, pyversions, licenses, package_url)

    coverage_service = settings.get('coverage') if not basic else None
    if coverage_service:
        coverage_service = COVERAGE_SERVICES[coverage_service]()
        extra_files.append(coverage_service)

    for service in settings.get('ci', []):
        if not basic:
            extra_files.append(CI_SERVICES[service](pyversions,
                                                    coverage_service))

    coveragerc = CoverageConfig(package_name, cli)
    tox = Tox(pyversions, coverage_service)

    package_dir = os.path.join(d, normalized_package_name)
    init_py = File('__init__.py',
                   "__version__ = '{version}'\n".format(version=version))
    init_py.write(package_dir)
    create_file(os.path.join(d, 'tests', '__init__.py'))

    if cli:
        cli_py = File(
            'cli.py', "def {}():\n    print('Hello world!')\n".format(
                normalized_package_name))
        cli_py.write(package_dir)
        main_py = File(
            '__main__.py', 'import sys\n'
            'from {npn}.cli import {npn}\n'
            'sys.exit({npn}())\n'.format(npn=normalized_package_name))
        main_py.write(package_dir)

    setup_py.write(d)
    projectfile.write(d)
    readme.write(d)
    coveragerc.write(d)
    tox.write(d)

    requirements = File('requirements.txt', "-e .\n")
    requirements.write(d)

    for li in licenses:
        li.write(d)

    for file in extra_files:
        file.write(d)

    for p in settings.get('extras', []):
        for path in glob.iglob(p):
            copy_path(path, d)

    manifest_text = ''

    manifest_files = {
        'AUTHORS*',
        'CHANGELOG*',
        'CHANGES*',
        'CONTRIBUTING*',
        'HISTORY*',
        'LICENCE*',
        'LICENSE*',
        'README*',
    }

    for pattern in manifest_files:
        for path in sorted(glob.iglob(os.path.join(d, pattern))):
            if os.path.isfile(path):  # no cov
                manifest_text += 'include {}\n'.format(os.path.basename(path))

    manifest = File('MANIFEST.in', manifest_text)
    manifest.write(d)

    vc_setup(d, package_name)