Skip to content

Commit

Permalink
fix: class menu and push_counter
Browse files Browse the repository at this point in the history
  • Loading branch information
Yazawazi committed Jul 15, 2024
1 parent 335f425 commit 9363bf5
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 18 deletions.
29 changes: 12 additions & 17 deletions backend/funix/decorator/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,19 +308,22 @@ def decorator(function: Callable) -> callable:
if disable:
return function
if __wrapper_enabled:
if menu:
push_counter(app_.name, menu)
elif now_module:
push_counter(app_.name, now_module)
else:
push_counter(app_.name, "$Funix_Main")

function_id = str(uuid4())

if default:
set_default_function(app_.name, function_id)

safe_module_now = now_module
safe_module_now = now_module if now_module else menu

replace_module = None

if safe_module_now:
replace_module = safe_module_now

if safe_module_now:
push_counter(app_.name, safe_module_now)
else:
push_counter(app_.name, "$Funix_Main")

if safe_module_now:
safe_module_now = funix_menu_to_safe_function_name(safe_module_now)
Expand Down Expand Up @@ -349,7 +352,7 @@ def decorator(function: Callable) -> callable:

if safe_module_now:
unique_function_name = (
now_module.replace(".", "/") + "/" + function_name
safe_module_now.replace(".", "/") + "/" + function_name
)

if function_name in banned_function_name_and_path:
Expand Down Expand Up @@ -410,14 +413,6 @@ def decorator(function: Callable) -> callable:

secret_key = get_secret_by_id(function_id) is not None

replace_module = None

if now_module:
replace_module = now_module

if menu:
replace_module = menu

if unique_function_name:
__decorated_functions_names_list.append(unique_function_name)
else:
Expand Down
2 changes: 1 addition & 1 deletion backend/funix/decorator/lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def push_counter(app_name: str, module: str) -> None:
"""
global module_functions_counter
if app_name in module_functions_counter:
if module in module_functions_counter:
if module in module_functions_counter[app_name]:
module_functions_counter[app_name][module] += 1
else:
module_functions_counter[app_name][module] = 1
Expand Down
11 changes: 11 additions & 0 deletions backend/funix/decorator/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,17 @@ def visit_FunctionDef(self, node: FunctionDef):
)
)

funix_decorator.keywords.append(
keyword(
arg="menu",
value=Constant(
value=self._cls_name.replace("_", " ")
if GlobalSwitchOption.AUTO_CONVERT_UNDERSCORE_TO_SPACE_IN_NAME
else self._cls_name
),
)
)

if not is_static_method:
# Yes .args
args.args.pop(0)
Expand Down

0 comments on commit 9363bf5

Please sign in to comment.