Skip to content

Commit

Permalink
Move conda.models.plugins to conda.plugins.types (conda#12058)
Browse files Browse the repository at this point in the history
* Move `conda.models.plugins` to `conda.plugins.types`

* Update test imports

* Simplify docstring.

Co-authored-by: Jannis Leidel <[email protected]>
  • Loading branch information
kenodegard and jezdez authored Nov 9, 2022
1 parent b10ba99 commit 3f8db55
Show file tree
Hide file tree
Showing 12 changed files with 23 additions and 31 deletions.
1 change: 1 addition & 0 deletions conda/plugins/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Copyright (C) 2012 Anaconda, Inc
# SPDX-License-Identifier: BSD-3-Clause
from .hookspec import hookimpl # noqa: F401
from .types import CondaVirtualPackage, CondaSubcommand # noqa: F401
8 changes: 3 additions & 5 deletions conda/plugins/hookspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import pluggy

from ..models.plugins import CondaSubcommand, CondaVirtualPackage
from .types import CondaSubcommand, CondaVirtualPackage

spec_name = "conda"
_hookspec = pluggy.HookspecMarker(spec_name)
Expand All @@ -28,7 +28,6 @@ def conda_subcommands(self) -> Iterable[CondaSubcommand]:
.. code-block:: python
from conda import plugins
from conda.models.plugins import CondaSubcommand
def example_command(args):
Expand All @@ -37,7 +36,7 @@ def example_command(args):
@plugins.hookimpl
def conda_subcommands():
yield CondaSubcommand(
yield plugins.CondaSubcommand(
name="example",
summary="example command",
action=example_command,
Expand All @@ -56,12 +55,11 @@ def conda_virtual_packages(self) -> Iterable[CondaVirtualPackage]:
.. code-block:: python
from conda import plugins
from conda.models.plugins import CondaVirtualPackage
@plugins.hookimpl
def conda_virtual_packages():
yield CondaVirtualPackage(
yield plugins.CondaVirtualPackage(
name="my_custom_os",
version="1.2.3",
)
Expand Down
2 changes: 2 additions & 0 deletions conda/models/plugins.py → conda/plugins/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class CondaSubcommand(NamedTuple):
:param summary: Subcommand summary, will be shown in ``conda --help``.
:param action: Callable that will be run when the subcommand is invoked.
"""

name: str
summary: str
action: Callable[
Expand All @@ -28,5 +29,6 @@ class CondaVirtualPackage(NamedTuple):
:param name: Virtual package name (e.g., ``my_custom_os``).
:param version: Virtual package version (e.g., ``1.2.3``).
"""

name: str
version: str | None
8 changes: 3 additions & 5 deletions conda/plugins/virtual_packages/archspec.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
# Copyright (C) 2012 Anaconda, Inc
# SPDX-License-Identifier: BSD-3-Clause
from .. import hookimpl, CondaVirtualPackage

from conda import plugins
from conda.models.plugins import CondaVirtualPackage


@plugins.hookimpl
@hookimpl
def conda_virtual_packages():
from conda.core.index import get_archspec_name
from ...core.index import get_archspec_name

yield CondaVirtualPackage("archspec", get_archspec_name())
8 changes: 3 additions & 5 deletions conda/plugins/virtual_packages/cuda.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
# Copyright (C) 2012 Anaconda, Inc
# SPDX-License-Identifier: BSD-3-Clause

import ctypes
import functools
import platform
from contextlib import suppress

from conda import plugins
from conda.common.decorators import env_override
from conda.models.plugins import CondaVirtualPackage
from ...common.decorators import env_override
from .. import hookimpl, CondaVirtualPackage


@env_override("CONDA_OVERRIDE_CUDA", convert_empty_to_none=True)
Expand Down Expand Up @@ -84,6 +82,6 @@ def cached_cuda_version():
return cuda_version()


@plugins.hookimpl
@hookimpl
def conda_virtual_packages():
yield CondaVirtualPackage("cuda", cached_cuda_version())
8 changes: 3 additions & 5 deletions conda/plugins/virtual_packages/linux.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
# Copyright (C) 2012 Anaconda, Inc
# SPDX-License-Identifier: BSD-3-Clause

import os
import platform
import re

from conda import plugins
from conda.common._os.linux import linux_get_libc_version
from conda.models.plugins import CondaVirtualPackage
from ...common._os.linux import linux_get_libc_version
from .. import hookimpl, CondaVirtualPackage


@plugins.hookimpl
@hookimpl
def conda_virtual_packages():
if platform.system() != "Linux":
return
Expand Down
6 changes: 2 additions & 4 deletions conda/plugins/virtual_packages/osx.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
# Copyright (C) 2012 Anaconda, Inc
# SPDX-License-Identifier: BSD-3-Clause

import os
import platform

from conda import plugins
from conda.models.plugins import CondaVirtualPackage
from .. import hookimpl, CondaVirtualPackage


@plugins.hookimpl
@hookimpl
def conda_virtual_packages():
if platform.system() != "Darwin":
return
Expand Down
5 changes: 2 additions & 3 deletions conda/plugins/virtual_packages/windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@

import platform

from conda import plugins
from conda.models.plugins import CondaVirtualPackage
from .. import hookimpl, CondaVirtualPackage


@plugins.hookimpl
@hookimpl
def conda_virtual_packages():
if platform.system() != "Windows":
return
Expand Down
2 changes: 1 addition & 1 deletion docs/source/dev-guide/plugins/subcommands.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ The conda CLI can be extended with the ``conda_subcommands`` plugin hook.
Registered subcommands will be available under the ``conda <subcommand>``
command.

.. autoclass:: conda.models.plugins.CondaSubcommand
.. autoclass:: conda.plugins.types.CondaSubcommand
:members:
:undoc-members:

Expand Down
2 changes: 1 addition & 1 deletion docs/source/dev-guide/plugins/virtual_packages.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ the plugin system. This mechanism lets users write plugins that provide
version identification for proprieties only known at runtime (e.g., OS
information).

.. autoclass:: conda.models.plugins.CondaVirtualPackage
.. autoclass:: conda.plugins.types.CondaVirtualPackage
:members:
:undoc-members:

Expand Down
2 changes: 1 addition & 1 deletion tests/plugins/test_subcommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# SPDX-License-Identifier: BSD-3-Clause
import pytest
from conda import plugins
from conda.models.plugins import CondaSubcommand
from conda.plugins.types import CondaSubcommand


class SubcommandPlugin:
Expand Down
2 changes: 1 addition & 1 deletion tests/plugins/test_virtual_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from conda.common.io import env_var
from conda.exceptions import PluginError
from conda.base.context import context
from conda.models.plugins import CondaVirtualPackage
from conda.plugins.types import CondaVirtualPackage
from conda.testing.solver_helpers import package_dict
from conda import plugins
from conda.plugins.virtual_packages import cuda
Expand Down

0 comments on commit 3f8db55

Please sign in to comment.