Example #1
0
def test_get_content_version_none():
    req_spec_data = {'namespace': 'some_namespace',
                     'name': 'some_name',
                     'version': None}
    req_spec = RequirementSpec.from_dict(req_spec_data)
    with pytest.raises(exceptions.GalaxyError, match="The list of available versions for some_namespace.some_name is empty"):
        repository_version.get_repository_version({}, req_spec, [])
Example #2
0
def from_dependencies_dict(dependencies_dict,
                           namespace_override=None,
                           editable=False,
                           repository_spec=None):
    '''Build a list of Requirement objects from the 'dependencies' item in galaxy.yml'''
    reqs = []
    for req_label, req_version_spec in dependencies_dict.items():
        req_spec_data = spec_data_from_string(
            req_label,
            namespace_override=namespace_override,
            editable=editable)
        req_spec_data['version_spec'] = req_version_spec
        req_spec_data['req_spec_string'] = req_spec_data.pop(
            'spec_string', None)

        log.debug('req_spec_data: %s', req_spec_data)

        req_spec = RequirementSpec.from_dict(req_spec_data)

        log.debug('req_spec: %s', req_spec)

        requirement = Requirement(repository_spec=repository_spec,
                                  op=RequirementOps.EQ,
                                  scope=RequirementScopes.INSTALL,
                                  requirement_spec=req_spec)
        log.debug('requirement: %s', requirement)
        reqs.append(requirement)

    return reqs
Example #3
0
def galaxy_url_fetch(galaxy_context_example_invalid):
    req_spec = RequirementSpec(namespace='some_namespace',
                               name='some_name',
                               version_spec='==9.3.245')

    galaxy_url_fetch = galaxy_url.GalaxyUrlFetch(requirement_spec=req_spec, galaxy_context=galaxy_context_example_invalid)
    log.debug('galaxy_url_fetch: %s', galaxy_url_fetch)

    return galaxy_url_fetch
Example #4
0
def test_get_latest_in_content_versions_1_0_0_v_and_no_v():
    req_spec_data = {'namespace': 'some_namespace',
                     'name': 'some_name',
                     'version_spec': '*'}
    req_spec = RequirementSpec.from_dict(req_spec_data)

    with pytest.raises(exceptions.GalaxyClientError, match=""):
        repository_version.get_repository_version({}, req_spec,
                                                  content_versions_1_0_v_and_no_v)
Example #5
0
def test_get_content_version(ver_data):
    req_spec_data = {'namespace': 'some_namespace',
                     'name': 'some_name',
                     'version': ver_data['ask']}
    req_spec = RequirementSpec.from_dict(req_spec_data)

    res = repository_version.get_repository_version({}, req_spec, ver_data['vlist'])
    log.debug('res: %s', res)
    assert res == ver_data['exp']
Example #6
0
def test_get_content_version_latest(latest_ver_data):
    log.debug('latest_ver_data: %s', latest_ver_data)
    req_spec_data = {'namespace': 'some_namespace',
                     'name': 'some_name',
                     'version_spec': '*'}
    req_spec = RequirementSpec.from_dict(req_spec_data)

    res = repository_version.get_repository_version({}, req_spec, latest_ver_data['vlist'])
    log.debug('res: %s', res)
    assert res == latest_ver_data['exp']
Example #7
0
def load(data_or_file_object, repository_spec=None):
    log.debug('START of load of requirements %s', data_or_file_object.name)

    requirements_data = yaml.safe_load(data_or_file_object)

    # log.debug('requirements_data: %s', pprint.pformat(requirements_data))

    requirements_list = []

    for req_data_item in requirements_data:
        # log.debug('req_data_item: %s', req_data_item)
        # log.debug('type(req_data_item): %s', type(req_data_item))

        req_spec_data = yaml_parse.yaml_parse(req_data_item)

        # FIXME: find a better place to do this
        # create a version_spec from the 'version' field, a requiremenst.yml
        # does not currently expect to have a 'version_spec' data in it
        version_spec_str = '*'
        version_str = req_spec_data.pop('version')

        if version_str:
            version_spec_str = '==%s' % version_str

        version_spec = semantic_version.Spec(version_spec_str)

        req_spec_data['version_spec'] = version_spec

        # log.debug('data_name (after): %s', data_name)
        # log.debug('name_info: %s', name_info)

        req_spec = RequirementSpec.from_dict(req_spec_data)

        # log.debug('req_spec: %s', req_spec)

        req = Requirement(repository_spec=repository_spec,
                          op=RequirementOps.EQ,
                          requirement_spec=req_spec)

        # log.debug('req: %s', req)

        requirements_list.append(req)

    log.debug('FINISH of load of requirements: %s: %s',
              data_or_file_object.name, requirements_list)
    return requirements_list
Example #8
0
def from_dependency_spec_strings(dependency_spec_strings, namespace_override=None, editable=False):
    deps = []
    for dep_spec_string in dependency_spec_strings:
        dep_spec_data = spec_data_from_string(dep_spec_string)

        log.debug('dep_spec_data: %s', dep_spec_data)

        dep_spec = RequirementSpec.from_dict(dep_spec_data)

        log.debug('dep_spec: %s', dep_spec)

        # Add a requirement, but with the 'RUNTIME' scope
        requirement = Requirement(repository_spec=None, op=RequirementOps.EQ,
                                  scope=RequirementScopes.RUNTIME,
                                  requirement_spec=dep_spec)
        deps.append(requirement)

    return deps
Example #9
0
def from_requirement_spec_strings(requirement_spec_strings,
                                  namespace_override=None,
                                  editable=False,
                                  repository_spec=None):
    reqs = []
    for requirement_spec_string in requirement_spec_strings:
        req_spec_data = spec_data_from_string(
            requirement_spec_string,
            namespace_override=namespace_override,
            editable=editable)

        req_spec = RequirementSpec.from_dict(req_spec_data)

        req = Requirement(repository_spec=repository_spec,
                          op=RequirementOps.EQ,
                          requirement_spec=req_spec)

        reqs.append(req)

    return reqs
Example #10
0
def test_local_file_fetch(mocker):
    tmp_file_fo = tempfile.NamedTemporaryFile(prefix='tmp',
                                              suffix='.tar.gz',
                                              delete=True)
    log.debug('tmp_file_fo.name=%s tmp_file=%s', tmp_file_fo.name, tmp_file_fo)

    requirement_spec_ = RequirementSpec(namespace='namespace',
                                        name='name',
                                        version_spec='==1.2.3',
                                        fetch_method=FetchMethods.LOCAL_FILE,
                                        src=tmp_file_fo.name)

    mocker.patch(
        'ansible_galaxy.fetch.local_file.LocalFileFetch._load_repository_archive',
        return_value=mocker.Mock(name='mockRepoArchive'))
    mocker.patch(
        'ansible_galaxy.fetch.local_file.LocalFileFetch._load_repository',
        return_value=mocker.Mock(name='mockRepo'))
    local_fetch = local_file.LocalFileFetch(requirement_spec_)

    find_results = local_fetch.find()
    results = local_fetch.fetch(find_results=find_results)

    log.debug('results: %s', results)
    local_fetch.cleanup()

    # LocalFileFetch is acting directly on an existing file, so it's cleanup
    # should _not_ delete the file
    assert os.path.isfile(tmp_file_fo.name)

    # results = {'archive_path': '/tmp/tmpcle_fdtp.tar.gz', 'fetch_method': 'local_file',
    # 'custom': {'local_path': '/tmp/tmpcle_fdtp.tar.gz'},
    # 'content': {'galaxy_namespace': None, 'repo_name': '/tmp/tmpcle_fdtp.tar',
    # 'fetched_name': <Mock name='mockRepo.repository_spec.name' id='139946600228288'>}}
    assert results['archive_path'] == tmp_file_fo.name
    assert results['fetch_method'] == 'local_file'
    assert results['custom']['local_path'] == tmp_file_fo.name

    log.debug('should unlink %s here', tmp_file_fo.name)
Example #11
0
def test_find_new_deps_from_installed(galaxy_context):
    repo_spec = RepositorySpec(namespace='some_namespace',
                               name='some_name',
                               version='4.3.2')

    req_spec = RequirementSpec(namespace='some_required_namespace',
                               name='some_required_name',
                               version_spec='==1.0.0')

    some_requirement = Requirement(repository_spec=repo_spec,
                                   op=RequirementOps.EQ,
                                   requirement_spec=req_spec)

    installed_repo = Repository(
        repo_spec, requirements=[some_requirement, some_requirement])
    res = install.find_new_deps_from_installed(galaxy_context,
                                               [installed_repo])

    log.debug('res: %s', res)
    assert isinstance(res, list)
    assert isinstance(res[0], Requirement)
    assert res[0].requirement_spec == req_spec
Example #12
0
def test_editable_fetch_fetch(galaxy_context, mocker, tmpdir):
    name = 'mazer_fetch_test_editable'
    namespace_override = 'some_editable_namespace'

    tmp_working_path = tmpdir.mkdir('some_working_tree')
    dest_tmp_path = tmp_working_path.mkdir('some_checkout')

    req_spec = RequirementSpec(namespace=namespace_override,
                               name=name,
                               fetch_method='EDITABLE',
                               src=dest_tmp_path,
                               version_spec='*')
    # RepositorySpec(namespace='some_editable_namespace', name='some_checkout',
    #                version=None, fetch_method='EDITABLE', scm=None,
    #                spec_string='/tmp/pytest-of-adrian/pytest-79/test_editable_fetch_fetch0/some_checkout',
    #                src='/tmp/pytest-of-adrian/pytest-79/test_editable_fetch_fetch0/some_checkout')
    log.debug('req_spec: %r', req_spec)

    fetcher = editable.EditableFetch(galaxy_context, req_spec)

    find_results = {
        'custom': {
            'real_path': dest_tmp_path.strpath
        },
        'content': []
    }

    res = fetcher.fetch(find_results=find_results)
    log.debug('res: %s', res)

    expected_link_name = os.path.join(galaxy_context.collections_path,
                                      COLLECTIONS_PYTHON_NAMESPACE,
                                      namespace_override, name)
    log.debug('expected_link_name: %s', expected_link_name)

    assert isinstance(res, dict)
    assert res['archive_path'] == dest_tmp_path.strpath
    assert res['custom']['symlinked_repo_root'] == expected_link_name
Example #13
0
def install_repository_specs_loop(galaxy_context,
                                  repository_spec_strings=None,
                                  requirements_list=None,
                                  collections_lockfile_path=None,
                                  editable=False,
                                  namespace_override=None,
                                  display_callback=None,
                                  # TODO: error handling callback ?
                                  ignore_errors=False,
                                  no_deps=False,
                                  force_overwrite=False):

    requirements_list = requirements_list or []

    for repository_spec_string in repository_spec_strings:
        fetch_method = \
            repository_spec_parse.choose_repository_fetch_method(repository_spec_string,
                                                                 editable=editable)
        log.debug('fetch_method: %s', fetch_method)

        if fetch_method == FetchMethods.LOCAL_FILE:
            # Since we only know this is a local file we vaguely recognize, we have to
            # open it up to get any more details. We _could_ attempt to parse the file
            # name, but that rarely ends well. Filename could also be arbitrary for downloads
            # from remote urls ('mazer install http://myci.example.com/somebuildjob/latest' etc)
            spec_data = collection_artifact.load_data_from_collection_artifact(repository_spec_string)
            spec_data['fetch_method'] = fetch_method
        elif fetch_method == FetchMethods.REMOTE_URL:
            # download the url
            # hope it is a collection artifact and use load_data_from_collection_artifact() for the
            # rest of the repo_spec data
            log.debug('repository_spec_string: %s', repository_spec_string)

            tmp_downloaded_path = download.fetch_url(repository_spec_string,
                                                     # Note: ignore_certs is meant for galaxy server,
                                                     # overloaded to apply for arbitrary http[s] downloads here
                                                     validate_certs=not galaxy_context.server['ignore_certs'])
            spec_data = collection_artifact.load_data_from_collection_artifact(tmp_downloaded_path)

            # pretend like this is a local_file install now
            spec_data['fetch_method'] = FetchMethods.LOCAL_FILE
        else:
            spec_data = repository_spec_parse.spec_data_from_string(repository_spec_string,
                                                                    namespace_override=namespace_override,
                                                                    editable=editable)

            spec_data['fetch_method'] = fetch_method

        log.debug('spec_data: %s', spec_data)

        req_spec = RequirementSpec.from_dict(spec_data)

        req = Requirement(repository_spec=None, op=RequirementOps.EQ, requirement_spec=req_spec)

        requirements_list.append(req)

    log.debug('collections_lockfile_path: %s', collections_lockfile_path)

    if collections_lockfile_path:
        # load collections lockfile as if the 'dependencies' dict from a collection_info
        collections_lockfile = load_collections_lockfile(collections_lockfile_path)

        dependencies_list = requirements.from_dependencies_dict(collections_lockfile.dependencies)

        # Create the CollectionsLock for the validators
        collections_lock = CollectionsLock(dependencies=dependencies_list)

        requirements_list.extend(collections_lock.dependencies)

    log.debug('requirements_list: %s', requirements_list)

    while True:
        if not requirements_list:
            break

        display_callback('', level='info')
        display_callback('Collection specs to install:', level='info')

        for req in requirements_list:
            if req.repository_spec:
                msg = '  %s (required by %s)' % (req.requirement_spec.label, req.repository_spec)
            else:
                msg = '  %s' % req.requirement_spec.label
            display_callback(msg, level='info')

        just_installed_repositories = \
            install_repositories_matching_repository_specs(galaxy_context,
                                                           requirements_list,
                                                           editable=editable,
                                                           namespace_override=namespace_override,
                                                           display_callback=display_callback,
                                                           ignore_errors=ignore_errors,
                                                           no_deps=no_deps,
                                                           force_overwrite=force_overwrite)

        for just_installed_repo in just_installed_repositories:
            display_callback('  Installed: %s (to %s)' %
                             (just_installed_repo.repository_spec,
                              just_installed_repo.path),
                             level='info')

        # set the repository_specs to search for to whatever the install reported as being needed yet
        # requirements_list = new_requirements_list
        requirements_list = find_new_deps_from_installed(galaxy_context,
                                                         just_installed_repositories,
                                                         no_deps=no_deps)

    # FIXME: what results to return?
    return 0
Example #14
0
def install_repository_specs_loop(galaxy_context,
                                  repository_spec_strings=None,
                                  requirements_list=None,
                                  editable=False,
                                  namespace_override=None,
                                  display_callback=None,
                                  # TODO: error handling callback ?
                                  ignore_errors=False,
                                  no_deps=False,
                                  force_overwrite=False):

    requirements_list = requirements_list or []

    for repository_spec_string in repository_spec_strings:
        fetch_method = \
            repository_spec.choose_repository_fetch_method(repository_spec_string,
                                                           editable=editable)
        log.debug('fetch_method: %s', fetch_method)

        if fetch_method == FetchMethods.LOCAL_FILE:
            # Since only know this is a local file we vaguely recognize, we have to
            # open it up to get any more details. We _could_ attempt to parse the file
            # name, but that rarely ends well...
            spec_data = collection_artifact.load_data_from_collection_artifact(repository_spec_string)
            spec_data['fetch_method'] = fetch_method
        else:
            spec_data = repository_spec.spec_data_from_string(repository_spec_string,
                                                              namespace_override=namespace_override,
                                                              editable=editable)

            spec_data['fetch_method'] = fetch_method

        log.debug('spec_data: %s', spec_data)

        req_spec = RequirementSpec.from_dict(spec_data)

        req = Requirement(repository_spec=None, op=RequirementOps.EQ, requirement_spec=req_spec)

        requirements_list.append(req)

    log.debug('requirements_list: %s', requirements_list)
    for req in requirements_list:
        display_callback('Installing %s' % req.requirement_spec.label, level='info')

    while True:
        if not requirements_list:
            break

        just_installed_repositories = \
            install_repositories_matching_repository_specs(galaxy_context,
                                                           requirements_list,
                                                           editable=editable,
                                                           namespace_override=namespace_override,
                                                           display_callback=display_callback,
                                                           ignore_errors=ignore_errors,
                                                           no_deps=no_deps,
                                                           force_overwrite=force_overwrite)

        # set the repository_specs to search for to whatever the install reported as being needed yet
        # requirements_list = new_requirements_list
        requirements_list = find_new_deps_from_installed(galaxy_context,
                                                         just_installed_repositories,
                                                         no_deps=no_deps)

        for req in requirements_list:
            if req.repository_spec:
                msg = 'Installing requirement %s (required by %s)' % (req.requirement_spec.label, req.repository_spec.label)
            else:
                msg = 'Installing requirement %s' % req.requirement_spec.label
            display_callback(msg, level='info')

    # FIXME: what results to return?
    return 0