From cfd7e2f5ef5f200d690057d3ccddf3f61e5400c6 Mon Sep 17 00:00:00 2001 From: gaoshuaixing Date: Tue, 6 Feb 2024 17:55:39 +0800 Subject: [PATCH] py --- electron/config/bin.js | 6 ++++++ electron/config/config.default.js | 6 ++++++ electron/config/config.local.js | 9 +++++++++ package.json | 1 + python/main.py | 8 +++++++- 5 files changed, 29 insertions(+), 1 deletion(-) diff --git a/electron/config/bin.js b/electron/config/bin.js index f4aedfd..5b5e328 100644 --- a/electron/config/bin.js +++ b/electron/config/bin.js @@ -125,5 +125,11 @@ module.exports = { cmd: 'npm', args: ['-v'], }, + py: { + directory: './python', + cmd: 'python', + args: ['./main.py', '--port=7074'], + //stdio: ['ignore', 'ignore', 'ignore'], + }, }, }; \ No newline at end of file diff --git a/electron/config/config.default.js b/electron/config/config.default.js index c038bcf..e70ca32 100644 --- a/electron/config/config.default.js +++ b/electron/config/config.default.js @@ -128,6 +128,12 @@ module.exports = (appInfo) => { args: ['--port=7073'], appExit: true, }, + python: { + enable: false, + name: 'pyapp', + args: ['--port=7074'], + appExit: true, + }, }; /** diff --git a/electron/config/config.local.js b/electron/config/config.local.js index 1c083a6..ecedc27 100644 --- a/electron/config/config.local.js +++ b/electron/config/config.local.js @@ -42,6 +42,15 @@ module.exports = (appInfo) => { args: ['run', './main.go', '--env=dev','--basedir=../', '--port=7073'], appExit: true, }, + python: { + enable: true, + name: 'pyapp', + cmd: 'python', + directory: './python', + args: ['./main.py', '--port=7074'], + stdio: "ignore", + appExit: true, + }, }; return { diff --git a/package.json b/package.json index 5aef5a9..20f67aa 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ "dev-frontend": "ee-bin dev --serve=frontend", "dev-electron": "ee-bin dev --serve=electron", "dev-go": "ee-bin dev --serve=go", + "dev-py": "ee-bin exec --cmds=py", "build-frontend": "ee-bin build --cmds=frontend && ee-bin move --flag=frontend_dist", "build-go-w": "ee-bin build --cmds=go_build_w", "build-go-m": "ee-bin build --cmds=go_build_m", diff --git a/python/main.py b/python/main.py index b2a1e71..a3256c4 100644 --- a/python/main.py +++ b/python/main.py @@ -1,8 +1,14 @@ +import argparse import uvicorn from fastapi import FastAPI app = FastAPI() +# argparse +parser = argparse.ArgumentParser(description='Process some integers.') +parser.add_argument('--port', type=int, default=7074, help='The port number.') +args = parser.parse_args() + @app.get("/") async def index(): """ @@ -24,4 +30,4 @@ async def info(): } if __name__ == "__main__": - uvicorn.run(app, host="127.0.0.1", port=8000) \ No newline at end of file + uvicorn.run(app, host="127.0.0.1", port=args.port) \ No newline at end of file