Closed Daksol closed 2 years ago
Hi, Thank you for your interest in this extension and sorry for your inconvenience.
To migrate your code snippets,
import os
import json
import glob
def extract_id(json):
try:
return json['id']
except KeyError:
return 0
snippets = []
counter = 0
for filepath in glob.glob(os.path.join('snippets', '*.json')):
with open(filepath) as f:
content = json.load(f)
content['id'] = counter
snippets.append(content)
counter+=1
snippets.sort(key=extract_id)
print('{"snippets": [\n')
for snip in snippets:
if not('tags' in snip):
snip["tags"] = []
if snippets.index(snip) == len(snippets)-1:
print(json.dumps(snip, indent=4, sort_keys=True))
else:
print(json.dumps(snip, indent=4, sort_keys=True), end=",\n")
print("]\n}\n")
Thanks. That worked for me.
I started off using the Snippets functionality available in Elyra. But Elyra is a big installation, and the snippets is the only bit I am using. So moving to the jupytercalpoly/jupyterlab-code-snippets looked a good option.
I need some small help in migrating my existing Elyra snippets - these are saved as "one snippet per json file" in directory
*USERPROFILE*\AppData\Roaming\jupyter\metadata\code-snippets
At this point I still have the Elyra snippets extension in place.
first attempt to import legacy snippets to jupytercalpoly snippets
*USERPROFILE*\.jupyter\lab\user-settings\jupyterlab-code-snippets
all in a single filesnippets.jupyterlab-settings
.snippets.jupyterlab-settings
. I allocated each snippet a unique sequence number following on from those id numbers already there.snippets.jupyterlab-settings
has been restored to its "factory setting" - same as when first installed.second attempt
*USERPROFILE*\AppData\Roaming\jupyter\nbextensions\snippets