|
1 | 1 | """ API used by spec finders and manager |
2 | 2 | """ |
3 | | -import os |
4 | 3 | import pathlib |
5 | 4 | import shutil |
6 | 5 | import sys |
7 | 6 | from typing import Callable, Dict, List, Text |
8 | 7 |
|
9 | | -from jupyterlab.commands import get_app_dir |
10 | 8 | from notebook.transutils import _ |
11 | 9 | from traitlets import List as List_, Unicode, default |
12 | 10 | from traitlets.config import LoggingConfigurable |
@@ -58,20 +56,32 @@ def _default_nodejs(self): |
58 | 56 |
|
59 | 57 | @default("node_roots") |
60 | 58 | def _default_node_roots(self): |
61 | | - """ get the "usual suspects" for where node_modules may be found |
| 59 | + """ get the "usual suspects" for where `node_modules` may be found |
62 | 60 |
|
63 | 61 | - where this was launch (usually the same as NotebookApp.notebook_dir) |
64 | | - - the JupyterLab staging folder |
| 62 | + - the JupyterLab staging folder (if available) |
65 | 63 | - wherever conda puts it |
66 | 64 | - wherever some other conventions put it |
67 | 65 | """ |
68 | | - return [ |
69 | | - os.getcwd(), |
70 | | - pathlib.Path(get_app_dir()) / "staging", |
71 | | - pathlib.Path(sys.prefix) / "lib", |
72 | | - # TODO: "well-known" windows paths |
73 | | - sys.prefix, |
74 | | - ] |
| 66 | + |
| 67 | + # check where the server was started first |
| 68 | + roots = [pathlib.Path.cwd()] |
| 69 | + |
| 70 | + # try jupyterlab staging next |
| 71 | + try: |
| 72 | + from jupyterlab import commands |
| 73 | + |
| 74 | + roots += [pathlib.Path(commands.get_app_dir()) / "staging"] |
| 75 | + except ImportError: # pragma: no cover |
| 76 | + pass |
| 77 | + |
| 78 | + # conda puts stuff in $PREFIX/lib on POSIX systems |
| 79 | + roots += [pathlib.Path(sys.prefix) / "lib"] |
| 80 | + |
| 81 | + # ... but right in %PREFIX% on nt |
| 82 | + roots += [pathlib.Path(sys.prefix)] |
| 83 | + |
| 84 | + return roots |
75 | 85 |
|
76 | 86 |
|
77 | 87 | # Gotta be down here so it can by typed... really should have a IL |
|
0 commit comments