Skip to content

Commit e2dd83a

Browse files
brettimusBrett Beutell
and
Brett Beutell
authored
Admin panel bookkeeping (#43)
* Keep track of all the functions we decorate --------- Co-authored-by: Brett Beutell <brett@fiberplane.com>
1 parent 7ec7ee6 commit e2dd83a

File tree

4 files changed

+28
-0
lines changed

4 files changed

+28
-0
lines changed

src/autometrics/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
from .decorator import *
2+
3+
from .admin_panel import *
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .function_registry import register_function_info, get_decorated_functions_list
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# This module will do some bookkeeping on information of any functions that have been wrapped by autometrics decorators
2+
3+
from typing import List, TypedDict
4+
5+
6+
class FunctionInfo(TypedDict):
7+
name: str
8+
module: str
9+
10+
11+
FUNCTION_REGISTRY: List[FunctionInfo] = []
12+
13+
14+
def register_function_info(func_name: str, module_name: str):
15+
global FUNCTION_REGISTRY
16+
function_info: FunctionInfo = {"name": func_name, "module": module_name}
17+
FUNCTION_REGISTRY.append(function_info)
18+
19+
20+
def get_decorated_functions_list():
21+
global FUNCTION_REGISTRY
22+
return FUNCTION_REGISTRY

src/autometrics/decorator.py

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from typing_extensions import ParamSpec
88
from .objectives import Objective
99
from .tracker import get_tracker, Result
10+
from .admin_panel import register_function_info
1011
from .utils import get_module_name, get_caller_function, append_docs_to_docstring
1112

1213

@@ -68,6 +69,7 @@ def sync_decorator(func: Callable[P, T]) -> Callable[P, T]:
6869

6970
module_name = get_module_name(func)
7071
func_name = func.__name__
72+
register_function_info(func_name, module_name)
7173

7274
@wraps(func)
7375
def sync_wrapper(*args: P.args, **kwds: P.kwargs) -> T:
@@ -100,6 +102,7 @@ def async_decorator(func: Callable[P, Awaitable[T]]) -> Callable[P, Awaitable[T]
100102

101103
module_name = get_module_name(func)
102104
func_name = func.__name__
105+
register_function_info(func_name, module_name)
103106

104107
@wraps(func)
105108
async def async_wrapper(*args: P.args, **kwds: P.kwargs) -> T:

0 commit comments

Comments
 (0)