regorator 0.1__tar.gz → 0.1.1__tar.gz
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.
- {regorator-0.1 → regorator-0.1.1}/PKG-INFO +2 -2
- {regorator-0.1 → regorator-0.1.1}/pyproject.toml +1 -1
- regorator-0.1.1/regorator/__init__.py +2 -0
- regorator-0.1.1/regorator/core/__init__.py +1 -0
- regorator-0.1.1/regorator/core/main.py +87 -0
- {regorator-0.1 → regorator-0.1.1}/regorator/version.py +1 -1
- {regorator-0.1 → regorator-0.1.1}/regorator.egg-info/PKG-INFO +2 -2
- {regorator-0.1 → regorator-0.1.1}/regorator.egg-info/SOURCES.txt +3 -1
- regorator-0.1/regorator/__init__.py +0 -2
- {regorator-0.1 → regorator-0.1.1}/README.md +0 -0
- {regorator-0.1 → regorator-0.1.1}/regorator.egg-info/dependency_links.txt +0 -0
- {regorator-0.1 → regorator-0.1.1}/regorator.egg-info/top_level.txt +0 -0
- {regorator-0.1 → regorator-0.1.1}/setup.cfg +0 -0
|
@@ -35,7 +35,7 @@ classifiers = [
|
|
|
35
35
|
Homepage = "https://github.com/pedrohenriquecoimbra/regorator"
|
|
36
36
|
|
|
37
37
|
[tool.setuptools]
|
|
38
|
-
packages = ["regorator"]
|
|
38
|
+
packages = ["regorator", "regorator.core"]
|
|
39
39
|
exclude-package-data = { "regorator" = ["deprecated*"] }
|
|
40
40
|
include-package-data = true
|
|
41
41
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from . import main
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import types
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def create_registry(desc=""):
|
|
5
|
+
"""Create a new registry dictionary."""
|
|
6
|
+
return regdict({}, __doc__=desc)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class regdict(dict):
|
|
10
|
+
"""A dict that supports a custom __doc__ attribute."""
|
|
11
|
+
|
|
12
|
+
def __init__(self, *args, __name__=None, __doc__=None, **kwargs):
|
|
13
|
+
super().__init__(*args, **kwargs)
|
|
14
|
+
if __doc__:
|
|
15
|
+
self.__doc__ = __doc__
|
|
16
|
+
if __name__:
|
|
17
|
+
self.__name__ = __name__
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def register(name: str, registry, description: str = ""):
|
|
21
|
+
"""Decorator to register a function in a given registry."""
|
|
22
|
+
def decorator(func):
|
|
23
|
+
func._correction_name = name
|
|
24
|
+
func._description = description or "No description provided"
|
|
25
|
+
registry[name] = func
|
|
26
|
+
return func
|
|
27
|
+
return decorator
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class Register:
|
|
31
|
+
"""
|
|
32
|
+
Base class for bricks that require registration.
|
|
33
|
+
"""
|
|
34
|
+
|
|
35
|
+
def __init__(self):
|
|
36
|
+
# Each instance gets its own registry
|
|
37
|
+
self.registry = create_registry()
|
|
38
|
+
|
|
39
|
+
def register(cls, name: str, description: str = ""):
|
|
40
|
+
"""Class method that wraps the register decorator for the class's registry."""
|
|
41
|
+
def decorator(func):
|
|
42
|
+
return register(name, cls.registry, description)(func)
|
|
43
|
+
return decorator
|
|
44
|
+
|
|
45
|
+
@property
|
|
46
|
+
def available(self):
|
|
47
|
+
return self.registry
|
|
48
|
+
|
|
49
|
+
# @classmethod
|
|
50
|
+
def get(self, name):
|
|
51
|
+
"""Retrieve a registered method by name.
|
|
52
|
+
Args:
|
|
53
|
+
name (str): The name of the method.
|
|
54
|
+
Raises:
|
|
55
|
+
KeyError: If the method is not registered.
|
|
56
|
+
"""
|
|
57
|
+
meth = self.available.get(
|
|
58
|
+
name, None)
|
|
59
|
+
|
|
60
|
+
if meth is None:
|
|
61
|
+
raise KeyError(
|
|
62
|
+
f"Method '{name}' is not registered.",
|
|
63
|
+
"Check metadata or make sure the method is registered (if custom method).")
|
|
64
|
+
return meth
|
|
65
|
+
|
|
66
|
+
# @classmethod
|
|
67
|
+
def add_method(self, name, how=None):
|
|
68
|
+
"""Decorator to add a method dynamically to a class."""
|
|
69
|
+
def decorator(func):
|
|
70
|
+
# Dynamically add the function to the class
|
|
71
|
+
if how == 'classmethod':
|
|
72
|
+
method = classmethod(func)
|
|
73
|
+
elif how == 'static':
|
|
74
|
+
method = func
|
|
75
|
+
else:
|
|
76
|
+
method = types.MethodType(func, self)
|
|
77
|
+
setattr(self, name, method)
|
|
78
|
+
return self
|
|
79
|
+
return decorator
|
|
80
|
+
|
|
81
|
+
def apply(self, data, **kwargs):
|
|
82
|
+
"""
|
|
83
|
+
Apply the correction routine to the provided data.
|
|
84
|
+
Must be overridden by subclasses.
|
|
85
|
+
"""
|
|
86
|
+
raise NotImplementedError(
|
|
87
|
+
"Each correction module must implement an apply() method.")
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|