-
Notifications
You must be signed in to change notification settings - Fork 7
feat: Register plugins through entry points #87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jlumpe
wants to merge
8
commits into
snakemake:main
Choose a base branch
from
jlumpe:entry-points
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d5c5188
Update PluginRegistryBase docs and reorder methods
jlumpe 9f7072d
Edits/fix to PluginRegistryBase.register_plugin()
jlumpe 6dec8ab
Change Python dependency to 3.11
jlumpe b23032d
Fix typing of PluginRegistryBase.__new__()
jlumpe fc9998c
Fix return type and err msg in PluginRegistryBase.get_plugin()
jlumpe a07bd6f
Add tests for registry
jlumpe c205193
Format test files in pixi task
jlumpe 1147efc
Register plugins through entry points
jlumpe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| # Make test dir a package to allow for relative imports |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| """Define example plugin type for testing.""" | ||
|
|
||
| from dataclasses import dataclass | ||
| from types import ModuleType | ||
| from pathlib import Path | ||
| from typing import Self | ||
|
|
||
| from snakemake_interface_common.plugin_registry import PluginRegistryBase | ||
| from snakemake_interface_common.plugin_registry.plugin import PluginBase, SettingsBase | ||
| from snakemake_interface_common.plugin_registry.attribute_types import ( | ||
| AttributeType, | ||
| AttributeMode, | ||
| AttributeKind, | ||
| ) | ||
|
|
||
|
|
||
| @dataclass | ||
| class ExamplePlugin(PluginBase): | ||
| _name: str | ||
| _settings_cls: type[SettingsBase] | None | ||
| file: Path | ||
| string_attr: str | ||
|
|
||
| @property | ||
| def name(self) -> str: | ||
| return self._name | ||
|
|
||
| @property | ||
| def cli_prefix(self) -> str: | ||
| return "example-plugin-" + self.name | ||
|
|
||
| @property | ||
| def settings_cls(self) -> type[SettingsBase] | None: | ||
| return self._settings_cls | ||
|
|
||
|
|
||
| class ExamplePluginRegistry(PluginRegistryBase[ExamplePlugin]): | ||
| @classmethod | ||
| def new(cls) -> Self: | ||
| """Create a new non-singleton instance for testing.""" | ||
| instance = object.__new__(cls) | ||
| instance.__init__() | ||
| return instance | ||
|
|
||
| @property | ||
| def module_prefix(self) -> str: | ||
| return "snakemake_example_plugin_" | ||
|
|
||
| @property | ||
| def entry_point(self) -> str: | ||
| return "example_plugins" | ||
|
|
||
| def load_plugin(self, name: str, module: ModuleType) -> ExamplePlugin: | ||
| settings_cls = getattr(module, "ExampleSettings", None) | ||
| string_attr = module.example_string | ||
|
|
||
| return ExamplePlugin( | ||
| _name=name, | ||
| _settings_cls=settings_cls, | ||
| file=Path(module.__file__), | ||
| string_attr=string_attr, | ||
| ) | ||
|
|
||
| def expected_attributes(self): | ||
| return { | ||
| "ExampleSettings": AttributeType( | ||
| cls=SettingsBase, | ||
| mode=AttributeMode.OPTIONAL, | ||
| kind=AttributeKind.CLASS, | ||
| ), | ||
| "example_string": AttributeType( | ||
| cls=str, | ||
| mode=AttributeMode.REQUIRED, | ||
| kind=AttributeKind.OBJECT, | ||
| ), | ||
| } |
7 changes: 7 additions & 0 deletions
7
tests/plugins/invalid-class/snakemake_example_plugin_invalid_class/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| """Plugin module with ExampleSettings class that does not inherit from correct base class.""" | ||
|
|
||
| example_string = "foo" | ||
|
|
||
|
|
||
| class ExampleSettings: | ||
| pass |
3 changes: 3 additions & 0 deletions
3
tests/plugins/invalid-object/snakemake_example_plugin_invalid_object/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| """Plugin module with wrong type for "example_string" attribute.""" | ||
|
|
||
| example_string = 1 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: snakemake/snakemake-interface-common
Length of output: 216
🌐 Web query:
snakemake-interface-common Python version requirement pyproject.toml💡 Result:
snakemake-interface-common requires Python >= 3.8. [1][2]
Sources:
🌐 Web query:
snakemake-interface-common dependencies typing_extensions pypi💡 Result:
Short answer: No — snakemake-interface-common on PyPI does not list typing_extensions as a dependency. See the PyPI project page and the Bioconda recipe (which lists its dependencies: argparse-dataclass, configargparse, packaging, python >=3.8). [1][2]
Sources:
Selfimport breaks backward compatibility with Python 3.8–3.10.The project requires Python >= 3.8, but
Self(imported fromtypingon line 20) was only added in Python 3.11. Users on Python 3.8–3.10 will encounter anImportErrorat runtime. Sincetyping_extensionsis not listed as a project dependency, use either:from typing_extensions import Selfwith a fallback for Python 3.11+, ortyping_extensionsas a dependency and import from there for consistency across all Python versions.🤖 Prompt for AI Agents