Skip to content

Commit f57b3a7

Browse files
authored
Merge pull request #80 from FilippoPolo/master
More strict installer
2 parents 4dcc5f4 + a31dd97 commit f57b3a7

File tree

6 files changed

+60
-36
lines changed

6 files changed

+60
-36
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
## Ignore Visual Studio temporary files, build results, and
22
## files generated by popular Visual Studio add-ons.
33

4+
.vs/
5+
46
# User-specific files
57
*.suo
68
*.user

ipython-profile/kernel.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
define(function () {
22

3+
var staticFolder = "/kernelspecs/ifsharp/static/";
4+
35
var link = document.createElement("link");
46
link.type = "text/css";
57
link.rel = "stylesheet";
6-
link.href = "/kernelspecs/ifsharp/static/custom/fsharp.css";
8+
link.href = staticFolder + "custom/fsharp.css";
79
document.getElementsByTagName("head")[0].appendChild(link);
810

911
require(['codemirror/addon/mode/loadmode']);
@@ -19,7 +21,7 @@ define(function () {
1921
console.log('add metadata hint that language is fsharp...');
2022
}
2123

22-
require(['/kernelspecs/ifsharp/static/custom/fsharp.js']);
24+
require([staticFolder + 'custom/fsharp.js']);
2325

2426
IPython.CodeCell.options_default.cm_config.mode = 'fsharp';
2527

@@ -62,7 +64,7 @@ define(function () {
6264
return results;
6365
}
6466

65-
require(['/kernelspecs/ifsharp/static/custom/webintellisense.js', '/kernelspecs/ifsharp/static/custom/webintellisense-codemirror.js'], function () {
67+
require([staticFolder + 'custom/webintellisense.js', staticFolder + 'custom/webintellisense-codemirror.js'], function () {
6668
// applies intellisense hooks onto a cell
6769
function applyIntellisense(cell) {
6870
if (cell.cell_type !== 'code') { return; }
@@ -156,7 +158,7 @@ define(function () {
156158

157159
// replace the image
158160
var img = $('.container img')[0];
159-
img.src = "/kernelspecs/ifsharp/static/custom/ifsharp_logo.png";
161+
img.src = staticFolder + "custom/ifsharp_logo.png";
160162

161163
}
162164

paket.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ NUGET
2121
xunit.abstractions (2.0)
2222
xunit.extensibility.execution (2.1) - framework: >= net451
2323
xunit.extensibility.core (2.1) - framework: >= net45, dnx451, dnxcore50, monoandroid, monotouch, xamarinios, winv4.5, wpv8.0, wpav8.1
24-
xunit.runner.console (2.1) - framework: >= net451
24+
xunit.runner.console (2.1) - framework: >= net451

src/IfSharp.Kernel/App.fs

Lines changed: 47 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ module App =
143143
Kernel.Value.AddPayload(text.ToString())
144144

145145
/// Installs the ifsharp files if they do not exist, then starts jupyter with the ifsharp profile
146-
let InstallAndStart(forceInstall) =
146+
let InstallAndStart(forceInstall, start) =
147147

148148
let thisExecutable = Assembly.GetEntryAssembly().Location
149149
let userDir = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
@@ -161,12 +161,31 @@ module App =
161161
createDir tempDir
162162
createDir customDir
163163

164-
let configFile = Path.Combine(kernelDir, "ipython_config.py")
165-
let configqtFile = Path.Combine(kernelDir, "ipython_qtconsole_config.py")
166-
let kernelFile = Path.Combine(kernelDir, "kernel.json")
167-
if forceInstall || (File.Exists(configFile) = false) then
164+
let allFiles = new System.Collections.Generic.List<string>()
165+
let addFile fn = allFiles.Add(fn); fn
166+
let configFile = Path.Combine(kernelDir, "ipython_config.py") |> addFile
167+
let configqtFile = Path.Combine(kernelDir, "ipython_qtconsole_config.py") |> addFile
168+
let kernelFile = Path.Combine(kernelDir, "kernel.json") |> addFile
169+
let logoFile = Path.Combine(customDir, "ifsharp_logo.png") |> addFile
170+
let kjsFile = Path.Combine(kernelDir, "kernel.js") |> addFile
171+
let fjsFile = Path.Combine(customDir, "fsharp.js") |> addFile
172+
let wjsFile = Path.Combine(customDir, "webintellisense.js") |> addFile
173+
let wcjsFile = Path.Combine(customDir, "webintellisense-codemirror.js") |> addFile
174+
let logo64File = Path.Combine(kernelDir, "logo-64x64.png") |> addFile
175+
let logo32File = Path.Combine(kernelDir, "logo-32x32.png") |> addFile
176+
let versionFile = Path.Combine(kernelDir, "version.txt") |> addFile
177+
let missingFiles = Seq.exists (fun fn -> File.Exists(fn) = false) allFiles
178+
179+
let differentVersion = File.Exists(versionFile) && File.ReadAllText(versionFile) <> Config.Version
180+
181+
if forceInstall then printfn "Force install required, performing install..."
182+
else if missingFiles then printfn "One or more files are missing, performing install..."
183+
else if differentVersion then printfn "Different version found, performing install..."
184+
185+
if forceInstall || missingFiles || differentVersion then
168186

169-
printfn "Config file does not exist, performing install..."
187+
// write the version file
188+
File.WriteAllText(versionFile, Config.Version);
170189

171190
// write the startup script
172191
let codeTemplate = IfSharpResources.ipython_config()
@@ -184,7 +203,6 @@ module App =
184203
File.WriteAllText(configqtFile, codeqt)
185204

186205
// write custom logo file
187-
let logoFile = Path.Combine(customDir, "ifsharp_logo.png")
188206
printfn "Saving custom logo [%s]" logoFile
189207
IfSharpResources.ifsharp_logo().Save(logoFile)
190208

@@ -194,24 +212,20 @@ module App =
194212
File.WriteAllText(cssFile, IfSharpResources.fsharp_css())
195213

196214
// write kernel js file
197-
let jsFile = Path.Combine(kernelDir, "kernel.js")
198-
printfn "Saving kernel js [%s]" jsFile
199-
File.WriteAllText(jsFile, IfSharpResources.kernel_js())
215+
printfn "Saving kernel js [%s]" kjsFile
216+
File.WriteAllText(kjsFile, IfSharpResources.kernel_js())
200217

201218
// write fsharp js file
202-
let jsFile = Path.Combine(customDir, "fsharp.js")
203-
printfn "Saving fsharp js [%s]" jsFile
204-
File.WriteAllText(jsFile, IfSharpResources.fsharp_js())
219+
printfn "Saving fsharp js [%s]" fjsFile
220+
File.WriteAllText(fjsFile, IfSharpResources.fsharp_js())
205221

206222
// write webintellisense js file
207-
let jsFile = Path.Combine(customDir, "webintellisense.js")
208-
printfn "Saving webintellisense js [%s]" jsFile
209-
File.WriteAllText(jsFile, IfSharpResources.webintellisense_js())
223+
printfn "Saving webintellisense js [%s]" wjsFile
224+
File.WriteAllText(wjsFile, IfSharpResources.webintellisense_js())
210225

211226
// write webintellisense-codemirror js file
212-
let jsFile = Path.Combine(customDir, "webintellisense-codemirror.js")
213-
printfn "Saving webintellisense-codemirror js [%s]" jsFile
214-
File.WriteAllText(jsFile, IfSharpResources.webintellisense_codemirror_js())
227+
printfn "Saving webintellisense-codemirror js [%s]" wcjsFile
228+
File.WriteAllText(wcjsFile, IfSharpResources.webintellisense_codemirror_js())
215229

216230
// Make the Kernel info folder
217231
let jsonTemplate = IfSharpResources.ifsharp_kernel_json()
@@ -224,31 +238,35 @@ module App =
224238
printfn "Saving custom kernel.json file [%s]" kernelFile
225239
File.WriteAllText(kernelFile, code)
226240

227-
let logo64File = Path.Combine(kernelDir, "logo-64x64.png")
228241
printfn "Saving kernel icon [%s]" logo64File
229242
IfSharpResources.ifsharp_64logo().Save(logo64File)
230243

231-
let logo32File = Path.Combine(kernelDir, "logo-32x32.png")
232244
printfn "Saving kernel icon [%s]" logo32File
233245
IfSharpResources.ifsharp_32logo().Save(logo32File)
234246

235-
printfn "Starting Jupyter notebook..."
236-
let p = new Process()
237-
p.StartInfo.FileName <- "jupyter"
238-
p.StartInfo.Arguments <- "notebook"
239-
p.StartInfo.WorkingDirectory <- userDir
247+
if start then
248+
(
249+
printfn "Starting ipython..."
250+
let p = new Process()
251+
p.StartInfo.FileName <- "jupyter"
252+
p.StartInfo.Arguments <- "notebook"
253+
p.StartInfo.WorkingDirectory <- userDir
240254

241-
// tell the user something bad happened
242-
if p.Start() = false then printfn "Unable to start jupyter, please install jupyter first"
255+
// tell the user something bad happened
256+
if p.Start() = false then printfn "Unable to start jupyter, please install jupyter first"
257+
)
243258

244259
/// First argument must be an ipython connection file, blocks forever
245260
let Start (args : array<string>) =
246261

247262
if args.Length = 0 then
248263

249-
InstallAndStart(true)
264+
InstallAndStart(true, true)
250265

251266
else
267+
// Verify kernel installation status
268+
InstallAndStart(false, false)
269+
252270
// Clear the temporary folder
253271
try
254272
if Directory.Exists(Config.TempDir) then Directory.Delete(Config.TempDir, true)

src/IfSharp.Kernel/Config.fs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,6 @@ let KernelDir =
4444
let kernelDir = Path.Combine(kernelsDir, "ifsharp")
4545
kernelDir
4646
let StaticDir = Path.Combine(KernelDir, "static")
47-
let TempDir = Path.Combine(StaticDir, "temp");
47+
let TempDir = Path.Combine(StaticDir, "temp")
48+
49+
let Version = "1"

src/IfSharp.Kernel/Kernel.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ type IfSharpKernel(connectionInformation : ConnectionInformation) =
511511
try
512512
while true do
513513
let hb = hbSocket.ReceiveMultipartBytes() in
514-
hbSocket.SendMultipartBytes(hb)
514+
hbSocket.SendMultipartBytes hb
515515
with
516516
| ex -> handleException ex
517517

0 commit comments

Comments
 (0)