pluginify 1.0.0.post16.dev0__py3-none-any.whl → 1.0.0.post41.dev0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pluginify/__init__.py +15 -2
- pluginify/_version.py +2 -2
- pluginify/commandline_typer.py +21 -19
- pluginify/config.py +18 -11
- pluginify/create_plugin_registries.py +162 -104
- pluginify/errors.py +11 -3
- pluginify/interfaces/__init__.py +10 -1
- pluginify/interfaces/base.py +168 -100
- pluginify/interfaces/class_based/data_modifiers.py +4 -1
- pluginify/interfaces/class_based_plugin.py +167 -63
- pluginify/interfaces/yaml_based/configs.py +2 -0
- pluginify/plugin_registry.py +213 -172
- pluginify/plugins/classes/data_modifiers/cuboid.py +10 -8
- pluginify/pydantic_models/v1/configs.py +8 -2
- pluginify/utils/__init__.py +37 -17
- pluginify/utils/context_managers.py +18 -6
- pluginify/utils/validators.py +87 -14
- {pluginify-1.0.0.post16.dev0.dist-info → pluginify-1.0.0.post41.dev0.dist-info}/METADATA +3 -1
- pluginify-1.0.0.post41.dev0.dist-info/RECORD +23 -0
- pluginify-1.0.0.post16.dev0.dist-info/RECORD +0 -23
- {pluginify-1.0.0.post16.dev0.dist-info → pluginify-1.0.0.post41.dev0.dist-info}/WHEEL +0 -0
- {pluginify-1.0.0.post16.dev0.dist-info → pluginify-1.0.0.post41.dev0.dist-info}/entry_points.txt +0 -0
- {pluginify-1.0.0.post16.dev0.dist-info → pluginify-1.0.0.post41.dev0.dist-info}/licenses/LICENSE +0 -0
pluginify/__init__.py
CHANGED
|
@@ -1,10 +1,23 @@
|
|
|
1
1
|
# # # This source code is subject to the license referenced at
|
|
2
2
|
# # # https://github.com/NRLMMD-GEOIPS.
|
|
3
3
|
|
|
4
|
-
"""Pluginify
|
|
4
|
+
"""Pluginify: plugin registry management for YAML and Python class plugins.
|
|
5
|
+
|
|
6
|
+
This package provides the ``PluginRegistry`` class and supporting infrastructure
|
|
7
|
+
for registering, retrieving, and creating plugin objects from YAML configuration
|
|
8
|
+
files and Python class definitions. It exposes:
|
|
9
|
+
|
|
10
|
+
- ``pluginify.interfaces`` — base classes for building custom plugin interfaces.
|
|
11
|
+
- ``pluginify.utils`` — utility functions (dict merging, validators).
|
|
12
|
+
|
|
13
|
+
Pluginify does not ship production plugins; it is a framework for packages that
|
|
14
|
+
build plugin-based infrastructure (e.g. GeoIPS).
|
|
15
|
+
|
|
16
|
+
Version information is auto-generated from git tags during build/install.
|
|
17
|
+
"""
|
|
5
18
|
|
|
6
19
|
# NOTE: _version.py is generated automatically during build/install
|
|
7
|
-
from ._version import __version__, __version_tuple__
|
|
20
|
+
from pluginify._version import __version__, __version_tuple__
|
|
8
21
|
from pluginify import interfaces
|
|
9
22
|
from pluginify import utils
|
|
10
23
|
|
pluginify/_version.py
CHANGED
pluginify/commandline_typer.py
CHANGED
|
@@ -23,7 +23,7 @@ import os
|
|
|
23
23
|
from pathlib import Path
|
|
24
24
|
from platformdirs import user_config_dir
|
|
25
25
|
import sys
|
|
26
|
-
from typing import
|
|
26
|
+
from typing import Any, Callable, Literal
|
|
27
27
|
|
|
28
28
|
import docstring_parser
|
|
29
29
|
import typer
|
|
@@ -33,7 +33,7 @@ from pluginify.config import NAMESPACE
|
|
|
33
33
|
from pluginify.plugin_registry import PluginRegistry
|
|
34
34
|
|
|
35
35
|
|
|
36
|
-
def configure_logging(level=logging.INFO):
|
|
36
|
+
def configure_logging(level: int = logging.INFO) -> None:
|
|
37
37
|
"""Configure root logging for the command-line interface.
|
|
38
38
|
|
|
39
39
|
This function attaches a StreamHandler to the root logger so that all log
|
|
@@ -71,12 +71,12 @@ def configure_logging(level=logging.INFO):
|
|
|
71
71
|
root.addHandler(handler)
|
|
72
72
|
|
|
73
73
|
|
|
74
|
-
def update_existing_fields(new_data):
|
|
74
|
+
def update_existing_fields(new_data: dict) -> None:
|
|
75
75
|
"""Overwrite fields in pluginify's config file if they exist in 'new_data'.
|
|
76
76
|
|
|
77
77
|
Parameters
|
|
78
78
|
----------
|
|
79
|
-
new_data: dict
|
|
79
|
+
new_data : dict
|
|
80
80
|
A dictionary containing configuration key, value pairs to overwrite data in
|
|
81
81
|
config_path.
|
|
82
82
|
"""
|
|
@@ -118,11 +118,11 @@ class DocstringTyper(typer.Typer):
|
|
|
118
118
|
'--namespace' automatically generates a '-n' flag.
|
|
119
119
|
"""
|
|
120
120
|
|
|
121
|
-
def command(self, *args, **kwargs):
|
|
121
|
+
def command(self, *args: Any, **kwargs: Any) -> Callable:
|
|
122
122
|
"""Overridden typer.Typer:command decorator."""
|
|
123
123
|
decorator = super().command(*args, **kwargs)
|
|
124
124
|
|
|
125
|
-
def wrapper(func):
|
|
125
|
+
def wrapper(func: Callable) -> Callable:
|
|
126
126
|
"""Generate help messages and shorthand aliases for all args of func."""
|
|
127
127
|
sig = inspect.signature(func)
|
|
128
128
|
doc = docstring_parser.parse(func.__doc__ or "")
|
|
@@ -136,7 +136,9 @@ class DocstringTyper(typer.Typer):
|
|
|
136
136
|
|
|
137
137
|
# Keep examples portion in command's help output if specified
|
|
138
138
|
if doc.examples:
|
|
139
|
-
new_doc += "\n\nExamples\n--------\n" +
|
|
139
|
+
new_doc += "\n\nExamples\n--------\n" + (
|
|
140
|
+
doc.examples[0].description or ""
|
|
141
|
+
)
|
|
140
142
|
|
|
141
143
|
func.__doc__ = new_doc
|
|
142
144
|
|
|
@@ -164,7 +166,7 @@ class DocstringTyper(typer.Typer):
|
|
|
164
166
|
new_params.append(param.replace(default=option))
|
|
165
167
|
|
|
166
168
|
new_sig = sig.replace(parameters=new_params)
|
|
167
|
-
func.__signature__ = new_sig
|
|
169
|
+
func.__signature__ = new_sig # type: ignore[attr-defined]
|
|
168
170
|
|
|
169
171
|
return decorator(func)
|
|
170
172
|
|
|
@@ -202,7 +204,7 @@ config_app.add_typer(
|
|
|
202
204
|
@app.command()
|
|
203
205
|
def create(
|
|
204
206
|
namespace: str = NAMESPACE,
|
|
205
|
-
packages:
|
|
207
|
+
packages: list[str] | None = None,
|
|
206
208
|
save_type: Literal["json", "yaml"] = "json",
|
|
207
209
|
):
|
|
208
210
|
"""Create plugin registries.
|
|
@@ -239,12 +241,12 @@ def create(
|
|
|
239
241
|
|
|
240
242
|
Parameters
|
|
241
243
|
----------
|
|
242
|
-
namespace: str, default='pluginify.plugin_packages'
|
|
244
|
+
namespace : str, default='pluginify.plugin_packages'
|
|
243
245
|
The namespace which plugin packages are registered under.
|
|
244
|
-
packages:
|
|
246
|
+
packages : list[str] | None, default=None
|
|
245
247
|
A list of strings representing plugin packages to create registries for. If
|
|
246
248
|
None, create registry files for all plugin packages found under 'namespace'.
|
|
247
|
-
save_type: Literal['json', 'yaml'], default='json'
|
|
249
|
+
save_type : Literal['json', 'yaml'], default='json'
|
|
248
250
|
The file extension to save the registry files as. Defaults to 'json', 'yaml'
|
|
249
251
|
can be specified as well.
|
|
250
252
|
"""
|
|
@@ -255,7 +257,7 @@ def create(
|
|
|
255
257
|
@app.command()
|
|
256
258
|
def delete(
|
|
257
259
|
namespace: str = NAMESPACE,
|
|
258
|
-
packages:
|
|
260
|
+
packages: list[str] | None = None,
|
|
259
261
|
):
|
|
260
262
|
"""Delete plugin registries.
|
|
261
263
|
|
|
@@ -289,9 +291,9 @@ def delete(
|
|
|
289
291
|
|
|
290
292
|
Parameters
|
|
291
293
|
----------
|
|
292
|
-
namespace: str, default='pluginify.plugin_packages'
|
|
294
|
+
namespace : str, default='pluginify.plugin_packages'
|
|
293
295
|
The namespace which plugin packages are registered under.
|
|
294
|
-
packages:
|
|
296
|
+
packages : list[str] | None, default=None
|
|
295
297
|
A list of strings representing plugin packages to create registries for. If
|
|
296
298
|
None, create registry files for all plugin packages found under 'namespace'.
|
|
297
299
|
"""
|
|
@@ -305,7 +307,7 @@ def set_rebuild_registries(rebuild_registries: bool):
|
|
|
305
307
|
|
|
306
308
|
Parameters
|
|
307
309
|
----------
|
|
308
|
-
rebuild_registries: bool
|
|
310
|
+
rebuild_registries : bool
|
|
309
311
|
The default setting for whether or not pluginify should rebuild registries by
|
|
310
312
|
default. This will persist between terminal sessions if set.
|
|
311
313
|
"""
|
|
@@ -318,7 +320,7 @@ def set_namespace(namespace: str):
|
|
|
318
320
|
|
|
319
321
|
Parameters
|
|
320
322
|
----------
|
|
321
|
-
namespace: str
|
|
323
|
+
namespace : str
|
|
322
324
|
The default namespace you want to pluginify to operate on. This will persist
|
|
323
325
|
between terminal sessions if set.
|
|
324
326
|
"""
|
|
@@ -331,14 +333,14 @@ def set_registry_directory(registry_directory: Path):
|
|
|
331
333
|
|
|
332
334
|
Parameters
|
|
333
335
|
----------
|
|
334
|
-
registry_directory: Path
|
|
336
|
+
registry_directory : Path
|
|
335
337
|
The default path to the directory you want to write registry files to. This will
|
|
336
338
|
persist between terminal sessions if set.
|
|
337
339
|
"""
|
|
338
340
|
update_existing_fields({"REGISTRY_DIRECTORY": registry_directory})
|
|
339
341
|
|
|
340
342
|
|
|
341
|
-
def main():
|
|
343
|
+
def main() -> None:
|
|
342
344
|
"""Entrypoint function for pluginify's CLI."""
|
|
343
345
|
configure_logging(logging.INFO)
|
|
344
346
|
app()
|
pluginify/config.py
CHANGED
|
@@ -3,13 +3,18 @@
|
|
|
3
3
|
|
|
4
4
|
"""Module containing configuration variables needed for pluginify to run."""
|
|
5
5
|
|
|
6
|
+
from __future__ import annotations
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
from typing import Any
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def _get_env_name() -> str:
|
|
8
13
|
"""Determine the name of the environment that this code is being executed under.
|
|
9
14
|
|
|
10
15
|
Returns
|
|
11
16
|
-------
|
|
12
|
-
env_name: str
|
|
17
|
+
env_name : str
|
|
13
18
|
The name of the environment which was active when this code was ran. If running
|
|
14
19
|
under the base environment, return 'base_env'.
|
|
15
20
|
"""
|
|
@@ -35,7 +40,7 @@ def _get_env_name():
|
|
|
35
40
|
return env_name
|
|
36
41
|
|
|
37
42
|
|
|
38
|
-
def _env_to_variable(name, default):
|
|
43
|
+
def _env_to_variable(name: str, default: Any) -> Any:
|
|
39
44
|
"""Convert an environment variable (str) to a python variable (Any).
|
|
40
45
|
|
|
41
46
|
If an environment variable under 'name' has been set, convert it to a python
|
|
@@ -44,14 +49,14 @@ def _env_to_variable(name, default):
|
|
|
44
49
|
|
|
45
50
|
Parameters
|
|
46
51
|
----------
|
|
47
|
-
name: str
|
|
52
|
+
name : str
|
|
48
53
|
The name of the environment variable to convert.
|
|
49
|
-
default: Any
|
|
54
|
+
default : Any
|
|
50
55
|
The default value for the environment variable named 'name'..
|
|
51
56
|
|
|
52
57
|
Returns
|
|
53
58
|
-------
|
|
54
|
-
converted: Any
|
|
59
|
+
converted : Any
|
|
55
60
|
- The converted value of the environment variable.
|
|
56
61
|
"""
|
|
57
62
|
# imports buried to avoid polluting this module's import namespace
|
|
@@ -72,7 +77,7 @@ def _env_to_variable(name, default):
|
|
|
72
77
|
return default
|
|
73
78
|
|
|
74
79
|
|
|
75
|
-
def _load_config_values():
|
|
80
|
+
def _load_config_values() -> tuple[str, bool, Path]:
|
|
76
81
|
"""Load and override pluginify configuration variables if they exist.
|
|
77
82
|
|
|
78
83
|
The configuration file for this package is expected to be found at
|
|
@@ -120,26 +125,28 @@ def _load_config_values():
|
|
|
120
125
|
return NAMESPACE, REBUILD_REGISTRIES, REGISTRY_DIRECTORY
|
|
121
126
|
|
|
122
127
|
|
|
128
|
+
# These module-level variables are resolved at import time from env vars,
|
|
129
|
+
# config file (~/.config/pluginify/config.yaml), and built-in defaults.
|
|
123
130
|
NAMESPACE, REBUILD_REGISTRIES, REGISTRY_DIRECTORY = _load_config_values()
|
|
124
131
|
|
|
125
132
|
|
|
126
|
-
def get_registry_cache_dir(namespace, package):
|
|
133
|
+
def get_registry_cache_dir(namespace: str, package: str) -> Path:
|
|
127
134
|
"""Return the path to the parent directory of where to write registry files to.
|
|
128
135
|
|
|
129
136
|
Where the path is formatted '~/.cache/{env_name}/{namespace}/{package}'.
|
|
130
137
|
|
|
131
138
|
Parameters
|
|
132
139
|
----------
|
|
133
|
-
namespace: str
|
|
140
|
+
namespace : str
|
|
134
141
|
Namespace that your plugin packages fall under. The argument parser defaults
|
|
135
142
|
this value to 'pluginify.plugin_packages', but a user can create separate
|
|
136
143
|
namespaces if developing interfaces outside of pluginify.
|
|
137
|
-
package: str
|
|
144
|
+
package : str
|
|
138
145
|
Name of a plugin package that is registered under 'namespace'.
|
|
139
146
|
|
|
140
147
|
Returns
|
|
141
148
|
-------
|
|
142
|
-
cache_dir: Path
|
|
149
|
+
cache_dir : Path
|
|
143
150
|
Full path to the parent directory in which registry files should be written
|
|
144
151
|
for a package under namespace.
|
|
145
152
|
"""
|