예제 #1
0
def install_perl_get_core_modules(version):
    try:
        from conda_build.config import Config
        from conda_build.conda_interface import TemporaryDirectory

        config = Config()

        if sys.platform.startswith('win'):
            subdirs = ('win-64', 'Library', 'bin', 'perl.exe')
        elif sys.platform.startswith('linux'):
            subdirs = ('linux-64', 'bin', 'perl')
        else:
            subdirs = ('osx-64', 'bin', 'perl')
        # Return one of the dist things instead?
        with TemporaryDirectory() as tmpdir:
            environ.create_env(tmpdir, [f'perl={version}'],
                               env='host',
                               config=config,
                               subdir=subdirs[0])
            args = [
                f'{join(tmpdir, *subdirs[1:])}', '-e',
                'use Module::CoreList; print join "\n", Module::CoreList->find_modules(qr/.*/);'
            ]
            from subprocess import check_output
            all_core_modules = check_output(
                args, shell=False).decode('utf-8').replace('\r\n',
                                                           '\n').split('\n')
            return all_core_modules
    except Exception as e:
        print(
            "Failed to query perl={} for core modules list, attempted command was:\n{}"
            .format(version, ' '.join(args)))
        print(e.message)

    return []
예제 #2
0
def test_env_creation_with_prefix_fallback_disabled(testing_config):
    tempdir = '/tmp' if platform.system() == 'Darwin' else tempfile.gettempdir(
    )
    testing_config.croot = os.path.join(tempdir, 'cb')
    testing_config.anaconda_upload = False
    testing_config.anaconda_upload = False
    testing_config.prefix_length_fallback = False
    testing_config.prefix_length = 80

    recipe_path = os.path.join(metadata_dir, "has_prefix_files")
    metadata = api.render(recipe_path, config=testing_config)[0][0]
    fn = api.get_output_file_paths(metadata)[0]
    if os.path.isfile(fn):
        os.remove(fn)

    with pytest.raises((SystemExit, PaddingError, LinkError, CondaError)):
        output = api.build(metadata)[0]
        assert not api.inspect_prefix_length(output, 255)
        testing_config.prefix_length = 255
        environ.create_env(testing_config.build_prefix,
                           specs_or_actions=["python",
                                             metadata.name()],
                           env='build',
                           config=testing_config,
                           subdir=subdir)
예제 #3
0
def test_environment_creation_preserves_PATH(testing_workdir, testing_config):
    ref_path = os.environ['PATH']
    environ.create_env(testing_workdir, ['python'],
                       env='host',
                       config=testing_config,
                       subdir=testing_config.build_subdir)
    assert os.environ['PATH'] == ref_path
예제 #4
0
def test_env_creation_with_short_prefix_does_not_deadlock(testing_workdir, caplog):
    config = api.Config(croot=testing_workdir, anaconda_upload=False, verbose=True,
                        set_build_id=False, _prefix_length=80)
    recipe_path = os.path.join(metadata_dir, "has_prefix_files")
    metadata = api.render(recipe_path, config=config)[0][0]
    output = api.build(metadata)[0]
    assert not api.inspect_prefix_length(output, 255)
    config.prefix_length = 255
    environ.create_env(config.build_prefix, specs_or_actions=["python", metadata.name()],
                        config=config, subdir=subdir)
    assert 'One or more of your package dependencies needs to be rebuilt' in caplog.text
예제 #5
0
def test_env_creation_with_short_prefix_does_not_deadlock(testing_workdir, caplog):
    tempdir = '/tmp' if platform.system() == 'Darwin' else tempfile.gettempdir()
    config = api.Config(croot=os.path.join(tempdir, 'cb'), anaconda_upload=False, verbose=True,
                        set_build_id=False, _prefix_length=80)
    recipe_path = os.path.join(metadata_dir, "has_prefix_files")
    metadata = api.render(recipe_path, config=config)[0][0]
    output = api.build(metadata)[0]
    assert not api.inspect_prefix_length(output, 255)
    config.prefix_length = 255
    environ.create_env(config.build_prefix, specs_or_actions=["python", metadata.name()],
                       env='build', config=config, subdir=subdir)
    assert 'One or more of your package dependencies needs to be rebuilt' in caplog.text
예제 #6
0
def test_env_creation_with_prefix_fallback_disabled():
    test_base = os.path.expanduser("~/cbtmp")
    config = api.Config(croot=test_base, anaconda_upload=False, verbose=True,
                        prefix_length_fallback=False, _prefix_length=80)
    recipe_path = os.path.join(metadata_dir, "has_prefix_files")
    metadata = api.render(recipe_path, config=config)[0][0]
    fn = api.get_output_file_path(metadata)[0]
    if os.path.isfile(fn):
        os.remove(fn)

    with pytest.raises((SystemExit, PaddingError, LinkError, CondaError)):
        output = api.build(metadata)[0]
        assert not api.inspect_prefix_length(output, 255)
        config.prefix_length = 255
        environ.create_env(config.build_prefix, specs_or_actions=["python", metadata.name()],
                           config=config, subdir=subdir)
예제 #7
0
def test_env_creation_with_short_prefix_does_not_deadlock(
        testing_workdir, caplog):
    config = api.Config(croot=testing_workdir,
                        anaconda_upload=False,
                        verbose=True,
                        set_build_id=False,
                        _prefix_length=80)
    recipe_path = os.path.join(metadata_dir, "has_prefix_files")
    metadata = api.render(recipe_path, config=config)[0][0]
    try:
        output = api.build(metadata)[0]
        assert not api.inspect_prefix_length(output, 255)
        config.prefix_length = 255
        environ.create_env(config.build_prefix,
                           specs=["python", metadata.name()],
                           config=config,
                           subdir=subdir)
    except:
        raise
    assert 'One or more of your package dependencies needs to be rebuilt' in caplog.text
예제 #8
0
def test_env_creation_with_prefix_fallback_disabled():
    test_base = os.path.expanduser("~/cbtmp")
    config = api.Config(croot=test_base,
                        anaconda_upload=False,
                        verbose=True,
                        prefix_length_fallback=False,
                        _prefix_length=80)
    recipe_path = os.path.join(metadata_dir, "has_prefix_files")
    metadata = api.render(recipe_path, config=config)[0][0]
    fn = api.get_output_file_path(metadata)[0]
    if os.path.isfile(fn):
        os.remove(fn)

    with pytest.raises((SystemExit, PaddingError, LinkError, CondaError)):
        output = api.build(metadata)[0]
        assert not api.inspect_prefix_length(output, 255)
        config.prefix_length = 255
        environ.create_env(config.build_prefix,
                           specs=["python", metadata.name()],
                           config=config,
                           subdir=subdir)
예제 #9
0
def test_env_creation_with_prefix_fallback_disabled(testing_config):
    tempdir = '/tmp' if platform.system() == 'Darwin' else tempfile.gettempdir()
    testing_config.croot = os.path.join(tempdir, 'cb')
    testing_config.anaconda_upload = False
    testing_config.anaconda_upload = False
    testing_config.prefix_length_fallback = False
    testing_config.prefix_length = 80

    recipe_path = os.path.join(metadata_dir, "has_prefix_files")
    metadata = api.render(recipe_path, config=testing_config)[0][0]
    fn = api.get_output_file_paths(metadata)[0]
    if os.path.isfile(fn):
        os.remove(fn)

    with pytest.raises((SystemExit, PaddingError, LinkError, CondaError)):
        output = api.build(metadata)[0]
        assert not api.inspect_prefix_length(output, 255)
        testing_config.prefix_length = 255
        environ.create_env(testing_config.build_prefix,
                           specs_or_actions=["python", metadata.name()],
                           env='build', config=testing_config, subdir=subdir)
예제 #10
0
def run_setuppy(src_dir, temp_dir, python_version, extra_specs, config,
                setup_options):
    '''
    Patch distutils and then run setup.py in a subprocess.

    :param src_dir: Directory containing the source code
    :type src_dir: str
    :param temp_dir: Temporary directory for doing for storing pkginfo.yaml
    :type temp_dir: str
    '''
    # TODO: we could make everyone's lives easier if we include packaging here, because setuptools
    #    needs it in recent versions.  At time of writing, it is not a package in defaults, so this
    #    actually breaks conda-build right now.  Omit it until packaging is on defaults.
    # specs = ['python %s*' % python_version, 'pyyaml', 'setuptools', 'six', 'packaging', 'appdirs']
    specs = ['python %s*' % python_version, 'pyyaml', 'setuptools']
    with open(os.path.join(src_dir, "setup.py")) as setup:
        text = setup.read()
        if 'import numpy' in text or 'from numpy' in text:
            specs.append('numpy')

    specs.extend(extra_specs)

    rm_rf(config.host_prefix)
    create_env(config.host_prefix,
               specs_or_actions=specs,
               env='host',
               subdir=config.host_subdir,
               clear_cache=False,
               config=config)
    stdlib_dir = join(
        config.host_prefix,
        'Lib' if sys.platform == 'win32' else 'lib/python%s' % python_version)

    patch = join(temp_dir, 'pypi-distutils.patch')
    with open(patch, 'w') as f:
        f.write(DISTUTILS_PATCH.format(temp_dir.replace('\\', '\\\\')))

    if exists(join(stdlib_dir, 'distutils', 'core.py-copy')):
        rm_rf(join(stdlib_dir, 'distutils', 'core.py'))
        copy2(join(stdlib_dir, 'distutils', 'core.py-copy'),
              join(stdlib_dir, 'distutils', 'core.py'))
        # Avoid race conditions. Invalidate the cache.
        if PY3:
            rm_rf(
                join(stdlib_dir, 'distutils', '__pycache__',
                     'core.cpython-%s%s.pyc' % sys.version_info[:2]))
            rm_rf(
                join(stdlib_dir, 'distutils', '__pycache__',
                     'core.cpython-%s%s.pyo' % sys.version_info[:2]))
        else:
            rm_rf(join(stdlib_dir, 'distutils', 'core.pyc'))
            rm_rf(join(stdlib_dir, 'distutils', 'core.pyo'))
    else:
        copy2(join(stdlib_dir, 'distutils', 'core.py'),
              join(stdlib_dir, 'distutils', 'core.py-copy'))
    apply_patch(join(stdlib_dir, 'distutils'), patch, config=config)

    # Save PYTHONPATH for later
    env = os.environ.copy()
    if 'PYTHONPATH' in env:
        env[str('PYTHONPATH')] = str(src_dir + ':' + env['PYTHONPATH'])
    else:
        env[str('PYTHONPATH')] = str(src_dir)
    cwd = getcwd()
    chdir(src_dir)
    cmdargs = [config.host_python, 'setup.py', 'install']
    cmdargs.extend(setup_options)
    try:
        check_call_env(cmdargs, env=env)
    except subprocess.CalledProcessError:
        print('$PYTHONPATH = %s' % env['PYTHONPATH'])
        sys.exit('Error: command failed: %s' % ' '.join(cmdargs))
    finally:
        chdir(cwd)
예제 #11
0
def test_environment_creation_preserves_PATH(testing_workdir, testing_config):
    ref_path = os.environ['PATH']
    environ.create_env(testing_workdir, ['python'], env='host', config=testing_config,
                       subdir=testing_config.build_subdir)
    assert os.environ['PATH'] == ref_path
예제 #12
0
def run_setuppy(src_dir, temp_dir, python_version, extra_specs, config, setup_options):
    '''
    Patch distutils and then run setup.py in a subprocess.

    :param src_dir: Directory containing the source code
    :type src_dir: str
    :param temp_dir: Temporary directory for doing for storing pkginfo.yaml
    :type temp_dir: str
    '''
    # TODO: we could make everyone's lives easier if we include packaging here, because setuptools
    #    needs it in recent versions.  At time of writing, it is not a package in defaults, so this
    #    actually breaks conda-build right now.  Omit it until packaging is on defaults.
    # specs = ['python %s*' % python_version, 'pyyaml', 'setuptools', 'six', 'packaging', 'appdirs']
    specs = ['python %s*' % python_version, 'pyyaml']
    with open(os.path.join(src_dir, "setup.py")) as setup:
        text = setup.read()
        if 'import numpy' in text or 'from numpy' in text:
            specs.append('numpy')

    specs.extend(extra_specs)

    # Do everything in the build env in case the setup.py install goes
    # haywire.
    # TODO: Try with another version of Python if this one fails. Some
    # packages are Python 2 or Python 3 only.

    if not os.path.isdir(config.build_prefix) or not os.listdir(config.build_prefix):
        create_env(config.build_prefix, specs_or_actions=specs,
                   subdir=config.build_subdir,
                   clear_cache=False,
                   config=config)
    stdlib_dir = join(config.build_prefix,
                      'Lib' if sys.platform == 'win32'
                      else 'lib/python%s' % python_version)

    patch = join(temp_dir, 'pypi-distutils.patch')
    with open(patch, 'w') as f:
        f.write(DISTUTILS_PATCH.format(temp_dir.replace('\\', '\\\\')))

    if exists(join(stdlib_dir, 'distutils', 'core.py-copy')):
        rm_rf(join(stdlib_dir, 'distutils', 'core.py'))
        copy2(join(stdlib_dir, 'distutils', 'core.py-copy'),
              join(stdlib_dir, 'distutils', 'core.py'))
        # Avoid race conditions. Invalidate the cache.
        if PY3:
            rm_rf(join(stdlib_dir, 'distutils', '__pycache__',
                'core.cpython-%s%s.pyc' % sys.version_info[:2]))
            rm_rf(join(stdlib_dir, 'distutils', '__pycache__',
                'core.cpython-%s%s.pyo' % sys.version_info[:2]))
        else:
            rm_rf(join(stdlib_dir, 'distutils', 'core.pyc'))
            rm_rf(join(stdlib_dir, 'distutils', 'core.pyo'))
    else:
        copy2(join(stdlib_dir, 'distutils', 'core.py'), join(stdlib_dir,
            'distutils', 'core.py-copy'))
    apply_patch(join(stdlib_dir, 'distutils'), patch, config=config)

    # Save PYTHONPATH for later
    env = os.environ.copy()
    if 'PYTHONPATH' in env:
        env[str('PYTHONPATH')] = str(src_dir + ':' + env['PYTHONPATH'])
    else:
        env[str('PYTHONPATH')] = str(src_dir)
    cwd = getcwd()
    chdir(src_dir)
    cmdargs = [config.build_python, 'setup.py', 'install']
    cmdargs.extend(setup_options)
    try:
        check_call_env(cmdargs, env=env)
    except subprocess.CalledProcessError:
        print('$PYTHONPATH = %s' % env['PYTHONPATH'])
        sys.exit('Error: command failed: %s' % ' '.join(cmdargs))
    finally:
        chdir(cwd)