Skip to content

Commit bff8f10

Browse files
committed
Added transition page to docs with python script.
1 parent b65542c commit bff8f10

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

docs/user/transition.rst

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
Transition to 2.1.0
2+
===================
3+
4+
The 2.1.0 update has made snippets globally accessible across notebooks by saving
5+
them at the JupyterLab Settings API endpoint.
6+
7+
One side effect of this change is that snippets created in the previous version of
8+
this extension will not be supported. The /snippets folder will continue to be available
9+
if previously created in a project folder.
10+
11+
12+
Transferring Single Snippets
13+
----------------------------
14+
15+
To add old snippets to the new snippet location, simply copy the JSON object and go to:
16+
Settings > Advanced Settings Editor > Code Snippet Manager
17+
18+
In the User Preferences panel there will be an array of snippets existing globally
19+
(something like "snippets" : [...]) where the ... are the globally accessible
20+
snippets.
21+
22+
At the end of the existing list, paste the copied JSON object, make sure the id value is
23+
sequential to what already is in the list. Save using the save icon in the top right corner.
24+
Snippet should appear in the snippets panel!
25+
26+
27+
Transferring Multiple Snippets
28+
------------------------------
29+
30+
To help with converting entire /snippets folder worth of snippets we have developed a python
31+
script to help with the transition:
32+
33+
.. code::
34+
35+
import os
36+
import json
37+
import glob
38+
39+
def extract_id(json):
40+
try:
41+
return json['id']
42+
except KeyError:
43+
return 0
44+
45+
snippets = []
46+
counter = 0
47+
for filepath in glob.glob(os.path.join('snippets', '*.json')):
48+
with open(filepath) as f:
49+
content = json.load(f)
50+
content['id'] = counter
51+
snippets.append(content)
52+
counter+=1
53+
54+
snippets.sort(key=extract_id)
55+
for snip in snippets:
56+
if not('tags' in snip):
57+
snip["tags"] = []
58+
print(snip, end=",\n")
59+
60+
61+
This script will concatenate and print out all of the json objects in a /snippets folder
62+
in a project. After running the script, copy the output and paste into the User Preferences
63+
panel in settings.

0 commit comments

Comments
 (0)