Start developing publish to static

This commit is contained in:
2023-12-17 11:07:00 +03:00
parent ce9808f151
commit 775a902c50
11 changed files with 66 additions and 27 deletions

View File

@@ -1,2 +1,5 @@
*/**/__pycache__ */**/__pycache__
*.pyc *.pyc
*.sqlite3
dist/
soul_diary/ui/requirements.txt

2
.gitignore vendored
View File

@@ -1,3 +1,5 @@
*.pyc *.pyc
*.sqlite3 *.sqlite3
__pycache__ __pycache__
dist/
soul_diary/ui/requirements.txt

26
poetry.lock generated
View File

@@ -57,6 +57,7 @@ files = [
] ]
[package.dependencies] [package.dependencies]
exceptiongroup = {version = ">=1.0.2", markers = "python_version < \"3.11\""}
idna = ">=2.8" idna = ">=2.8"
sniffio = ">=1.1" sniffio = ">=1.1"
@@ -348,6 +349,20 @@ pyyaml = ">=5.3.1"
requests = ">=2.23.0" requests = ">=2.23.0"
rich = "*" rich = "*"
[[package]]
name = "exceptiongroup"
version = "1.2.0"
description = "Backport of PEP 654 (exception groups)"
optional = false
python-versions = ">=3.7"
files = [
{file = "exceptiongroup-1.2.0-py3-none-any.whl", hash = "sha256:4bfd3996ac73b41e9b9628b04e079f193850720ea5945fc96a08633c66912f14"},
{file = "exceptiongroup-1.2.0.tar.gz", hash = "sha256:91f5c769735f051a4290d52edd0858999b57e5876e9f85937691bd4c9fa3ed68"},
]
[package.extras]
test = ["pytest (>=6)"]
[[package]] [[package]]
name = "facet" name = "facet"
version = "0.9.1" version = "0.9.1"
@@ -848,13 +863,13 @@ signedtoken = ["cryptography (>=3.0.0)", "pyjwt (>=2.0.0,<3)"]
[[package]] [[package]]
name = "packaging" name = "packaging"
version = "23.2" version = "23.1"
description = "Core utilities for Python packages" description = "Core utilities for Python packages"
optional = false optional = false
python-versions = ">=3.7" python-versions = ">=3.7"
files = [ files = [
{file = "packaging-23.2-py3-none-any.whl", hash = "sha256:8c491190033a9af7e1d931d0b5dacc2ef47509b34dd0de67ed209b5203fc88c7"}, {file = "packaging-23.1-py3-none-any.whl", hash = "sha256:994793af429502c4ea2ebf6bf664629d07c1a9fe974af92966e4b8d2df7edc61"},
{file = "packaging-23.2.tar.gz", hash = "sha256:048fb0e9405036518eaaf48a55953c750c11e1a1b68e0dd1a9d62ed0c092cfc5"}, {file = "packaging-23.1.tar.gz", hash = "sha256:a392980d2b6cffa644431898be54b0045151319d1e7ec34f0cfed48767dd334f"},
] ]
[[package]] [[package]]
@@ -1465,6 +1480,7 @@ files = [
[package.dependencies] [package.dependencies]
click = ">=7.0" click = ">=7.0"
h11 = ">=0.8" h11 = ">=0.8"
typing-extensions = {version = ">=4.0", markers = "python_version < \"3.11\""}
[package.extras] [package.extras]
standard = ["colorama (>=0.4)", "httptools (>=0.5.0)", "python-dotenv (>=0.13)", "pyyaml (>=5.1)", "uvloop (>=0.14.0,!=0.15.0,!=0.15.1)", "watchfiles (>=0.13)", "websockets (>=10.4)"] standard = ["colorama (>=0.4)", "httptools (>=0.5.0)", "python-dotenv (>=0.13)", "pyyaml (>=5.1)", "uvloop (>=0.14.0,!=0.15.0,!=0.15.1)", "watchfiles (>=0.13)", "websockets (>=10.4)"]
@@ -1712,5 +1728,5 @@ sqlite = ["aiosqlite"]
[metadata] [metadata]
lock-version = "2.0" lock-version = "2.0"
python-versions = "^3.11" python-versions = "^3.10"
content-hash = "2edc77f8a1e7fc20a3330be55ee660506982acfa0ace143d3b5fc41c3b813e5d" content-hash = "3073f58d2f86f70870251b6c879a5417de6d4767cf3560daad0f3416e007642e"

View File

@@ -14,7 +14,7 @@ aiosqlite = { version = "^0.19.0", optional = true }
asyncpg = { version = "^0.28.0", optional = true } asyncpg = { version = "^0.28.0", optional = true }
# main # main
python = "^3.11" python = "^3.10"
uvicorn = "^0.24.0.post1" uvicorn = "^0.24.0.post1"
facet = "^0.9.1" facet = "^0.9.1"
pydantic = "^2.5.2" pydantic = "^2.5.2"
@@ -38,6 +38,7 @@ flet-fastapi = "^0.14.0"
pycryptodomex = "^3.19.0" pycryptodomex = "^3.19.0"
yarl = "^1.9.4" yarl = "^1.9.4"
httpx = "0.24.1" httpx = "0.24.1"
packaging = "23.1"
[build-system] [build-system]
requires = ["poetry-core"] requires = ["poetry-core"]

View File

@@ -28,6 +28,7 @@ class SenseListPage(BasePage):
) )
settings_button = flet.IconButton( settings_button = flet.IconButton(
icon=flet.icons.SETTINGS, icon=flet.icons.SETTINGS,
visible=False,
) )
logout_button = flet.IconButton( logout_button = flet.IconButton(
icon=flet.icons.LOGOUT, icon=flet.icons.LOGOUT,

View File

@@ -1,4 +1,6 @@
import asyncio import asyncio
import pathlib
import subprocess
import typer import typer
@@ -6,6 +8,19 @@ from . import web
from .service import get_service 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(): def run():
ui_service = get_service() ui_service = get_service()
@@ -16,6 +31,7 @@ def get_cli() -> typer.Typer:
cli = typer.Typer() cli = typer.Typer()
cli.command(name="run")(run) cli.command(name="run")(run)
cli.command(name="publish")(publish)
cli.add_typer(web.get_cli(), name="web") cli.add_typer(web.get_cli(), name="web")
return cli return cli

View 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)

View File

@@ -1,6 +1,6 @@
from facet import ServiceMixin 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): class UIService(ServiceMixin):
@@ -15,6 +15,5 @@ class UIService(ServiceMixin):
def get_service() -> UIService: def get_service() -> UIService:
settings = WebSettings() web = get_web_service()
web = get_web_service(settings=settings)
return UIService(web=web) return UIService(web=web)

View File

@@ -2,27 +2,17 @@ import asyncio
import typer import typer
from .service import get_service from .service import get_service
from .settings import WebSettings, get_settings
def run(ctx: typer.Context): def run():
settings: WebSettings = ctx.obj["settings"] web_service = get_service()
loop = asyncio.get_event_loop() asyncio.run(web_service.run())
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()
def get_cli() -> typer.Typer: def get_cli() -> typer.Typer:
cli = typer.Typer() cli = typer.Typer()
cli.callback()(settings_callback)
cli.command(name="run")(run) cli.command(name="run")(run)
return cli return cli

View File

@@ -34,5 +34,6 @@ class WebService(ServiceMixin):
self.add_task(server.serve()) 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) return WebService(port=settings.port, backend_data=settings.backend_data)

View File

@@ -11,7 +11,3 @@ class WebSettings(BaseSettings):
backend_data: dict[str, Any] = { backend_data: dict[str, Any] = {
"url": "http://localhost:8001", "url": "http://localhost:8001",
} }
def get_settings() -> WebSettings:
return WebSettings()