Debian Codegraph @

llvm-project/llvm/utils/TableGen/jupyter/tablegen_kernel/install.py

raw
1 # Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
2 # See https://llvm.org/LICENSE.txt for license information.
3 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4
5 import os
6 import argparse
7 from jupyter_client.kernelspec import KernelSpecManager
8
9
10 def install_my_kernel_spec(user=True, prefix=None):
11 """Install the kernel spec for user in given prefix."""
12 print("Installing llvm-tblgen IPython kernel spec")
13 pkgroot = os.path.dirname(__file__)
14 KernelSpecManager().install_kernel_spec(
15 os.path.join(pkgroot, "assets"), "tablegen", user=user, prefix=prefix
16 )
17
18
19 def _is_root():
20 """Returns whether the current user is root."""
21 try:
22 return os.geteuid() == 0
23 except AttributeError:
24 # Return false wherever unknown.
25 return False
26
27
28 def main(argv=None):
29 parser = argparse.ArgumentParser(
30 description="Install KernelSpec for LLVM TableGen Kernel"
31 )
32 prefix_locations = parser.add_mutually_exclusive_group()
33
34 prefix_locations.add_argument(
35 "--user", help="Install in user home directory", action="store_true"
36 )
37 prefix_locations.add_argument(
38 "--prefix", help="Install directory prefix", default=None
39 )
40
41 args = parser.parse_args(argv)
42
43 user = args.user or not _is_root()
44 prefix = args.prefix
45
46 install_my_kernel_spec(user=user, prefix=prefix)
47
48
49 if __name__ == "__main__":
50 main()