Skip to content

Commit

Permalink
install plugins working for 1 test
Browse files Browse the repository at this point in the history
  • Loading branch information
khiron committed Apr 4, 2024
1 parent 0fd6840 commit d2912c4
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 222 deletions.
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ dependencies = ["chardet",
"numba>=0.59.0; python_version=='3.12'",
"scipy",
"scitrack",
"stevedore",
"tqdm",
"typing_extensions",
"stevedore"]
"typing_extensions"]
# remember to update version in requires-python and classifiers
requires-python = ">=3.9,<3.13"
classifiers = [
Expand Down
56 changes: 15 additions & 41 deletions src/cogent3/app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
from .composable import is_app, is_app_composable
from .io import open_data_store


# from stevedore.extension import ExtensionManager

# Entry_point for apps to register themselves as plugins
APP_ENTRY_POINT = "cogent3.app"

def _get_extension_attr(extension):
"""
Expand Down Expand Up @@ -60,43 +59,32 @@ def _make_types(app) -> dict:
__apps = None


def apps(force: bool = False) -> stevedore.ExtensionManager:
def get_app_manager(force: bool = False) -> stevedore.ExtensionManager:
"""
Lazy load a stevedore ExtensionManager to collect apps.
Parameters
----------
force : bool, optional
If set to True, forces the re-creation of the ExtensionManager,
even if it already exists. Default is False.
Returns
-------
ExtensionManager
The ExtensionManager instance that collects apps.
Notes
-----
If force is set, the app_manager will refresh it's cache of apps.
"""
global __apps
if force:
importlib.invalidate_caches()
importlib.reload(stevedore)
stevedore.extension.ExtensionManager.ENTRY_POINT_CACHE.clear()
if APP_ENTRY_POINT in stevedore.extension.ExtensionManager.ENTRY_POINT_CACHE:
del stevedore.extension.ExtensionManager.ENTRY_POINT_CACHE[APP_ENTRY_POINT]
if not __apps or force:
__apps = stevedore.ExtensionManager(
namespace="cogent3.app", invoke_on_load=False
namespace=APP_ENTRY_POINT, invoke_on_load=False
)
return __apps


def available_apps(name_filter: str | None = None, force: bool = False) -> Table:
"""returns Table listing the available apps
Parameters
----------
name_filter
include apps whose name includes name_filter
force : bool, optional
If set to True, forces the re-creation of the ExtensionManager,
even if it already exists. Default is False.
Notes
-----
If force is set, the app_manager will refresh it's cache of apps.
"""
from cogent3.util.table import Table

Expand All @@ -105,7 +93,7 @@ def available_apps(name_filter: str | None = None, force: bool = False) -> Table

rows = []

extensions = apps(force)
extensions = get_app_manager(force)

for extension in extensions:
if any(extension.name.startswith(d) for d in deprecated):
Expand Down Expand Up @@ -189,7 +177,7 @@ def _get_app_matching_name(name: str):
else:
modname = None

extensions_matching = [extension for extension in apps() if extension.name == name]
extensions_matching = [extension for extension in get_app_manager() if extension.name == name]
if not extensions_matching:
raise ValueError(f"App {name!r} not found. Please check for typos.")

Expand All @@ -210,24 +198,10 @@ def _get_app_matching_name(name: str):
def get_app(_app_name: str, *args, **kwargs):
"""returns app instance, use app_help() to display arguments
Parameters
----------
_app_name
app name, e.g. 'minlength', or can include module information,
e.g. 'cogent3.app.sample.minlength' or 'sample.minlength'. Use the
latter (qualified class name) style when there are multiple matches
to name.
*args, **kwargs
positional and keyword arguments passed through to the app
Returns
-------
cogent3 app instance
Raises
------
NameError when multiple apps have the same name. In that case use a
qualified class name, as shown above.
qualified class name.
"""
return _get_app_matching_name(_app_name)(*args, **kwargs)

Expand Down
21 changes: 0 additions & 21 deletions tests/test_app/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,27 +137,6 @@ def test_app_help(capsys):
assert "Options" in got
assert got.count("bytes") >= 2 # both input and output types are bytes


@pytest.mark.xfail(reason="Constructing apps on the fly is no longer supported")
def test_app_help_doctest_examples(capsys):
app_doc = "A line of text describing the app."
init_doc = "\n Parameters\n ----------\n arg\n arg description\n\n Examples\n --------\n How to use the app\n\n >>>blah(arg)\n output\n"
blah.__doc__ = app_doc
blah.__init__.__doc__ = init_doc
app_help("blah")
got = capsys.readouterr().out
# Two new lines after the end of Parameters should be preserved
expect1 = "arg description\n\nExamples\n--------\n"
# Two new lines within Examples are preserved
expect2 = "How to use the app\n\n>>>blah(arg)\noutput\n"
# Two new lines at the end of Examples preserved
expect3 = "output\n\nInput type"

assert expect1 in got
assert expect2 in got
assert expect3 in got


@pytest.mark.parametrize(
"app_name", ("bootstrap", "from_primitive", "load_db", "take_named_seqs")[:1]
)
Expand Down
Loading

0 comments on commit d2912c4

Please sign in to comment.