Skip to content

Commit

Permalink
More adaptive Pluto locate
Browse files Browse the repository at this point in the history
  • Loading branch information
ctrekker committed Feb 16, 2024
1 parent 39e207d commit 2e8385a
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 8 deletions.
11 changes: 8 additions & 3 deletions assets/env_for_julia/Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
26 changes: 24 additions & 2 deletions assets/locate_pluto.jl
Original file line number Diff line number Diff line change
@@ -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")), "..", ".."))
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()
7 changes: 7 additions & 0 deletions src/main/plutoProcess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export function findPluto(): Promise<string> {
if (_plutoLocation !== null) resolve(String(_plutoLocation));

const juliaCmd = findJulia();
let resolved = false;

const options = [
`--project=${plutoProject}`,
Expand All @@ -49,11 +50,17 @@ export function findPluto(): Promise<string> {
});
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`!');
}
});
});
}
6 changes: 3 additions & 3 deletions src/main/startup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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) =>
Expand Down

0 comments on commit 2e8385a

Please sign in to comment.