示例#1
0
        def _add_to_installed(distname, enabled, npe_version=1):
            norm_name = normalized_name(distname or '')
            if distname:
                try:
                    meta = metadata(distname)
                except PackageNotFoundError:
                    self.refresh_state = RefreshState.OUTDATED
                    return  # a race condition has occurred and the package is uninstalled by another thread
                if len(meta) == 0:
                    # will not add builtins.
                    return
                self.already_installed.add(norm_name)
            else:
                meta = {}

            self.installed_list.addItem(
                PackageMetadata(
                    metadata_version="1.0",
                    name=norm_name,
                    version=meta.get('version', ''),
                    summary=meta.get('summary', ''),
                    home_page=meta.get('url', ''),
                    author=meta.get('author', ''),
                    license=meta.get('license', ''),
                ),
                installed=True,
                enabled=enabled,
                npe_version=npe_version,
            )
示例#2
0
文件: hub.py 项目: julianbader/napari
def hub_plugin_info(
    name: str,
    min_dev_status=3,
    conda_forge=True,
) -> Tuple[Optional[PackageMetadata], bool]:
    """Get package metadata from the napari hub.

    Parameters
    ----------
    name : str
        name of the package
    min_dev_statur : int, optional
        Development status. Default is 3.
    conda_forge: bool, optional
        Check if package is available in conda-forge. Default is True.

    Returns
    -------
    Tuple of optional PackageMetadata and bool
        Project PackageMetadata and availability on conda forge.
    """
    try:
        with request.urlopen(NAPARI_HUB_PLUGINS + "/" + name) as resp:
            info = json.loads(resp.read().decode())
    except error.HTTPError:
        return None, False

    version = info["version"]
    norm_name = normalized_name(info["name"])
    is_available_in_conda_forge = True
    if conda_forge:
        is_available_in_conda_forge = False
        anaconda_api = ANACONDA_ORG.format(
            channel="conda-forge", package_name=norm_name
        )
        try:
            with request.urlopen(anaconda_api) as resp_api:
                anaconda_info = json.loads(resp_api.read().decode())
                if version in anaconda_info.get("versions", []):
                    is_available_in_conda_forge = True

        except error.HTTPError:
            pass

    classifiers = info.get("development_status", [])
    for _ in range(1, min_dev_status):
        if any(f'Development Status :: {1}' in x for x in classifiers):
            return None, False

    authors = ", ".join([author["name"] for author in info["authors"]])
    data = PackageMetadata(
        metadata_version="1.0",
        name=norm_name,
        version=version,
        summary=info["summary"],
        home_page=info["project_site"],
        author=authors,
        license=info["license"] or "UNKNOWN",
    )
    return data, is_available_in_conda_forge
示例#3
0
文件: __init__.py 项目: kne42/napari
def _initialize_plugins():
    _npe2pm = _PluginManager.instance()

    settings = get_settings()
    if settings.schema_version >= '0.4.0':
        for p in settings.plugins.disabled_plugins:
            _npe2pm.disable(p)

    _npe2pm.discover(include_npe1=settings.plugins.use_npe2_adaptor)
    _npe2pm.events.enablement_changed.connect(
        _npe2._on_plugin_enablement_change)

    # this is a workaround for the fact that briefcase does not seem to include
    # napari's entry_points.txt in the bundled app, so the builtin plugins
    # don't get detected.  So we just register it manually.  This could
    # potentially be removed when we move to a different bundle strategy
    if 'napari' not in _npe2pm._manifests:
        mf_file = Path(__file__).parent.parent / 'builtins.yaml'
        mf = PluginManifest.from_file(mf_file)
        mf.package_metadata = PackageMetadata.for_package('napari')
        _npe2pm.register(mf)

    # Disable plugins listed as disabled in settings, or detected in npe2
    _from_npe2 = {m.name for m in _npe2pm.iter_manifests()}
    if 'napari' in _from_npe2:
        _from_npe2.update({'napari', 'builtins'})
    plugin_manager._skip_packages = _from_npe2
    plugin_manager._blocked.update(settings.plugins.disabled_plugins)

    if settings.plugins.use_npe2_adaptor:
        # prevent npe1 plugin_manager discovery
        # (this doesn't prevent manual registration)
        plugin_manager.discover = lambda *a, **k: None
    else:
        plugin_manager._initialize()
示例#4
0
def ensure_published_at_pypi(name: str,
                             min_dev_status=3) -> Optional[PackageMetadata]:
    """Return name if ``name`` is a package in PyPI with dev_status > min."""
    try:
        with request.urlopen(f'https://pypi.org/pypi/{name}/json') as resp:
            info = json.loads(resp.read().decode()).get("info")
    except error.HTTPError:
        return None
    classifiers = info.get("classifiers")
    for i in range(1, min_dev_status):
        if any(f'Development Status :: {1}' in x for x in classifiers):
            return None

    return PackageMetadata(
        metadata_version="1.0",
        name=normalized_name(info["name"]),
        version=info["version"],
        summary=info["summary"],
        home_page=info["home_page"],
        author=info["author"],
        license=info["license"] or "UNKNOWN",
    )
示例#5
0
def _iter_napari_hub_or_pypi_plugin_info(
    conda_forge: bool,
) -> Generator[Tuple[Optional[PackageMetadata], bool], None, None]:
    """Mock the hub and pypi methods to collect available plugins.

    This will mock `napari.plugins.hub.iter_hub_plugin_info` for napari-hub,
    and `napari.plugins.pypi.iter_napari_plugin_info` for pypi.

    It will return two fake plugins that will populate the available plugins
    list (the bottom one). The first plugin will not be available on
    conda-forge so will be greyed out ("test-name-0"). The second plugin will
    be available on conda-forge so will be enabled ("test-name-1").
    """
    # This mock `base_data`` will be the same for both fake plugins.
    base_data = {
        "metadata_version": "1.0",
        "version": "0.1.0",
        "summary": "some test package",
        "home_page": "http://napari.org",
        "author": "test author",
        "license": "UNKNOWN",
    }
    for i in range(2):
        yield PackageMetadata(name=f"test-name-{i}", **base_data), bool(i)