Start developing publish to static
This commit is contained in:
@@ -28,6 +28,7 @@ class SenseListPage(BasePage):
|
||||
)
|
||||
settings_button = flet.IconButton(
|
||||
icon=flet.icons.SETTINGS,
|
||||
visible=False,
|
||||
)
|
||||
logout_button = flet.IconButton(
|
||||
icon=flet.icons.LOGOUT,
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import asyncio
|
||||
import pathlib
|
||||
import subprocess
|
||||
|
||||
import typer
|
||||
|
||||
@@ -6,6 +8,19 @@ from . import web
|
||||
from .service import get_service
|
||||
|
||||
|
||||
def publish():
|
||||
current_path = pathlib.Path(__file__).parent
|
||||
root_path = current_path.parent.parent
|
||||
requirements_path = current_path / "requirements.txt"
|
||||
entrypoint_path = current_path / "entrypoint.py"
|
||||
dist_path = root_path / "dist"
|
||||
|
||||
subprocess.call(["poetry", "export", "-f", "requirements.txt", "--with", "ui", "--with", "main",
|
||||
"--without-hashes", "--output", str(requirements_path)])
|
||||
subprocess.call(["flet", "publish", "--pre", "--distpath", str(dist_path),
|
||||
str(entrypoint_path)])
|
||||
|
||||
|
||||
def run():
|
||||
ui_service = get_service()
|
||||
|
||||
@@ -16,6 +31,7 @@ def get_cli() -> typer.Typer:
|
||||
cli = typer.Typer()
|
||||
|
||||
cli.command(name="run")(run)
|
||||
cli.command(name="publish")(publish)
|
||||
cli.add_typer(web.get_cli(), name="web")
|
||||
|
||||
return cli
|
||||
|
||||
14
soul_diary/ui/entrypoint.py
Normal file
14
soul_diary/ui/entrypoint.py
Normal file
@@ -0,0 +1,14 @@
|
||||
import pathlib
|
||||
import sys
|
||||
|
||||
current_path = str(pathlib.Path(__file__).parent.absolute())
|
||||
if current_path not in sys.path:
|
||||
sys.path.append(current_path)
|
||||
|
||||
import flet
|
||||
|
||||
from app.app import SoulDiaryApp
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
flet.app(target=SoulDiaryApp().run)
|
||||
@@ -1,6 +1,6 @@
|
||||
from facet import ServiceMixin
|
||||
|
||||
from .web import WebService, WebSettings, get_service as get_web_service
|
||||
from .web import WebService, get_service as get_web_service
|
||||
|
||||
|
||||
class UIService(ServiceMixin):
|
||||
@@ -15,6 +15,5 @@ class UIService(ServiceMixin):
|
||||
|
||||
|
||||
def get_service() -> UIService:
|
||||
settings = WebSettings()
|
||||
web = get_web_service(settings=settings)
|
||||
web = get_web_service()
|
||||
return UIService(web=web)
|
||||
|
||||
@@ -2,27 +2,17 @@ import asyncio
|
||||
import typer
|
||||
|
||||
from .service import get_service
|
||||
from .settings import WebSettings, get_settings
|
||||
|
||||
|
||||
def run(ctx: typer.Context):
|
||||
settings: WebSettings = ctx.obj["settings"]
|
||||
def run():
|
||||
web_service = get_service()
|
||||
|
||||
loop = asyncio.get_event_loop()
|
||||
frontend_service = get_service(settings=settings)
|
||||
|
||||
loop.run_until_complete(frontend_service.run())
|
||||
|
||||
|
||||
def settings_callback(ctx: typer.Context):
|
||||
ctx.obj = ctx.obj or {}
|
||||
ctx.obj["settings"] = get_settings()
|
||||
asyncio.run(web_service.run())
|
||||
|
||||
|
||||
def get_cli() -> typer.Typer:
|
||||
cli = typer.Typer()
|
||||
|
||||
cli.callback()(settings_callback)
|
||||
cli.command(name="run")(run)
|
||||
|
||||
return cli
|
||||
|
||||
@@ -34,5 +34,6 @@ class WebService(ServiceMixin):
|
||||
self.add_task(server.serve())
|
||||
|
||||
|
||||
def get_service(settings: WebSettings) -> WebService:
|
||||
def get_service() -> WebService:
|
||||
settings = WebSettings()
|
||||
return WebService(port=settings.port, backend_data=settings.backend_data)
|
||||
|
||||
@@ -11,7 +11,3 @@ class WebSettings(BaseSettings):
|
||||
backend_data: dict[str, Any] = {
|
||||
"url": "http://localhost:8001",
|
||||
}
|
||||
|
||||
|
||||
def get_settings() -> WebSettings:
|
||||
return WebSettings()
|
||||
|
||||
Reference in New Issue
Block a user