From 775a902c50eb2e226545a370063409268e11f425 Mon Sep 17 00:00:00 2001 From: Oleg Yurchik Date: Sun, 17 Dec 2023 11:07:00 +0300 Subject: [PATCH] Start developing publish to static --- .dockerignore | 3 +++ .gitignore | 2 ++ poetry.lock | 26 +++++++++++++++++++++----- pyproject.toml | 3 ++- soul_diary/ui/app/pages/sense_list.py | 1 + soul_diary/ui/cli.py | 16 ++++++++++++++++ soul_diary/ui/entrypoint.py | 14 ++++++++++++++ soul_diary/ui/service.py | 5 ++--- soul_diary/ui/web/cli.py | 16 +++------------- soul_diary/ui/web/service.py | 3 ++- soul_diary/ui/web/settings.py | 4 ---- 11 files changed, 66 insertions(+), 27 deletions(-) create mode 100644 soul_diary/ui/entrypoint.py diff --git a/.dockerignore b/.dockerignore index e4f765a..221e5d6 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,2 +1,5 @@ */**/__pycache__ *.pyc +*.sqlite3 +dist/ +soul_diary/ui/requirements.txt diff --git a/.gitignore b/.gitignore index 195c87a..c5bb120 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ *.pyc *.sqlite3 __pycache__ +dist/ +soul_diary/ui/requirements.txt diff --git a/poetry.lock b/poetry.lock index b3788b7..afcab22 100644 --- a/poetry.lock +++ b/poetry.lock @@ -57,6 +57,7 @@ files = [ ] [package.dependencies] +exceptiongroup = {version = ">=1.0.2", markers = "python_version < \"3.11\""} idna = ">=2.8" sniffio = ">=1.1" @@ -348,6 +349,20 @@ pyyaml = ">=5.3.1" requests = ">=2.23.0" 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]] name = "facet" version = "0.9.1" @@ -848,13 +863,13 @@ signedtoken = ["cryptography (>=3.0.0)", "pyjwt (>=2.0.0,<3)"] [[package]] name = "packaging" -version = "23.2" +version = "23.1" description = "Core utilities for Python packages" optional = false python-versions = ">=3.7" files = [ - {file = "packaging-23.2-py3-none-any.whl", hash = "sha256:8c491190033a9af7e1d931d0b5dacc2ef47509b34dd0de67ed209b5203fc88c7"}, - {file = "packaging-23.2.tar.gz", hash = "sha256:048fb0e9405036518eaaf48a55953c750c11e1a1b68e0dd1a9d62ed0c092cfc5"}, + {file = "packaging-23.1-py3-none-any.whl", hash = "sha256:994793af429502c4ea2ebf6bf664629d07c1a9fe974af92966e4b8d2df7edc61"}, + {file = "packaging-23.1.tar.gz", hash = "sha256:a392980d2b6cffa644431898be54b0045151319d1e7ec34f0cfed48767dd334f"}, ] [[package]] @@ -1465,6 +1480,7 @@ files = [ [package.dependencies] click = ">=7.0" h11 = ">=0.8" +typing-extensions = {version = ">=4.0", markers = "python_version < \"3.11\""} [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)"] @@ -1712,5 +1728,5 @@ sqlite = ["aiosqlite"] [metadata] lock-version = "2.0" -python-versions = "^3.11" -content-hash = "2edc77f8a1e7fc20a3330be55ee660506982acfa0ace143d3b5fc41c3b813e5d" +python-versions = "^3.10" +content-hash = "3073f58d2f86f70870251b6c879a5417de6d4767cf3560daad0f3416e007642e" diff --git a/pyproject.toml b/pyproject.toml index 974c0dc..c79e385 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,7 +14,7 @@ aiosqlite = { version = "^0.19.0", optional = true } asyncpg = { version = "^0.28.0", optional = true } # main -python = "^3.11" +python = "^3.10" uvicorn = "^0.24.0.post1" facet = "^0.9.1" pydantic = "^2.5.2" @@ -38,6 +38,7 @@ flet-fastapi = "^0.14.0" pycryptodomex = "^3.19.0" yarl = "^1.9.4" httpx = "0.24.1" +packaging = "23.1" [build-system] requires = ["poetry-core"] diff --git a/soul_diary/ui/app/pages/sense_list.py b/soul_diary/ui/app/pages/sense_list.py index 867a1ef..32091e9 100644 --- a/soul_diary/ui/app/pages/sense_list.py +++ b/soul_diary/ui/app/pages/sense_list.py @@ -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, diff --git a/soul_diary/ui/cli.py b/soul_diary/ui/cli.py index 1397eb7..406924e 100644 --- a/soul_diary/ui/cli.py +++ b/soul_diary/ui/cli.py @@ -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 diff --git a/soul_diary/ui/entrypoint.py b/soul_diary/ui/entrypoint.py new file mode 100644 index 0000000..fdefd6d --- /dev/null +++ b/soul_diary/ui/entrypoint.py @@ -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) diff --git a/soul_diary/ui/service.py b/soul_diary/ui/service.py index c8257fb..9a0f6cd 100644 --- a/soul_diary/ui/service.py +++ b/soul_diary/ui/service.py @@ -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) diff --git a/soul_diary/ui/web/cli.py b/soul_diary/ui/web/cli.py index 7d7332b..cafd64f 100644 --- a/soul_diary/ui/web/cli.py +++ b/soul_diary/ui/web/cli.py @@ -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 diff --git a/soul_diary/ui/web/service.py b/soul_diary/ui/web/service.py index 77b5efc..33f2af0 100644 --- a/soul_diary/ui/web/service.py +++ b/soul_diary/ui/web/service.py @@ -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) diff --git a/soul_diary/ui/web/settings.py b/soul_diary/ui/web/settings.py index db7dd15..572c020 100644 --- a/soul_diary/ui/web/settings.py +++ b/soul_diary/ui/web/settings.py @@ -11,7 +11,3 @@ class WebSettings(BaseSettings): backend_data: dict[str, Any] = { "url": "http://localhost:8001", } - - -def get_settings() -> WebSettings: - return WebSettings()