[Infra] Fix version-check workflow (#100090)
[llvm-project.git] / mlir / utils / jupyter / mlir_opt_kernel / install.py
blobbd7b1d10b734fb8fc62639045040434336ef10c8
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
5 import os
6 import argparse
8 from jupyter_client.kernelspec import KernelSpecManager
11 def install_my_kernel_spec(user=True, prefix=None):
12 """Install the kernel spec for user in given prefix."""
13 print("Installing mlir-opt IPython kernel spec")
14 pkgroot = os.path.dirname(__file__)
15 KernelSpecManager().install_kernel_spec(
16 os.path.join(pkgroot, "assets"), "mlir", user=user, prefix=prefix
20 def _is_root():
21 """Returns whether the current user is root."""
22 try:
23 return os.geteuid() == 0
24 except AttributeError:
25 # Return false wherever unknown.
26 return False
29 def main(argv=None):
30 parser = argparse.ArgumentParser(
31 description="Install KernelSpec for MlirOpt Kernel"
33 prefix_locations = parser.add_mutually_exclusive_group()
35 prefix_locations.add_argument(
36 "--user", help="Install in user home directory", action="store_true"
38 prefix_locations.add_argument(
39 "--prefix", help="Install directory prefix", default=None
42 args = parser.parse_args(argv)
44 user = args.user or not _is_root()
45 prefix = args.prefix
47 install_my_kernel_spec(user=user, prefix=prefix)
50 if __name__ == "__main__":
51 main()