| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
import os |
| 6 |
import argparse |
| 7 |
|
| 8 |
from jupyter_client.kernelspec import KernelSpecManager |
| 9 |
|
| 10 |
|
| 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(os.path.join(pkgroot, 'assets'), |
| 16 |
'mlir', |
| 17 |
user=user, |
| 18 |
prefix=prefix) |
| 19 |
|
| 20 |
|
| 21 |
def _is_root(): |
| 22 |
"""Returns whether the current user is root.""" |
| 23 |
try: |
| 24 |
return os.geteuid() == 0 |
| 25 |
except AttributeError: |
| 26 |
|
| 27 |
return False |
| 28 |
|
| 29 |
|
| 30 |
def main(argv=None): |
| 31 |
parser = argparse.ArgumentParser( |
| 32 |
description='Install KernelSpec for MlirOpt Kernel') |
| 33 |
prefix_locations = parser.add_mutually_exclusive_group() |
| 34 |
|
| 35 |
prefix_locations.add_argument('--user', |
| 36 |
help='Install in user home directory', |
| 37 |
action='store_true') |
| 38 |
prefix_locations.add_argument('--prefix', |
| 39 |
help='Install directory prefix', |
| 40 |
default=None) |
| 41 |
|
| 42 |
args = parser.parse_args(argv) |
| 43 |
|
| 44 |
user = args.user or not _is_root() |
| 45 |
prefix = args.prefix |
| 46 |
|
| 47 |
install_my_kernel_spec(user=user, prefix=prefix) |
| 48 |
|
| 49 |
|
| 50 |
if __name__ == '__main__': |
| 51 |
main() |