Skip to content

Commit

Permalink
chore: Automate version updates (#68)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
Ramimashkouk and MXerFix authored Jul 29, 2024
1 parent c9427d5 commit 21959ba
Show file tree
Hide file tree
Showing 14 changed files with 175 additions and 68 deletions.
19 changes: 17 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
3 changes: 2 additions & 1 deletion backend/df_designer/app/api/api_v1/api.py
Original file line number Diff line number Diff line change
@@ -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"])
14 changes: 14 additions & 0 deletions backend/df_designer/app/api/api_v1/endpoints/config.py
Original file line number Diff line number Diff line change
@@ -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"]
3 changes: 3 additions & 0 deletions backend/df_designer/app/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import sys
from pathlib import Path

import toml
import nest_asyncio
import typer
from cookiecutter.main import cookiecutter
Expand Down Expand Up @@ -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)
1 change: 1 addition & 0 deletions backend/df_designer/app/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
13 changes: 12 additions & 1 deletion backend/df_designer/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion backend/df_designer/pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 = [
Expand Down Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>DFD 0.1.0-beta.1</title>
<title>DF Designer</title>
</head>
<body>
<div id="root"></div>
Expand Down
7 changes: 7 additions & 0 deletions frontend/src/api/meta.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { $v1 } from "."



export const get_config_version = async () => {
return (await $v1.get("/config/version")).data
}
4 changes: 3 additions & 1 deletion frontend/src/components/footbar/FootBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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()
Expand Down Expand Up @@ -119,7 +121,7 @@ const FootBar = () => {
<Logo />
<div className='flex items-end justify-start gap-1'>
<span className='flex font-bold text-lg'>DF Designer</span>
<span className='flex font-semibold text-neutral-400 text-sm'>v 0.1.0-beta1</span>
<span className='flex font-semibold text-neutral-400 text-sm'>v {version}</span>
</div>
</Link>
<div className='flex items-end gap-0.5'>
Expand Down
102 changes: 58 additions & 44 deletions frontend/src/components/header/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
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"
import BuildMenu from "./BuildMenu"
import NodeInstruments from "./components/NodeInstruments"

const Header = () => {
const { version } = useContext(MetaContext)
const { toggleTheme, theme } = useContext(themeContext)
const location = useLocation()
const {
Expand All @@ -35,50 +38,61 @@ const Header = () => {
<div
data-testid='header'
className='min-h-14 flex items-center justify-between w-screen z-10 bg-bg-secondary border-b border-border px-2 pr-4'>
<div className='flex items-center gap-4 w-52'>
<div className='flex items-center gap-1.5'>
<Tooltip
radius='sm'
content={`Grab mode ${managerMode ? "on" : "off"}`}>
<Button
isIconOnly
onClick={toggleManagerMode}
className={classNames(
"bg-overlay hover:bg-background border border-border rounded-small",
!managerMode ? "bg-background border-border-darker" : ""
)}>
<GrabModeIcon />
</Button>
</Tooltip>
<Tooltip
radius='sm'
content={`Free grid mode ${workspaceMode ? "on" : "off"}`}>
<Button
onClick={toggleWorkspaceMode}
isIconOnly
className={classNames(
" bg-overlay hover:bg-background border border-border rounded-small",
!workspaceMode ? "bg-background border-border-darker" : ""
)}>
<GridModeIcon />
</Button>
</Tooltip>
<Tooltip
radius='sm'
content={`List mode ${nodesLayoutMode ? "on" : "off"}`}>
<Button
onClick={toggleNodesLayoutMode}
isIconOnly
className={classNames(
" bg-overlay hover:bg-background border border-border rounded-small",
!nodesLayoutMode ? "bg-background border-border-darker" : ""
)}>
{/* {nodesLayoutMode ? "Canvas Mode" : "List mode"} */}
<ListViewIcon />
</Button>
</Tooltip>
{location.pathname.includes("app/home") && (
<Link data-testid='logo-header' to={"/app/home"} className='flex items-center gap-1 z-10 cursor-pointer'>
<Logo />
<div className="flex items-end justify-start gap-1">
<span className='flex font-bold text-lg'>DF Designer</span>
<span className='flex font-semibold text-neutral-400 text-sm'>v {version}</span>
</div>
</Link>
)}
{location.pathname.includes("flow") && (
<div className='flex items-center gap-4 w-52'>
<div className='flex items-center gap-1.5'>
<Tooltip
radius='sm'
content={`Grab mode ${managerMode ? "on" : "off"}`}>
<Button
isIconOnly
onClick={toggleManagerMode}
className={classNames(
" bg-overlay hover:bg-background border border-border rounded-small",
!managerMode ? "bg-background border-border-darker" : ""
)}>
<GrabModeIcon />
</Button>
</Tooltip>
<Tooltip
radius='sm'
content={`Free grid mode ${workspaceMode ? "on" : "off"}`}>
<Button
onClick={toggleWorkspaceMode}
isIconOnly
className={classNames(
" bg-overlay hover:bg-background border border-border rounded-small",
!workspaceMode ? "bg-background border-border-darker" : ""
)}>
<GridModeIcon />
</Button>
</Tooltip>
<Tooltip
radius='sm'
content={`List mode ${nodesLayoutMode ? "on" : "off"}`}>
<Button
onClick={toggleNodesLayoutMode}
isIconOnly
className={classNames(
" bg-overlay hover:bg-background border border-border rounded-small",
!nodesLayoutMode ? "bg-background border-border-darker" : ""
)}>
{/* {nodesLayoutMode ? "Canvas Mode" : "List mode"} */}
<ListViewIcon />
</Button>
</Tooltip>
</div>
</div>
</div>
)}
<div className='flex items-center'>
{selectedNode && flow && location.pathname.includes("flow") && (
<NodeInstruments flow={flow} />
Expand Down
33 changes: 18 additions & 15 deletions frontend/src/contexts/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,30 @@ 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"
import { WorkspaceProvider } from "./workspaceContext"

export default function ContextWrapper({ children }: { children: React.ReactNode }) {
return (
<ThemeProvider>
<ChatProvider>
<BuildProvider>
<RunProvider>
<FlowProvider>
<WorkspaceProvider>
<IdeProvider>
<PopUpProvider>{children}</PopUpProvider>
</IdeProvider>
</WorkspaceProvider>
</FlowProvider>
</RunProvider>
</BuildProvider>
</ChatProvider>
</ThemeProvider>
<MetaProvider>
<ThemeProvider>
<ChatProvider>
<BuildProvider>
<RunProvider>
<FlowProvider>
<WorkspaceProvider>
<IdeProvider>
<PopUpProvider>{children}</PopUpProvider>
</IdeProvider>
</WorkspaceProvider>
</FlowProvider>
</RunProvider>
</BuildProvider>
</ChatProvider>
</ThemeProvider>
</MetaProvider>
)
}
35 changes: 35 additions & 0 deletions frontend/src/contexts/metaContext.tsx
Original file line number Diff line number Diff line change
@@ -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<React.SetStateAction<string>>
}

export const MetaContext = createContext<metaContextType>({
version: "",
setVersion: () => {},
})

interface MetaProviderProps {
children: React.ReactNode
}

const MetaProvider = ({ children }: MetaProviderProps) => {
const [version, setVersion] = useState<string>("")

const getVersion = async () => {
const version_data = await get_config_version()
setVersion(version_data)
}

useEffect(() => {
getVersion()
}, [])

return <MetaContext.Provider value={{ version, setVersion }}>{children}</MetaContext.Provider>
}

export default MetaProvider
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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')`,
},
},
],
Expand Down

0 comments on commit 21959ba

Please sign in to comment.