Skip to content

Commit

Permalink
Use python -m pip / fix init screen
Browse files Browse the repository at this point in the history
  • Loading branch information
roll committed Sep 26, 2023
1 parent 3f5d5de commit 9ee9138
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
5 changes: 2 additions & 3 deletions client/components/Application/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ import * as menu from '../Parts/Bars/Menu'
import { useStore } from './store'

export default function Menu() {
const folder = useStore((state) => state.config?.folder)
const folder = useStore((state) => state.config?.folder || '')
const openProject = useStore((state) => state.openProject)
const projectName = useStore((state) => state.config?.project.name)
if (!folder) return
const name = projectName || folder.split(/[\\/]/g).slice(-1)[0]
const name = projectName || folder.split(/[\\/]/g).slice(-1)[0] || ''
// @ts-ignore
const openDirectoryDialog = window?.opendataeditor?.openDirectoryDialog
const handleOpen = async () => {
Expand Down
10 changes: 7 additions & 3 deletions desktop/python.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export async function ensurePython() {

let message = 'existed'
if (!fs.existsSync(settings.APP_PYTHON)) {
await system.execFile(settings.ORIGINAL_PYTHON, ['-m', 'venv', settings.APP_PYTHON])
await system.execFile(settings.PYTHON_SOURCE, ['-m', 'venv', settings.APP_PYTHON])
message = 'created'
}

Expand All @@ -26,7 +26,9 @@ export async function ensureLibraries() {
const missing = required.filter((spec) => !installed.includes(spec))
if (!missing.length) return

await system.execFile(settings.PIP, [
await system.execFile(settings.PYTHON_TARGET, [
'-m',
'pip',
'install',
'--upgrade',
'--disable-pip-version-check',
Expand All @@ -50,7 +52,9 @@ export async function readRequiredLibraries() {
export async function readInstalledLibraries() {
log.info('[readInstalledLibraries]')

const text = await system.execFile(settings.PIP, [
const text = await system.execFile(settings.PYTHON_TARGET, [
'-m',
'pip',
'list',
'--format',
'freeze',
Expand Down
3 changes: 1 addition & 2 deletions desktop/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ import { spawnFile } from './system'
import timersp from 'timers/promises'
import * as settings from './settings'
import log from 'electron-log'
import * as settings from './settings'

export async function runServer({ serverPort }: { serverPort: number }) {
log.info('[runServer]', { serverPort })
const url = `http://localhost:${serverPort}`

// Start server
const proc = spawnFile(
settings.PYTHON,
settings.PYTHON_TARGET,
['-m', 'server', settings.APP_EXAMPLE, '--port', serverPort.toString()],
process.resourcesPath
)
Expand Down
5 changes: 2 additions & 3 deletions desktop/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,5 @@ export const APP_RUNNER = join(APP_HOME, 'runner')
export const APP_PYTHON = join(APP_HOME, 'python')
export const APP_EXAMPLE = join(APP_HOME, 'example')

export const ORIGINAL_PYTHON = join(APP_RUNNER, 'bin', 'python3')
export const PYTHON = join(APP_PYTHON, 'bin', 'python3')
export const PIP = join(APP_PYTHON, 'bin', 'pip3')
export const PYTHON_SOURCE = join(APP_RUNNER, 'bin', 'python3')
export const PYTHON_TARGET = join(APP_PYTHON, 'bin', 'python3')

0 comments on commit 9ee9138

Please sign in to comment.