From 2d7be3348af981680fccb986c2bcdb76242e43e1 Mon Sep 17 00:00:00 2001 From: louistiti Date: Thu, 6 Oct 2022 16:27:20 +0800 Subject: [PATCH] feat(python bridge): set up script --- package.json | 3 ++ scripts/commit-msg.js | 2 +- scripts/python-bridge/setup-python-bridge.js | 35 ++++++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 scripts/python-bridge/setup-python-bridge.js diff --git a/package.json b/package.json index 79e01aa2..e235250c 100644 --- a/package.json +++ b/package.json @@ -34,6 +34,7 @@ "setup:offline-stt": "ts-node scripts/setup-offline/run-setup-stt.js", "setup:offline-tts": "ts-node scripts/setup-offline/run-setup-tts.js", "setup:offline-hotword": "ts-node scripts/setup-offline/run-setup-hotword.js", + "setup:python-bridge": "ts-node scripts/python-bridge/setup-python-bridge.js", "preinstall": "node scripts/setup/preinstall.js", "postinstall": "ts-node scripts/setup/setup.js", "dev:app": "vite --config app/vite.config.js", @@ -47,6 +48,8 @@ "build": "npm run build:app && npm run build:server", "build:app": "cross-env LEON_NODE_ENV=production ts-node scripts/app/run-build-app.js", "build:server": "npm run delete-dist:server && npm run train && npm run generate:skills-endpoints && tsc && resolve-tspaths && shx rm -rf server/dist/core server/dist/package.json && shx mv -f server/dist/server/src/* server/dist && shx rm -rf server/dist/server && shx mkdir -p server/dist/tmp", + "build:python-bridge": "cross-env PIPENV_PIPFILE=bridges/python/src/Pipfile PIPENV_VENV_IN_PROJECT=true PIP_NO_BINARY=cx_Freeze", + "build:tcp-server": "", "start:tcp-server": "cross-env PIPENV_PIPFILE=bridges/python/src/Pipfile pipenv run python tcp_server/src/main.py", "start": "cross-env LEON_NODE_ENV=production node ./server/dist/index.js", "train": "ts-node scripts/train/run-train.js", diff --git a/scripts/commit-msg.js b/scripts/commit-msg.js index 7c9dcae7..e296411a 100644 --- a/scripts/commit-msg.js +++ b/scripts/commit-msg.js @@ -14,7 +14,7 @@ if (fs.existsSync(commitEditMsgFile)) { try { const commitMessage = fs.readFileSync(commitEditMsgFile, 'utf8') const regex = - '(build|BREAKING|chore|ci|docs|feat|fix|perf|refactor|style|test)(\\((web app|docker|server|hotword|skill|tcp server|python bridge\\/([\\w-]+)))?\\)?: .{1,50}' + '(build|BREAKING|chore|ci|docs|feat|fix|perf|refactor|style|test)(\\((web app|docker|server|hotword|tcp server|python bridge|skill\\/([\\w-]+)))?\\)?: .{1,50}' if (commitMessage.match(regex) !== null) { LogHelper.success('Commit message validated') diff --git a/scripts/python-bridge/setup-python-bridge.js b/scripts/python-bridge/setup-python-bridge.js new file mode 100644 index 00000000..b3eec594 --- /dev/null +++ b/scripts/python-bridge/setup-python-bridge.js @@ -0,0 +1,35 @@ +import { command } from 'execa' + +import { LogHelper } from '@/helpers/log-helper' +import { LoaderHelper } from '@/helpers/loader-helper' + +/** + * Set up Python bridge development environment + * 1. Install Python packages from the Pipfile + */ + +const PIPFILE_PATH = 'bridges/python/src/Pipfile' + +;(async () => { + LoaderHelper.start() + LogHelper.info('Setting up Python bridge development environment...') + LogHelper.info(`Installing Python packages from ${PIPFILE_PATH}.lock...`) + + try { + process.env.PIPENV_PIPFILE = PIPFILE_PATH + process.env.PIPENV_VENV_IN_PROJECT = true + // As per: https://github.com/marcelotduarte/cx_Freeze/issues/1548 + process.env.PIP_NO_BINARY = 'cx_Freeze' + + await command(`pipenv install --site-packages`, { + shell: true + }) + + LogHelper.success('Python packages installed') + LogHelper.success('Python bridge development environment ready') + } catch (e) { + LogHelper.error(`Failed to set up Python bridge: ${e}`) + } finally { + LoaderHelper.stop() + } +})()