mirror of
https://github.com/WolframResearch/WolframLanguageForJupyter.git
synced 2025-04-17 04:06:06 +00:00
Add handling of wolframscript binaries when specified through install methods
This commit is contained in:
parent
e91f036f37
commit
4779f3b880
@ -82,12 +82,17 @@ If[
|
||||
];
|
||||
|
||||
(* obtain details on how to connect to Jupyter, from Jupyter's invocation of "KernelForWolframLanguageForJupyter.wl" *)
|
||||
connectionAssoc = ToString /@ Association[Import[$CommandLine[[4]], "JSON"]];
|
||||
firstPosition = First[FirstPosition[$CommandLine, "positional", {$Failed}]];
|
||||
If[
|
||||
FailureQ[firstPosition],
|
||||
connectionAssoc = ToString /@ Association[Import[$CommandLine[[4]], "JSON"]];,
|
||||
connectionAssoc = ToString /@ Association[Import[$CommandLine[[firstPosition + 1]], "JSON"]];
|
||||
];
|
||||
|
||||
(* warnings to display in kernel information *)
|
||||
bannerWarning =
|
||||
If[
|
||||
Length[$CommandLine] > 4,
|
||||
MemberQ[$CommandLine, "ScriptInstall"],
|
||||
"\\n\\nThis Jupyter kernel was installed through the WolframLanguageForJupyter WolframScript script install option. Accordingly, updates to a WolframLanguageForJupyter paclet installed to a Wolfram Engine will not propagate to this installation.",
|
||||
""
|
||||
];
|
||||
|
@ -36,18 +36,48 @@ projectHome = DirectoryName[$InputFileName];
|
||||
(* returns string form *)
|
||||
getVersionFromKernel[mathBin_String] :=
|
||||
Module[{link, res},
|
||||
link =
|
||||
LinkLaunch[
|
||||
(* detect wolframscript *)
|
||||
If[
|
||||
StringMatchQ[Last[FileNameSplit[mathBin]], "wolframscript", IgnoreCase -> True],
|
||||
(* START: wolframscript support *)
|
||||
(* create a link *)
|
||||
link = LinkCreate[LinkProtocol -> "TCPIP"];
|
||||
If[
|
||||
FailureQ[link],
|
||||
Return[$Failed];
|
||||
];
|
||||
(* split a link to get its port *)
|
||||
splitLink = StringSplit[link[[1]], "@"];
|
||||
If[
|
||||
Length[splitLink] == 0,
|
||||
Return[$Failed];
|
||||
];
|
||||
(* launch the provided wolframscript and have it connect to the link above *)
|
||||
(* RunProcess also works here *)
|
||||
(* void *) LinkLaunch[
|
||||
StringJoin[
|
||||
{
|
||||
"\"",
|
||||
mathBin,
|
||||
"\" -wstp"
|
||||
}
|
||||
mathBin, " ",
|
||||
"-code", " ",
|
||||
"\"\$Output = {}; \$ParentLink = LinkConnect[\\\"", First[splitLink], "\\\", LinkProtocol->\\\"TCPIP\\\"]; Pause[2];\"", " ",
|
||||
"; echo "
|
||||
]
|
||||
];
|
||||
If[FailureQ[link],
|
||||
Return[$Failed];
|
||||
(* END: wolframscript support *)
|
||||
,
|
||||
(* normal wolfram/WolframKernel link launch method *)
|
||||
link =
|
||||
LinkLaunch[
|
||||
StringJoin[
|
||||
{
|
||||
"\"",
|
||||
mathBin,
|
||||
"\" -wstp"
|
||||
}
|
||||
]
|
||||
];
|
||||
If[FailureQ[link],
|
||||
Return[$Failed];
|
||||
];
|
||||
];
|
||||
(* bleed link *)
|
||||
While[LinkReadyQ[link, 0.5], LinkRead[link];];
|
||||
@ -295,7 +325,8 @@ configureJupyter[specs_Association, removeQ_?BooleanQ, removeAllQ_?BooleanQ] :=
|
||||
(only) if the Wolfram Engine being installed is the same as the one used to execute this command *)
|
||||
"-script",
|
||||
FileNameJoin[{projectHome, "Resources", "KernelForWolframLanguageForJupyter.wl"}],
|
||||
"{connection_file}"
|
||||
"positional",
|
||||
"{connection_file}",
|
||||
(* , "-noprompt" *)
|
||||
},
|
||||
"display_name" -> displayName,
|
||||
|
@ -30,18 +30,48 @@ projectHome = If[StringQ[$InputFileName] && $InputFileName != "", DirectoryName[
|
||||
(* returns string form *)
|
||||
getVersionFromKernel[mathBin_String] :=
|
||||
Module[{link, res},
|
||||
link =
|
||||
LinkLaunch[
|
||||
(* detect wolframscript *)
|
||||
If[
|
||||
StringMatchQ[Last[FileNameSplit[mathBin]], "wolframscript", IgnoreCase -> True],
|
||||
(* START: wolframscript support *)
|
||||
(* create a link *)
|
||||
link = LinkCreate[LinkProtocol -> "TCPIP"];
|
||||
If[
|
||||
FailureQ[link],
|
||||
Return[$Failed];
|
||||
];
|
||||
(* split a link to get its port *)
|
||||
splitLink = StringSplit[link[[1]], "@"];
|
||||
If[
|
||||
Length[splitLink] == 0,
|
||||
Return[$Failed];
|
||||
];
|
||||
(* launch the provided wolframscript and have it connect to the link above *)
|
||||
(* RunProcess also works here *)
|
||||
(* void *) LinkLaunch[
|
||||
StringJoin[
|
||||
{
|
||||
"\"",
|
||||
mathBin,
|
||||
"\" -wstp"
|
||||
}
|
||||
mathBin, " ",
|
||||
"-code", " ",
|
||||
"\"\$Output = {}; \$ParentLink = LinkConnect[\\\"", First[splitLink], "\\\", LinkProtocol->\\\"TCPIP\\\"]; Pause[2];\"", " ",
|
||||
"; echo "
|
||||
]
|
||||
];
|
||||
If[FailureQ[link],
|
||||
Return[$Failed];
|
||||
(* END: wolframscript support *)
|
||||
,
|
||||
(* normal wolfram/WolframKernel link launch method *)
|
||||
link =
|
||||
LinkLaunch[
|
||||
StringJoin[
|
||||
{
|
||||
"\"",
|
||||
mathBin,
|
||||
"\" -wstp"
|
||||
}
|
||||
]
|
||||
];
|
||||
If[FailureQ[link],
|
||||
Return[$Failed];
|
||||
];
|
||||
];
|
||||
(* bleed link *)
|
||||
While[LinkReadyQ[link, 0.5], LinkRead[link];];
|
||||
@ -311,7 +341,16 @@ configureJupyter[specs_Association, removeQ_?BooleanQ, removeAllQ_?BooleanQ] :=
|
||||
Export[
|
||||
FileNameJoin[{tempDir, "kernel.json"}],
|
||||
Association[
|
||||
"argv" -> {mathBin, "-script", kernelScript, "{connection_file}", "ScriptInstall" (* , "-noprompt" *)},
|
||||
"argv" ->
|
||||
{
|
||||
mathBin,
|
||||
"-script",
|
||||
kernelScript,
|
||||
"positional",
|
||||
"{connection_file}",
|
||||
(* remove any wolframscript noise, if wolframscript was used*)
|
||||
"ScriptInstall" (* , "-noprompt" *)
|
||||
},
|
||||
"display_name" -> displayName,
|
||||
"language" -> "Wolfram Language"
|
||||
]
|
||||
|
Loading…
x
Reference in New Issue
Block a user