From 21959ba2821958bde2f131f69590c291f92d1f96 Mon Sep 17 00:00:00 2001 From: Rami <54779216+Ramimashkouk@users.noreply.github.com> Date: Mon, 29 Jul 2024 12:30:18 +0300 Subject: [PATCH] chore: Automate version updates (#68) * chore: Automate version changing * feat: automate version front * fix: python response default value fix * fix: title version fix * chore: Update Readme & version --------- Co-authored-by: MXerFix --- README.md | 19 +++- backend/df_designer/app/api/api_v1/api.py | 3 +- .../app/api/api_v1/endpoints/config.py | 14 +++ backend/df_designer/app/cli.py | 3 + backend/df_designer/app/core/config.py | 1 + backend/df_designer/poetry.lock | 13 ++- backend/df_designer/pyproject.toml | 3 +- frontend/index.html | 2 +- frontend/src/api/meta.ts | 7 ++ frontend/src/components/footbar/FootBar.tsx | 4 +- frontend/src/components/header/Header.tsx | 102 ++++++++++-------- frontend/src/contexts/index.tsx | 33 +++--- frontend/src/contexts/metaContext.tsx | 35 ++++++ .../components/PythonResponse.tsx | 4 +- 14 files changed, 175 insertions(+), 68 deletions(-) create mode 100644 backend/df_designer/app/api/api_v1/endpoints/config.py create mode 100644 frontend/src/api/meta.ts create mode 100644 frontend/src/contexts/metaContext.tsx diff --git a/README.md b/README.md index 58b713b0..cdbb514e 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,23 @@ Ensure you have Python version 3.10 or higher installed. ## Installation To install the necessary package, run the following command: ```bash -pip install dflowd==0.1.0b0 +pip install dflowd --pre +``` + +## Configuring the dflowd app +You may add a `.env` file in the root directory and configure any of following environment variables. The values shown below are the default ones. +```.env +HOST=0.0.0.0 +PORT=8000 +CONF_RELOAD=True +LOG_LEVEL=info + +GRACEFUL_TERMINATION_TIMEOUT=2 # Waiting for process to stop +PING_PONG_TIMEOUT=0.5 # Waiting the process to response before it mark it as still `running` + +# For tests: +BUILD_COMPLETION_TIMEOUT=10 +RUN_RUNNING_TIMEOUT=5 ``` ## Project Initiation @@ -21,4 +37,3 @@ To run your project, use the following command: ```bash dflowd run_backend ``` -Note: Currently, the project runs exclusively on port 8000. diff --git a/backend/df_designer/app/api/api_v1/api.py b/backend/df_designer/app/api/api_v1/api.py index d6e857e6..44ed909d 100644 --- a/backend/df_designer/app/api/api_v1/api.py +++ b/backend/df_designer/app/api/api_v1/api.py @@ -1,10 +1,11 @@ from fastapi import APIRouter -from app.api.api_v1.endpoints import bot, dff_services, flows +from app.api.api_v1.endpoints import bot, dff_services, flows, config from app.core.config import settings api_router = APIRouter() +api_router.include_router(config.router, prefix="/".join([settings.API_V1_STR, "config"]), tags=["config"]) api_router.include_router(flows.router, prefix="/".join([settings.API_V1_STR, "flows"]), tags=["flows"]) api_router.include_router(dff_services.router, prefix="/".join([settings.API_V1_STR, "services"]), tags=["services"]) api_router.include_router(bot.router, prefix="/".join([settings.API_V1_STR, "bot"]), tags=["bot"]) diff --git a/backend/df_designer/app/api/api_v1/endpoints/config.py b/backend/df_designer/app/api/api_v1/endpoints/config.py new file mode 100644 index 00000000..97ad716b --- /dev/null +++ b/backend/df_designer/app/api/api_v1/endpoints/config.py @@ -0,0 +1,14 @@ +from fastapi import APIRouter + +import toml + +from app.core.config import settings + + +router = APIRouter() + + +@router.get("/version") +async def get_version(): + pyproject = toml.load(settings.pyproject_path) + return pyproject["tool"]["poetry"]["version"] diff --git a/backend/df_designer/app/cli.py b/backend/df_designer/app/cli.py index 250b1beb..050109bb 100644 --- a/backend/df_designer/app/cli.py +++ b/backend/df_designer/app/cli.py @@ -4,6 +4,7 @@ import sys from pathlib import Path +import toml import nest_asyncio import typer from cookiecutter.main import cookiecutter @@ -101,12 +102,14 @@ def run_app( @cli.command("init") def init(destination: str = settings.work_directory, no_input: bool = False, overwrite_if_exists: bool = True): original_dir = os.getcwd() + pyproject = toml.load(settings.pyproject_path) try: os.chdir(destination) cookiecutter( "https://github.com/Ramimashkouk/df_d_template.git", no_input=no_input, overwrite_if_exists=overwrite_if_exists, + extra_context={"dflowd_version": pyproject["tool"]["poetry"]["version"]}, ) finally: os.chdir(original_dir) diff --git a/backend/df_designer/app/core/config.py b/backend/df_designer/app/core/config.py index 859f17e4..254f9a1a 100644 --- a/backend/df_designer/app/core/config.py +++ b/backend/df_designer/app/core/config.py @@ -17,6 +17,7 @@ class Settings(BaseSettings): static_files: Path = config_file_path.parent.with_name("static") start_page: Path = static_files.joinpath("index.html") package_dir: Path = config_file_path.parents[3] + pyproject_path: Path = package_dir / "df_designer" / "pyproject.toml" host: str = os.getenv("HOST", "0.0.0.0") port: int = int(os.getenv("PORT", 8000)) diff --git a/backend/df_designer/poetry.lock b/backend/df_designer/poetry.lock index 1a4db478..12c0be0f 100644 --- a/backend/df_designer/poetry.lock +++ b/backend/df_designer/poetry.lock @@ -1441,6 +1441,17 @@ files = [ {file = "text_unidecode-1.3-py2.py3-none-any.whl", hash = "sha256:1311f10e8b895935241623731c2ba64f4c455287888b18189350b67134a822e8"}, ] +[[package]] +name = "toml" +version = "0.10.2" +description = "Python Library for Tom's Obvious, Minimal Language" +optional = false +python-versions = ">=2.6, !=3.0.*, !=3.1.*, !=3.2.*" +files = [ + {file = "toml-0.10.2-py2.py3-none-any.whl", hash = "sha256:806143ae5bfb6a3c6e736a764057db0e6a0e05e338b5630894a5f779cabb4f9b"}, + {file = "toml-0.10.2.tar.gz", hash = "sha256:b3bda1d108d5dd99f4a20d24d9c348e91c4db7ab1b749200bded2f839ccbe68f"}, +] + [[package]] name = "tomli" version = "2.0.1" @@ -1857,4 +1868,4 @@ h11 = ">=0.9.0,<1" [metadata] lock-version = "2.0" python-versions = "^3.10" -content-hash = "172f319abb137328b25d29bb0dc64773cd093f45c3c571d2fc282704f4102923" +content-hash = "c00f7a8ff2d1dabc5a7cfa165e191ecbbc82198eead23946a4e7e76b78015728" diff --git a/backend/df_designer/pyproject.toml b/backend/df_designer/pyproject.toml index 3bebb972..bf46a29f 100644 --- a/backend/df_designer/pyproject.toml +++ b/backend/df_designer/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "dflowd" -version = "0.1.0-beta.1" +version = "0.1.0b2" description = "Dialog Flow Designer" license = "Apache-2.0" authors = [ @@ -30,6 +30,7 @@ httpx-ws = "^0.6.0" pylint = "^3.2.3" sphinx = "^7.3.7" sphinx-rtd-theme = "^2.0.0" +toml = "^0.10.2" [tool.poetry.scripts] dflowd = "app.cli:cli" diff --git a/frontend/index.html b/frontend/index.html index d769bd50..d659d194 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -4,7 +4,7 @@ - DFD 0.1.0-beta.1 + DF Designer
diff --git a/frontend/src/api/meta.ts b/frontend/src/api/meta.ts new file mode 100644 index 00000000..e25d469c --- /dev/null +++ b/frontend/src/api/meta.ts @@ -0,0 +1,7 @@ +import { $v1 } from "." + + + +export const get_config_version = async () => { + return (await $v1.get("/config/version")).data +} \ No newline at end of file diff --git a/frontend/src/components/footbar/FootBar.tsx b/frontend/src/components/footbar/FootBar.tsx index 78e3a1b5..08403b6c 100644 --- a/frontend/src/components/footbar/FootBar.tsx +++ b/frontend/src/components/footbar/FootBar.tsx @@ -3,6 +3,7 @@ import classNames from "classnames" import { BellRing, EditIcon, Rocket, Settings } from "lucide-react" import { Key, useContext } from "react" import { Link, useSearchParams } from "react-router-dom" +import { MetaContext } from "../../contexts/metaContext" import { buildContext } from "../../contexts/buildContext" import { workspaceContext } from "../../contexts/workspaceContext" import { Logo } from "../../icons/Logo" @@ -18,6 +19,7 @@ const FootBar = () => { onClose: onLocalStogareClose, } = useDisclosure() + const { version } = useContext(MetaContext) const { settingsPage, setSettingsPage } = useContext(workspaceContext) const { logsPage, setLogsPage } = useContext(buildContext) const [searchParams, setSearchParams] = useSearchParams() @@ -119,7 +121,7 @@ const FootBar = () => {
DF Designer - v 0.1.0-beta1 + v {version}
diff --git a/frontend/src/components/header/Header.tsx b/frontend/src/components/header/Header.tsx index e8160412..b6a6cccb 100644 --- a/frontend/src/components/header/Header.tsx +++ b/frontend/src/components/header/Header.tsx @@ -1,10 +1,12 @@ import { Button, Tooltip, useDisclosure } from "@nextui-org/react" import classNames from "classnames" import { useContext } from "react" -import { useLocation } from "react-router-dom" +import { Link, useLocation } from "react-router-dom" import { flowContext } from "../../contexts/flowContext" +import { MetaContext } from "../../contexts/metaContext" import { themeContext } from "../../contexts/themeContext" import { workspaceContext } from "../../contexts/workspaceContext" +import { Logo } from "../../icons/Logo" import GrabModeIcon from "../../icons/header/GrabModeIcon" import GridModeIcon from "../../icons/header/GridModeIcon" import ListViewIcon from "../../icons/header/ListViewIcon" @@ -12,6 +14,7 @@ import BuildMenu from "./BuildMenu" import NodeInstruments from "./components/NodeInstruments" const Header = () => { + const { version } = useContext(MetaContext) const { toggleTheme, theme } = useContext(themeContext) const location = useLocation() const { @@ -35,50 +38,61 @@ const Header = () => {
-
-
- - - - - - - - - + {location.pathname.includes("app/home") && ( + + +
+ DF Designer + v {version} +
+ + )} + {location.pathname.includes("flow") && ( +
+
+ + + + + + + + + +
-
+ )}
{selectedNode && flow && location.pathname.includes("flow") && ( diff --git a/frontend/src/contexts/index.tsx b/frontend/src/contexts/index.tsx index e55fa5cf..6b76f620 100644 --- a/frontend/src/contexts/index.tsx +++ b/frontend/src/contexts/index.tsx @@ -2,6 +2,7 @@ import { BuildProvider } from "./buildContext" import { ChatProvider } from "./chatContext" import { FlowProvider } from "./flowContext" import IdeProvider from "./ideContext" +import MetaProvider from "./metaContext" import PopUpProvider from "./popUpContext" import { RunProvider } from "./runContext" import { ThemeProvider } from "./themeContext" @@ -9,20 +10,22 @@ import { WorkspaceProvider } from "./workspaceContext" export default function ContextWrapper({ children }: { children: React.ReactNode }) { return ( - - - - - - - - {children} - - - - - - - + + + + + + + + + {children} + + + + + + + + ) } diff --git a/frontend/src/contexts/metaContext.tsx b/frontend/src/contexts/metaContext.tsx new file mode 100644 index 00000000..c2e54016 --- /dev/null +++ b/frontend/src/contexts/metaContext.tsx @@ -0,0 +1,35 @@ +import React, { createContext, useEffect, useState } from "react" +import { get_config_version } from "../api/meta" + +// context to set JSX element on the DOM + +type metaContextType = { + version: string + setVersion: React.Dispatch> +} + +export const MetaContext = createContext({ + version: "", + setVersion: () => {}, +}) + +interface MetaProviderProps { + children: React.ReactNode +} + +const MetaProvider = ({ children }: MetaProviderProps) => { + const [version, setVersion] = useState("") + + const getVersion = async () => { + const version_data = await get_config_version() + setVersion(version_data) + } + + useEffect(() => { + getVersion() + }, []) + + return {children} +} + +export default MetaProvider diff --git a/frontend/src/modals/ResponseModal/components/PythonResponse.tsx b/frontend/src/modals/ResponseModal/components/PythonResponse.tsx index ebb8c4f2..73510ea4 100644 --- a/frontend/src/modals/ResponseModal/components/PythonResponse.tsx +++ b/frontend/src/modals/ResponseModal/components/PythonResponse.tsx @@ -22,7 +22,7 @@ const PythonResponse = ({ const { theme } = useContext(themeContext) const { methods: dffMethods } = useContext(IdeContext) - const firstString = `def ${response.name}(ctx: Context, pipeline: Pipeline) -> bool:` + const firstString = `def ${response.name}(ctx: Context, pipeline: Pipeline) -> Message(""):` useEffect(() => { if (!response.data[0].python) { @@ -33,7 +33,7 @@ const PythonResponse = ({ { priority: 1, python: { - action: `def ${response.name}(ctx: Context, pipeline: Pipeline) -> bool:\n # enter your python response:\n return True`, + action: `def ${response.name}(ctx: Context, pipeline: Pipeline) -> bool:\n # enter your python response:\n return Message('Hello')`, }, }, ],