From ec7744c7c19b817f76c2f720d7d83a5169720594 Mon Sep 17 00:00:00 2001 From: Marc Liyanage Date: Wed, 30 Oct 2013 13:50:39 -0700 Subject: [PATCH] Clear matplotlib's font cache file at launch to prevent sandboxing violations when the app bundle was moved since the last launch. See http://stackoverflow.com/questions/19675235/matplotlib-output-not-showing-up-inline-in-ipython-notebook-despite-pylab-inli/19676283#19676283 for details. --- .../NotebookWindowController.m | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/IPython Notebook/Notebook Controller/NotebookWindowController.m b/IPython Notebook/Notebook Controller/NotebookWindowController.m index f4d0acc..bb0cfb5 100644 --- a/IPython Notebook/Notebook Controller/NotebookWindowController.m +++ b/IPython Notebook/Notebook Controller/NotebookWindowController.m @@ -218,6 +218,8 @@ - (IBAction)openNotebooksFolder:(id)sender - (BOOL)launchNotebookServerTask { + [self clearApplicationBundleLocationDependentCacheFiles]; + NSURL *virtualEnvPythonURL = [[NSBundle mainBundle] URLForResource:@"python" withExtension:nil subdirectory:@"virtualenv/bin"]; NSURL *launchScriptURL = [[NSBundle mainBundle] URLForResource:@"launch-ipython" withExtension:@"py" subdirectory:@"virtualenv/bin"]; NSAssert(launchScriptURL, NSLocalizedString(@"Unable to determine url to launch-ipython.py script in resources", nil)); @@ -256,6 +258,22 @@ - (BOOL)launchNotebookServerTask } +- (void)clearApplicationBundleLocationDependentCacheFiles +{ + NSURL *homeDirectoryUrl = [NSURL fileURLWithPath:NSHomeDirectory()]; + NSURL *matplotlibFontListCacheUrl = [homeDirectoryUrl URLByAppendingPathComponent:@".matplotlib/fontList.cache"]; + + NSFileManager *fm = [NSFileManager defaultManager]; + if ([fm fileExistsAtPath:[matplotlibFontListCacheUrl path]]) { + NSLog(@"Removing cache file %@", [matplotlibFontListCacheUrl path]); + NSError *error = nil; + if (![fm removeItemAtURL:matplotlibFontListCacheUrl error:&error]) { + NSLog(@"Unable to remove cache file: %@", error); + } + } +} + + - (NSString *)customPythonPath { if (![self.pythonPathURLs count]) {