1
1
mirror of https://github.com/leon-ai/leon.git synced 2024-11-28 12:43:35 +03:00

perf: check if Python deps tree has been updated before going through deps install

This commit is contained in:
louistiti 2022-02-04 13:33:14 +08:00
parent 699ded22ad
commit 2d0b0f1365
No known key found for this signature in database
GPG Key ID: 0A1C3B043E70C77D
2 changed files with 20 additions and 6 deletions

View File

@ -51,7 +51,7 @@ export default () => new Promise(async (resolve, reject) => {
try {
if (process.env.LEON_HTTP_API_KEY === '') {
await generateHttpApiKey()
} else {
} else if (!process.env.IS_DOCKER) {
const answer = await prompt({
type: 'confirm',
name: 'generate.httpApiKey',

View File

@ -1,5 +1,6 @@
import { command } from 'execa'
import fs from 'fs'
import path from 'path'
import log from '@/helpers/log'
@ -31,12 +32,25 @@ export default () => new Promise(async (resolve, reject) => {
}
try {
// Installing Python packages
log.info('Installing Python packages from bridges/python/Pipfile...')
const dotVenvPath = path.join(process.cwd(), 'bridges/python/.venv')
const pipfileLockPath = path.join(process.cwd(), 'bridges/python/Pipfile.lock')
const dotProjectPath = path.join(process.cwd(), 'bridges/python/.venv/.project')
const isDotVenvExist = fs.existsSync(dotVenvPath)
const pipfileLockMtime = fs.statSync(pipfileLockPath).mtime
const dotProjectMtime = fs.statSync(dotProjectPath).mtime
// Check if Python deps tree has been modified since the initial setup
if (!isDotVenvExist || (pipfileLockMtime > dotProjectMtime)) {
// Installing Python packages
log.info('Installing Python packages from bridges/python/Pipfile...')
await command('pipenv --three', { shell: true })
await command('pipenv install', { shell: true })
log.success('Python packages installed')
} else {
log.success('Python packages are up-to-date')
}
await command('pipenv --three', { shell: true })
await command('pipenv install', { shell: true })
log.success('Python packages installed')
resolve()
} catch (e) {
log.error(`Failed to install the Python packages: ${e}`)