Skip to content

Commit

Permalink
fix: circular import
Browse files Browse the repository at this point in the history
  • Loading branch information
Yazawazi committed Feb 28, 2024
1 parent 61e8517 commit 9bb9a0f
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 41 deletions.
3 changes: 1 addition & 2 deletions backend/funix/config/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
It's a global switch for quick turning on/off some key features in Funix.
"""

from dataclasses import dataclass
from secrets import token_hex
from typing import Union


class SwitchOption(dataclass):
class SwitchOption:
"""Switch option."""

AUTO_CONVERT_UNDERSCORE_TO_SPACE_IN_NAME: bool = True
Expand Down
15 changes: 7 additions & 8 deletions backend/funix/decorator/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@

from flask import Response, request, session
from funix.decorator.layout import handle_input_layout, handle_output_layout
from funix.decorator.magic import (
parse_function_annotation,
get_type_widget_prop,
get_type_dict,
anal_function_result,
function_param_to_widget,
)
from funix.decorator.pre_fill import parse_pre_fill, get_pre_fill_metadata
from funix.decorator.widget import widget_parse, parse_widget
from requests import post
Expand Down Expand Up @@ -47,14 +54,6 @@
push_counter,
set_default_function,
)
from funix.decorator.magic import (
anal_function_result,
convert_row_item,
function_param_to_widget,
get_type_dict,
get_type_widget_prop,
parse_function_annotation,
)
from funix.decorator.reactive import function_reactive_update, get_reactive_config
from funix.decorator.runtime import RuntimeClassVisitor
from funix.decorator.theme import (
Expand Down
2 changes: 1 addition & 1 deletion backend/funix/decorator/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from flask import abort, send_file

from funix import create_safe_tempdir
from funix.util.file import create_safe_tempdir
from funix.app import app
from funix.config.switch import GlobalSwitchOption
from funix.util.uri import is_valid_uri
Expand Down
19 changes: 18 additions & 1 deletion backend/funix/decorator/layout.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,24 @@
"""
Layout decorator
"""
from funix.decorator import convert_row_item


def convert_row_item(row_item: dict, item_type: str) -> dict:
"""
Convert a layout row item(block) to frontend-readable item.
Parameters:
row_item (dict): The row item.
item_type (str): The item type.
Returns:
dict: The converted item.
"""
converted_item = row_item
converted_item["type"] = item_type
converted_item["content"] = row_item[item_type]
converted_item.pop(item_type)
return converted_item


def handle_input_layout(input_layout: list) -> (list, dict):
Expand Down
29 changes: 6 additions & 23 deletions backend/funix/decorator/magic.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
ipython_type_convert_dict,
dataframe_convert_dict,
)
from funix.decorator import analyze, get_static_uri, handle_ipython_audio_image_video
from funix.decorator.annnotation_analyzer import analyze
from funix.decorator.file import get_static_uri, handle_ipython_audio_image_video

__matplotlib_use = False
"""
Expand Down Expand Up @@ -75,10 +76,10 @@ def get_type_dict(annotation: any) -> dict:
>>> import typing
>>> from funix.decorator.magic import get_type_dict
>>>
>>> get_type_dict(int) == {"type": "int"}
>>> get_type_dict(type(True)) == {"type": "bool"}
>>> get_type_dict(typing.Literal["a", "b", "c"]) == {'type': 'str', 'whitelist': ('a', 'b', 'c')}
>>> get_type_dict(typing.Optional[int]) == {'optional': True, 'type': 'int'}
>>> assert get_type_dict(int) == {"type": "int"}
>>> assert get_type_dict(type(True)) == {"type": "bool"}
>>> assert get_type_dict(typing.Literal["a", "b", "c"]) == {'type': 'str', 'whitelist': ('a', 'b', 'c')}
>>> assert get_type_dict(typing.Optional[int]) == {'optional': True, 'type': 'int'}
Returns:
dict: The type dict.
Expand Down Expand Up @@ -266,24 +267,6 @@ def get_type_widget_prop(
return {"type": "object", "widget": widget}


def convert_row_item(row_item: dict, item_type: str) -> dict:
"""
Convert a layout row item(block) to frontend-readable item.
Parameters:
row_item (dict): The row item.
item_type (str): The item type.
Returns:
dict: The converted item.
"""
converted_item = row_item
converted_item["type"] = item_type
converted_item["content"] = row_item[item_type]
converted_item.pop(item_type)
return converted_item


def funix_param_to_widget(annotation: any) -> str:
"""
Convert the funix parameter annotation to widget.
Expand Down
4 changes: 0 additions & 4 deletions backend/funix/prep/global_to_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,11 @@
"""

from _ast import (
AST,
Assign,
Attribute,
Call,
Constant,
Expr,
FunctionDef,
Global,
List,
Load,
Module,
Name,
Expand Down
3 changes: 1 addition & 2 deletions backend/funix/util/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from uuid import uuid4

from funix import decorator, hint
from funix.decorator import funix, funix_class


def getsourcefile_safe(obj: Any) -> str | None:
Expand Down Expand Up @@ -111,7 +110,7 @@ def handle_module(
)
if in_funix:
continue
use_func = funix if is_func else funix_class
use_func = decorator.funix if is_func else decorator.funix_class
if member.startswith("__") or member.startswith("_FUNIX_"):
continue
if need_path:
Expand Down

0 comments on commit 9bb9a0f

Please sign in to comment.