Skip to content

Commit d18b17a

Browse files
installation updates
1 parent 063910e commit d18b17a

File tree

3 files changed

+93
-3
lines changed

3 files changed

+93
-3
lines changed

.vscode/settings.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"[python]": {
3+
"editor.defaultFormatter": "ms-python.black-formatter"
4+
},
5+
"python.formatting.provider": "none"
6+
}

README.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
1-
# Installation Instruction for Jaclang Jupyter Kernel
1+
# A Jupyter kernel for Jaclang
2+
3+
## Installation
4+
5+
Installation Instruction for Jaclang Jupyter Kernel
6+
7+
- Step 1:
8+
9+
```
10+
pip install jackernel
11+
python3 -m jackernel.install
12+
```
213

3-
- Step 1: Open the Terminal and go to `jaclang/support/`
4-
- Step 2: Run the command `jupyter kernelspec install --replace --user jupyter_kernel`
514
- Step 3: Start the Jupyter Notebook; If you already installed you have to refresh the server.
615
- Step 4: Open a new notebook and select the kernel as the `Jac`,
716

jackernel/install.py

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import json
2+
import os
3+
import sys
4+
import argparse
5+
import pathlib
6+
import shutil
7+
8+
from jupyter_client.kernelspec import KernelSpecManager
9+
from IPython.utils.tempdir import TemporaryDirectory
10+
from .resources import _ICON_PATH
11+
12+
kernel_json = {
13+
"argv": ["python", "-m", "jackernel.kernel", "-f", "{connection_file}"],
14+
"display_name": "Jac",
15+
"language_info": {
16+
"name": "python",
17+
"mimetype": "text/plain",
18+
"pygments_lexer": "jac_lexer",
19+
"file_extension": ".jac",
20+
},
21+
}
22+
23+
24+
def install_my_kernel_spec(user=True, prefix=None):
25+
with TemporaryDirectory() as td:
26+
os.chmod(td, 0o755) # Starts off as 700, not user readable
27+
with open(os.path.join(td, "kernel.json"), "w") as f:
28+
json.dump(kernel_json, f, sort_keys=True)
29+
# shutil.copyfile(_ICON_PATH, pathlib.Path(td) / _ICON_PATH.name)
30+
KernelSpecManager().install_kernel_spec(td, "Jac", user=user, prefix=prefix)
31+
32+
33+
def _is_root():
34+
try:
35+
return os.geteuid() == 0
36+
except AttributeError:
37+
return False # assume not an admin on non-Unix platforms
38+
39+
40+
def main(argv=None):
41+
parser = argparse.ArgumentParser(description="Install KernelSpec for Jac Kernel")
42+
prefix_locations = parser.add_mutually_exclusive_group()
43+
44+
prefix_locations.add_argument(
45+
"--user",
46+
help="Install KernelSpec in user's home directory",
47+
action="store_true",
48+
)
49+
prefix_locations.add_argument(
50+
"--sys-prefix",
51+
help="Install KernelSpec in sys.prefix. Useful in conda / virtualenv",
52+
action="store_true",
53+
dest="sys_prefix",
54+
)
55+
prefix_locations.add_argument(
56+
"--prefix", help="Install KernelSpec in this prefix", default=None
57+
)
58+
59+
args = parser.parse_args(argv)
60+
61+
user = False
62+
prefix = None
63+
if args.sys_prefix:
64+
prefix = sys.prefix
65+
elif args.prefix:
66+
prefix = args.prefix
67+
elif args.user or not _is_root():
68+
user = True
69+
70+
install_my_kernel_spec(user=user, prefix=prefix)
71+
72+
73+
if __name__ == "__main__":
74+
main()
75+
print("Installed jaclang kernel spec")

0 commit comments

Comments
 (0)