"""
Script and utilities to launch the plasma calculator
"""
__all__ = ["main"]

import argparse
import os
import shlex
import subprocess

_description = """
Plasma calculator is a tool that opens a page in a web browser for
interactive calculation of plasma parameters.

This tool is currently in the prototype stage and is expected to change in
the future. Please raise an issue at the following link to provide suggestions
and feedback: https://github.com/PlasmaPy/PlasmaPy/issues/new
"""


def main():
    """
    Stub function for command line tool that launches the plasma calculator notebook.
    """
    parser = argparse.ArgumentParser(description=_description)
    parser.add_argument(
        "--port", type=int, default=8866, help="Port to run the notebook"
    )
    parser.add_argument(
        "--dark", action="store_true", help="Turn on dark mode, reduces eye strain"
    )
    parser.add_argument(
        "--no-browser", action="store_true", help="Do not open the browser"
    )

    # module_path = plasmapy.__path__[0]
    module_path = os.path.dirname(os.path.abspath(__file__))
    computed_calculator_path = os.path.join(module_path, "plasma_calculator.ipynb")

    args = parser.parse_args()
    theme = "dark" if args.dark else "light"
    no_browser = "--no-browser" if args.no_browser else ""

    command = f"voila {no_browser} --port={args.port} --theme={theme} {computed_calculator_path} \
        --VoilaConfiguration.file_whitelist favicon.ico"
    try:
        subprocess.call(shlex.split(command))
    except KeyboardInterrupt:
        print("Stopping calculator! Bye")

@@ -103,18 +103,23 @@
 %0Aimport 
-os
+pathlib
 %0D%0Aimport
@@ -1039,10 +1039,8 @@
 %0A   
- #
  mod
@@ -1055,135 +1055,69 @@
  = p
-lasmapy.__p
+athlib.P
 ath
+(
 __
-%5B0%5D%0D%0A    module_path = os.path.dirname(os.path.abspath(__file__))%0D%0A    computed_calculator_path = os.path.join(
+file__).parent.absolute()%0D%0A    notebook_path = 
 modu
@@ -1123,17 +1123,18 @@
 ule_path
-,
+ /
  %22plasma
@@ -1151,17 +1151,64 @@
 r.ipynb%22
-)
+%0D%0A    favicon_path = module_path / %22favicon.ico%22
 %0D%0A%0D%0A    
@@ -1361,29 +1361,63 @@
 d = 
-f%22voila %7Bno_browser%7D 
+%5B%0D%0A        %22voila%22,%0D%0A        notebook_path,%0D%0A        f%22
 --po
@@ -1430,17 +1430,30 @@
 gs.port%7D
- 
+%22,%0D%0A        f%22
 --theme=
@@ -1463,37 +1463,10 @@
 eme%7D
- %7Bcomputed_calculator_path%7D %5C
+%22,
 %0D%0A  
@@ -1471,16 +1471,18 @@
         
+f%22
 --VoilaC
@@ -1512,21 +1512,90 @@
 list
- 
+=%7B
 favicon
-.ico%22
+_path%7D%22,%0D%0A    %5D%0D%0A    if no_browser:%0D%0A        command.append(no_browser)%0D%0A
 %0D%0A  
@@ -1630,28 +1630,16 @@
 all(
-shlex.split(
 command)
 )%0D%0A 
@@ -1634,17 +1634,16 @@
 command)
-)
 %0D%0A    ex

Use `pathlib` to get path to `plasma-calculator` notebook (#1613)