From 2e8385a039f714de93f746fd2ea75abb6d6c9a9d Mon Sep 17 00:00:00 2001 From: Connor Burns Date: Fri, 16 Feb 2024 12:36:21 -0700 Subject: [PATCH] More adaptive Pluto locate --- assets/env_for_julia/Manifest.toml | 11 ++++++++--- assets/locate_pluto.jl | 26 ++++++++++++++++++++++++-- src/main/plutoProcess.ts | 7 +++++++ src/main/startup.ts | 6 +++--- 4 files changed, 42 insertions(+), 8 deletions(-) diff --git a/assets/env_for_julia/Manifest.toml b/assets/env_for_julia/Manifest.toml index 2aeb9bf..b79f798 100644 --- a/assets/env_for_julia/Manifest.toml +++ b/assets/env_for_julia/Manifest.toml @@ -71,6 +71,11 @@ git-tree-sha1 = "e90caa41f5a86296e014e148ee061bd6c3edec96" uuid = "460bff9d-24e4-43bc-9d9f-a8973cb893f4" version = "0.1.9" +[[deps.ExpressionExplorer]] +git-tree-sha1 = "bce17cd0180a75eec637d6e3f8153011b8bdb25a" +uuid = "21656369-7473-754a-2065-74616d696c43" +version = "1.0.0" + [[deps.ExproniconLite]] git-tree-sha1 = "637309d52dd9034af79c9df9b5f07a824e30ca2f" uuid = "55351af7-c7e9-48d6-89ff-24e801d99491" @@ -235,10 +240,10 @@ uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" version = "1.9.0" [[deps.Pluto]] -deps = ["Base64", "Configurations", "Dates", "Downloads", "FileWatching", "FuzzyCompletions", "HTTP", "HypertextLiteral", "InteractiveUtils", "Logging", "LoggingExtras", "MIMEs", "Malt", "Markdown", "MsgPack", "Pkg", "PrecompileSignatures", "PrecompileTools", "REPL", "RegistryInstances", "RelocatableFolders", "Scratch", "Sockets", "TOML", "Tables", "URIs", "UUIDs"] -git-tree-sha1 = "42d7bd2e5df1c504e42125cf49dfd95fa38174f6" +deps = ["Base64", "Configurations", "Dates", "Downloads", "ExpressionExplorer", "FileWatching", "FuzzyCompletions", "HTTP", "HypertextLiteral", "InteractiveUtils", "Logging", "LoggingExtras", "MIMEs", "Malt", "Markdown", "MsgPack", "Pkg", "PrecompileSignatures", "PrecompileTools", "REPL", "RegistryInstances", "RelocatableFolders", "Scratch", "Sockets", "TOML", "Tables", "URIs", "UUIDs"] +git-tree-sha1 = "449f468cbb80c3eec6e6d8443a0913d8bbad4d0d" uuid = "c3e4b0f8-55cb-11ea-2926-15256bba5781" -version = "0.19.31" +version = "0.19.38" [[deps.PrecompileSignatures]] git-tree-sha1 = "18ef344185f25ee9d51d80e179f8dad33dc48eb1" diff --git a/assets/locate_pluto.jl b/assets/locate_pluto.jl index 02315f5..ef05fa0 100644 --- a/assets/locate_pluto.jl +++ b/assets/locate_pluto.jl @@ -1,2 +1,24 @@ -# designed to very quickly determine Pluto's real path without first importing it -println(normpath(Base.locate_package(Base.identify_package("Pluto")), "..", "..")) \ No newline at end of file +using Pkg + +function main() + # designed to very quickly determine Pluto's real path without first importing it + try_print = () -> begin + pkg_loc = Base.locate_package(Base.identify_package("Pluto")) + if !isnothing(pkg_loc) + println(normpath(pkg_loc, "..", "..")) + return true + end + false + end + + if try_print() return end + + # Package was not found if pkg is nothing. Assume this means env_for_pluto has not been instantiated + Pkg.instantiate() # env_for_pluto should already be activated by the caller + + if try_print() return end + + @error "Could not locate Pluto!" +end + +main() diff --git a/src/main/plutoProcess.ts b/src/main/plutoProcess.ts index d3bbbb4..8b6d32e 100644 --- a/src/main/plutoProcess.ts +++ b/src/main/plutoProcess.ts @@ -39,6 +39,7 @@ export function findPluto(): Promise { if (_plutoLocation !== null) resolve(String(_plutoLocation)); const juliaCmd = findJulia(); + let resolved = false; const options = [ `--project=${plutoProject}`, @@ -49,11 +50,17 @@ export function findPluto(): Promise { }); proc.stdout.on('data', (chunk) => { _plutoLocation = chunk.toString(); + resolved = true; resolve(String(_plutoLocation)); }); proc.stderr.on('error', (err) => { juliaLogger.error('Error determining Pluto.jl package location:', err); reject(); }); + proc.on('close', () => { + if (!resolved) { + reject('Pluto could not be found with `locate_pluto.jl`!'); + } + }); }); } diff --git a/src/main/startup.ts b/src/main/startup.ts index d0e2111..79816aa 100644 --- a/src/main/startup.ts +++ b/src/main/startup.ts @@ -4,7 +4,7 @@ import { generalLogger, juliaLogger } from './logger'; import { DEPOT_LOCATION, READONLY_DEPOT_LOCATION, getAssetPath } from './paths'; import { findJulia, findPluto } from './plutoProcess'; import { copyDirectoryRecursive, setAxiosDefaults } from './util'; -import { App, BrowserWindow, dialog } from 'electron'; +import { App, dialog } from 'electron'; import chalk from 'chalk'; import { spawn } from 'node:child_process'; import Pluto from './pluto'; @@ -13,11 +13,11 @@ import { GlobalWindowManager } from './windowHelpers'; export async function startup(app: App) { Globals.JULIA = findJulia(); + generalLogger.log(`Julia found at: ${Globals.JULIA}`); Globals.JULIA_PROJECT = process.env.DEBUG_PROJECT_PATH ?? getAssetPath('env_for_julia'); Globals.PLUTO_LOCATION = await findPluto(); - - generalLogger.log(`Julia found at: ${Globals.JULIA}`); + generalLogger.log(`Pluto found at: ${Globals.PLUTO_LOCATION}`); const statusUpdate = (status: string) => GlobalWindowManager.all((p) =>