コード例 #1
0
ファイル: model.py プロジェクト: chanzuckerberg/napari-hub
def build_plugin_metadata(plugin: str, version: str) -> Tuple[str, dict]:
    """
    Build plugin metadata from multiple sources, reuse cached ones if available.

    :return: dict for aggregated plugin metadata
    """
    cached_plugin = get_cache(f'cache/{plugin}/{version}.json')
    if cached_plugin:
        return plugin, cached_plugin
    metadata = get_plugin_pypi_metadata(plugin, version)
    github_repo_url = metadata.get('code_repository')
    if github_repo_url:
        metadata = {**metadata, **get_github_metadata(github_repo_url)}
    if 'description' in metadata:
        metadata['description_text'] = render_description(
            metadata.get('description'))
    if 'labels' in metadata:
        category_mappings = get_categories_mapping(
            metadata['labels']['ontology'])
        categories = defaultdict(list)
        category_hierarchy = defaultdict(list)
        for category in metadata['labels']['terms']:
            mapped_category = get_category_mapping(category, category_mappings)
            for match in mapped_category:
                if match['label'] not in categories[match['dimension']]:
                    categories[match['dimension']].append(match['label'])
                match['hierarchy'][0] = match['label']
                category_hierarchy[match['dimension']].append(
                    match['hierarchy'])
        metadata['category'] = categories
        metadata['category_hierarchy'] = category_hierarchy
        del metadata['labels']
    cache(metadata, f'cache/{plugin}/{version}.json')
    return plugin, metadata
コード例 #2
0
ファイル: model.py プロジェクト: chanzuckerberg/napari-hub
def get_hidden_plugins() -> Dict[str, str]:
    """
    Get the dictionary of hidden plugins and versions.

    :return: dict of hidden plugins and their versions
    """
    hidden_plugins = get_cache('cache/hidden-plugins.json')
    if hidden_plugins:
        return hidden_plugins
    else:
        return {}
コード例 #3
0
ファイル: model.py プロジェクト: chanzuckerberg/napari-hub
def get_public_plugins() -> Dict[str, str]:
    """
    Get the dictionary of public plugins and versions.

    :return: dict of public plugins and their versions
    """
    public_plugins = get_cache('cache/public-plugins.json')
    if public_plugins:
        return public_plugins
    else:
        return {}
コード例 #4
0
ファイル: model.py プロジェクト: chanzuckerberg/napari-hub
def get_excluded_plugins() -> Dict[str, str]:
    """
    Get the excluded plugins.

    :return: dict for excluded plugins and their exclusion status
    """
    excluded_plugins = get_cache('excluded_plugins.json')
    if excluded_plugins:
        return excluded_plugins
    else:
        return {}
コード例 #5
0
ファイル: model.py プロジェクト: chanzuckerberg/napari-hub
def get_index() -> dict:
    """
    Get the index page related metadata for all plugins.

    :return: dict for index page metadata
    """
    index = get_cache('cache/index.json')
    if index:
        return index
    else:
        return {}
コード例 #6
0
ファイル: model.py プロジェクト: chanzuckerberg/napari-hub
def get_plugin(plugin: str, version: str = None) -> dict:
    """
    Get plugin metadata for a particular plugin, get latest if version is None.

    :param plugin: name of the plugin to get
    :param version: version of the plugin
    :return: plugin metadata dictionary
    """
    plugins = get_valid_plugins()
    if plugin not in plugins:
        return {}
    elif version is None:
        version = plugins[plugin]
    plugin = get_cache(f'cache/{plugin}/{version}.json')
    if plugin:
        return plugin
    else:
        return {}
コード例 #7
0
ファイル: model.py プロジェクト: chanzuckerberg/napari-hub
def get_categories_mapping(version: str) -> Dict[str, List]:
    """
    Get all category mappings.

    Parameters
    ----------
    version
        version of the category mapping to get

    Returns
    -------
    Mapping between ontology label to list of mappings, each mapping consists:
        dimension: dimension of the mapping, should be one of ["Supported data", "Image modality", "Workflow step"]
        hierarchy: mapped hierarchy from the top level ontology label to the bottom as a list
        label: mapped napari hub label.
    """
    mappings = get_cache(f'category/{version.replace(":", "/")}.json')
    return mappings or {}
コード例 #8
0
ファイル: model.py プロジェクト: chanzuckerberg/napari-hub
def get_manifest(plugin: str, version: str = None) -> dict:
    """
    Get plugin manifest file for a particular plugin, get latest if version is None.

    :param plugin: name of the plugin to get
    :param version: version of the plugin manifest
    :return: plugin manifest dictionary
    """
    plugins = get_valid_plugins()
    if plugin not in plugins:
        return {}
    elif version is None:
        version = plugins[plugin]
    plugin = get_cache(f'cache/{plugin}/{version}.yaml', 'yaml')
    if plugin:
        return plugin
    else:
        cache({"process_count": 0},
              f'cache/{plugin}/{version}.yaml',
              format='yaml')
        return {"process_count": 0}