Skip to content

Commit

Permalink
Adds inspect to write on callee module.
Browse files Browse the repository at this point in the history
  • Loading branch information
josead committed Sep 9, 2024
1 parent 5aaa196 commit f0047e8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
6 changes: 1 addition & 5 deletions examples/metacall_faas/main.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
from fasthtml_extn.deploy import deploy_metacall_faas

# Initialize __all__ as an empty list
__all__ = []

deploy_metacall_faas(__all__)

print(f"Exported functions: {__all__}")
deploy_metacall_faas()
17 changes: 13 additions & 4 deletions fasthtml_extn/deploy.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import inspect
from fasthtml.core import to_xml
from fasthtml_extn.libraries.tailwind import ExtnHtml
from fasthtml_extn.utils import create_metacall_app, get_metacall_app_path


pages = create_metacall_app()


Expand All @@ -17,19 +17,28 @@ def app():
return app


def deploy_metacall_faas(_all_):
def deploy_metacall_faas() -> list[str]:
"""
Discover functions in the module and add them to _all_
"""
frame = inspect.currentframe()
if frame is None:
raise RuntimeError(
"Cannot deploy functions in the module. Please call this function from a module."
)
caller_frame = frame.f_back
caller_module = inspect.getmodule(caller_frame)

_all_ = []
for page in pages:
app = pages[page]
route = app["route"]
function_name = f"app{route}"
print("Adding Function", function_name)
globals()[function_name] = _with_route(route)
setattr(caller_module, function_name, _with_route(route))
if function_name not in _all_:
_all_.append(function_name)
if "app" not in _all_:
globals()["app"] = _with_route("")
setattr(caller_module, "app", _with_route(""))
_all_.append("app")
return _all_
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "fasthtml_extn"
version = "0.0.2"
version = "0.0.3"
description = "An fasthtml extension framework to build webapps using python."
authors = ["Jose Antonio Dominguez <[email protected]>"]
readme = "README.md"
Expand Down

0 comments on commit f0047e8

Please sign in to comment.