-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
183 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import os | ||
import sys | ||
import argparse | ||
from pathlib import Path | ||
|
||
|
||
def get_extension_paths(): | ||
base_dir = Path(sys.prefix) | ||
nglview_js_widgets = "nglview-js-widgets" | ||
nbextension_dest = base_dir / "share" / "jupyter" / "nbextensions" / nglview_js_widgets | ||
labextension_dest = base_dir / "share" / "jupyter" / "labextensions" / nglview_js_widgets | ||
return nbextension_dest, labextension_dest | ||
|
||
|
||
def create_symlink(source, destination): | ||
try: | ||
if os.path.islink(destination): | ||
os.remove(destination) | ||
os.symlink(source, destination) | ||
print(f"Created symlink: {destination} -> {source}") | ||
except OSError as e: | ||
print(f"Failed to create symlink: {e}", file=sys.stderr) | ||
|
||
|
||
def remove_symlink(destination): | ||
try: | ||
if os.path.islink(destination): | ||
os.remove(destination) | ||
print(f"Removed symlink: {destination}") | ||
else: | ||
print(f"No symlink to remove at: {destination}") | ||
except OSError as e: | ||
print(f"Failed to remove symlink: {e}", file=sys.stderr) | ||
|
||
|
||
def main(): | ||
parser = argparse.ArgumentParser(description="Create or remove symlinks for nbextension and labextension.") | ||
parser.add_argument('-d', '--delete', action='store_true', help="Remove the symlinks instead of creating them.") | ||
args = parser.parse_args() | ||
|
||
nbextension_dest, labextension_dest = get_extension_paths() | ||
|
||
base_dir = Path(__file__).resolve().parent.parent | ||
nbextension_source = base_dir / 'nglview' / 'nbextension' | ||
labextension_source = base_dir / 'nglview' / 'labextension' | ||
|
||
if args.delete: | ||
remove_symlink(nbextension_dest) | ||
remove_symlink(labextension_dest) | ||
else: | ||
create_symlink(nbextension_source, nbextension_dest) | ||
create_symlink(labextension_source, labextension_dest) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 20, | ||
"id": "82035655-b580-4e4d-86bf-5a90563c2840", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"application/vnd.jupyter.widget-view+json": { | ||
"model_id": "c7cd4ef8a8ca410c96f8cad4d48928b2", | ||
"version_major": 2, | ||
"version_minor": 0 | ||
}, | ||
"text/plain": [ | ||
"NGLWidget()" | ||
] | ||
}, | ||
"metadata": {}, | ||
"output_type": "display_data" | ||
} | ||
], | ||
"source": [ | ||
"import nglview as nv\n", | ||
"\n", | ||
"view = nv.demo()\n", | ||
"view" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 23, | ||
"id": "7bf1502e-ce30-4b5c-9a72-5a2360322c82", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"view.control.rotate([0.6, -0.4, 0.3, -0.4])" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 24, | ||
"id": "d07a8c2b-806d-42c6-b841-e49460688348", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"nv.write_html('index.html', view)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 25, | ||
"id": "f397830a-2c05-4275-bdbe-40e0b58f621a", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"!open index.html" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 26, | ||
"id": "5c00397d-cdd4-4196-91e4-fb55d98774a0", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"[65.20023905320915,\n", | ||
" -93.88834423662117,\n", | ||
" 5.2160191242567215,\n", | ||
" 0,\n", | ||
" -31.29611474554039,\n", | ||
" 13.040047810641841,\n", | ||
" -93.88834423662117,\n", | ||
" 0,\n", | ||
" 88.67232511236445,\n", | ||
" 31.29611474554039,\n", | ||
" -5.216019124256737,\n", | ||
" 0,\n", | ||
" -37.284461975097656,\n", | ||
" -42.47041130065918,\n", | ||
" -44.55349826812744,\n", | ||
" 1]" | ||
] | ||
}, | ||
"execution_count": 26, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"view._camera_orientation" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3 (ipykernel)", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.12.7" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |