[PATCH] D154351: [llvm][TableGen][Jupyter] Record current python when kernel is installed
David Spickett via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 3 07:59:54 PDT 2023
DavidSpickett updated this revision to Diff 536778.
DavidSpickett added a comment.
Remove the very proffesional runtime error I was using to check PYTHONPATH wasn't needed :).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D154351/new/
https://reviews.llvm.org/D154351
Files:
llvm/utils/TableGen/jupyter/README.md
llvm/utils/TableGen/jupyter/tablegen_kernel/assets/kernel.json
llvm/utils/TableGen/jupyter/tablegen_kernel/install.py
Index: llvm/utils/TableGen/jupyter/tablegen_kernel/install.py
===================================================================
--- llvm/utils/TableGen/jupyter/tablegen_kernel/install.py
+++ llvm/utils/TableGen/jupyter/tablegen_kernel/install.py
@@ -3,17 +3,39 @@
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
import os
+import json
+import sys
import argparse
+from tempfile import TemporaryDirectory
from jupyter_client.kernelspec import KernelSpecManager
def install_my_kernel_spec(user=True, prefix=None):
"""Install the kernel spec for user in given prefix."""
print("Installing llvm-tblgen IPython kernel spec")
- pkgroot = os.path.dirname(__file__)
- KernelSpecManager().install_kernel_spec(
- os.path.join(pkgroot, "assets"), "tablegen", user=user, prefix=prefix
- )
+
+ kernel_json = {
+ "argv": [
+ sys.executable, "-m", "tablegen_kernel", "-f", "{connection_file}"
+ ],
+ "display_name": "LLVM TableGen",
+ "language": "tablegen",
+ "language_info": {
+ "name": "tablegen",
+ "codemirror_mode": "tablegen",
+ "mimetype": "text/x-tablegen",
+ "file_extension": ".td",
+ "pygments_lexer": "text"
+ }
+ }
+
+ with TemporaryDirectory() as tmpdir:
+ json_path = os.path.join(tmpdir, "kernel.json")
+ with open(json_path, 'w') as json_file:
+ json.dump(kernel_json, json_file)
+ KernelSpecManager().install_kernel_spec(
+ tmpdir, "tablegen", user=user, prefix=prefix
+ )
def _is_root():
Index: llvm/utils/TableGen/jupyter/tablegen_kernel/assets/kernel.json
===================================================================
--- llvm/utils/TableGen/jupyter/tablegen_kernel/assets/kernel.json
+++ /dev/null
@@ -1,14 +0,0 @@
-{
- "argv": [
- "python3", "-m", "tablegen_kernel", "-f", "{connection_file}"
- ],
- "display_name": "LLVM TableGen",
- "language": "tablegen",
- "language_info": {
- "name": "tablegen",
- "codemirror_mode": "tablegen",
- "mimetype": "text/x-tablegen",
- "file_extension": ".td",
- "pygments_lexer": "text"
- }
-}
Index: llvm/utils/TableGen/jupyter/README.md
===================================================================
--- llvm/utils/TableGen/jupyter/README.md
+++ llvm/utils/TableGen/jupyter/README.md
@@ -15,15 +15,13 @@
## TableGen Kernel
-To use the kernel, first install it into jupyter:
+To use the kernel, first install it into jupyter.
- python3 -m tablegen_kernel.install
-
-Then put this folder on your PYTHONPATH so jupyter can find it:
+If you have installed Jupyter into a virtual environment, adjust `python3` to
+be the interpreter for that environment. This will ensure that tools run the
+kernel in the correct context.
-```shell
- export PYTHONPATH=$PYTHONPATH:<path to this dir>
-```
+ python3 -m tablegen_kernel.install
Then run one of:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D154351.536778.patch
Type: text/x-patch
Size: 2986 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230703/0018ce09/attachment.bin>
More information about the llvm-commits
mailing list