예제 #1
0
 def get_project(self, proj_name):
     root = pathlib.Path(self.cfg['DEFAULT']['project_path'])
     project_loc = root/proj_name
     if project_loc.exists():
         if in_colab() or in_jupyter():self.setup_project_env(project_loc)
     else:
         if in_colab() or in_jupyter():
             self.clone_setup_repo(proj_name)
             self.setup_project_env(project_loc)
     return project_loc
예제 #2
0
 def launch(self):
     self.install()
     print(f"Inside lauch in_colab:{in_colab()}")
     if in_colab():
         self.preinstall_colab()
     self.start_server()
     self.run()
예제 #3
0
def start_pluto(port:Param("Port to Start Jupyter", type=int)=9000,
                tunnel:Param("Tunel Type", type=str)='ngrok',
                authtoken:Param("Tunnel Authtoken for ngrok", type=str)=None):
    "Starts Pluto.jl reactive notebook"
    if in_colab(): mount_drive()
    remote = RemotePluto(port=port, tunnel=tunnel, authtoken=authtoken)
    remote.launch()
예제 #4
0
def start_code(port:Param("Port to Start Code", type=int)=10000,
               password:Param("Password to Start Code", type=str)=None,
               tunnel:Param("Tunel Type", type=str)='ngrok',
               authtoken:Param("Tunnel Authtoken for ngrok", type=str)=None):
    "Starts Code Server"
    if in_colab(): mount_drive()
    remote = RemoteCode(password=password, port=port, tunnel=tunnel, authtoken=authtoken)
    remote.launch()
예제 #5
0
 def setup_git_global(self):
     if in_colab():
         root = pathlib.Path(self.cfg['DEFAULT']['project_path'])
         get_ipython().magic(f"cd {root}")
         setup_gh()
     execute_cmd(f"git config --global user.name  {self.git_username}")
     execute_cmd(f"git config --global user.email {self.git_useremail}")
     execute_cmd(f"git config credential.helper store")
     execute_cmd(f"gh auth login --with-token < {self.cfg['DEFAULT']['git_user_pat']}")
     execute_cmd(f'gh auth status')
예제 #6
0
def connect_to_localtunel(port, subdomain=None):
    try:
        print("Inside localtunnel")
        print("IN_COLAB:", in_colab())
        if in_colab():
            url_folder = pathlib.Path.cwd()
            print("Installing localtunnel on colab")
            execute_cmd("npm install -g localtunnel")
            time.sleep(1)
            print("Finished localtunnel Installation")
            if subdomain:
                execute_cmd(
                    f"nohup lt --port {port} --subdomain {subdomain}>> {url_folder}/url.txt 2>&1 &"
                )
                time.sleep(1)
            else:
                execute_cmd(
                    f"nohup lt --port {port} >> {url_folder}/url.txt 2>&1 &")
                time.sleep(1)
            print("Finished IN_COLAB")
        else:
            url_folder = pathlib.Path.home()

            if subdomain:
                execute_cmd(
                    f"lt --port {port} --subdomain {subdomain}>> {url_folder}/url.txt 2>&1 &"
                )
                time.sleep(1)
            else:
                execute_cmd(f"lt --port {port}>> {url_folder}/url.txt 2>&1 &")
                time.sleep(1)
        print("Reading Generated url file")
        s = pathlib.Path(f"{url_folder}/url.txt").open().read()
        #         print(s)
        url = re.findall(
            'http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+',
            str(s))
        #         print(url)
        if isinstance(url, list): url = url[-1]
        print(f"Remote server can be assesed on : {url}")
        return url
    except subprocess.CalledProcessError:
        print("Need to install localtunnel first")
예제 #7
0
 def __init__(self, cfg_path, cfg_name, is_nbdev=True):
     if in_colab(): mount_drive()
     self.is_nbdev = is_nbdev
     self.cfg_path = cfg_path
     self.cfg_name = cfg_name
     self.cfg = configparser.ConfigParser()
     self.cfg.read_file((pathlib.Path(self.cfg_path)/self.cfg_name).open('r'))
     self.git_pat = pathlib.Path(self.cfg['DEFAULT']['git_user_pat']).read_text()
     self.git_username = self.cfg['DEFAULT']['git_user_name']
     self.git_useremail = self.cfg['DEFAULT']['git_user_email']
     self.setup_git_global()
예제 #8
0
 def run(self):
     os.system(f"fuser -n tcp -k {self.port}")
     jupyter_cmd = f"jupyter {self.ui} --NotebookApp.allow_remote_access=True  --NotebookApp.disable_check_xsrf=True --ip=0.0.0.0 --port={self.port}"
     if self.ui == 'lab':
         jupyter_cmd = f"jupyter {self.ui} --ip=0.0.0.0 --port={self.port} --no-browser"
     if in_colab():
         token = str(uuid.uuid1())
         print(f"Jupyter token for colab: {token}")
         execute_cmd(f"export JUPYTER_TOKEN={token}")
         add_cmd = f" --allow-root"
         jupyter_cmd = jupyter_cmd + add_cmd
         # passwd()
     execute_cmd(jupyter_cmd)
예제 #9
0
def setup_julia():
    if in_colab():
        subprocess.run([
            "wget",
            "https://gist.githubusercontent.com/Rahuketu86/765ee2ecd59aa40c493fe6a10db606a4/raw/a3498236fb96109e0f6ed2ea8325cf8acafe75d0/install_julia_colab.sh"
        ],
                       stdout=subprocess.PIPE)
        execute_cmd("bash install_julia_colab.sh")
    else:
        subprocess.run([
            "wget",
            "https://gist.githubusercontent.com/Rahuketu86/3543336b8fe4ea2c1cc7b6edcc96f975/raw/db6c562201ecf655b0bb82d7fcd2a16128bb0148/install_julia.sh"
        ],
                       stdout=subprocess.PIPE)
        execute_cmd("bash install_julia.sh")
예제 #10
0
def start_jupyter(port:Param("Port to Start Jupyter", type=int)=9000,
                  ui:Param("Interface to start", type=str)='notebook',
                  tunnel:Param("Tunel Type", type=str)='ngrok',
                  authtoken:Param("Tunnel Authtoken for ngrok", type=str)=None,
                  subdomain:Param("Add a subdomain only for localtunnel", type=str)=None,
                  install_code:Param("Flag to install code", type=bool)=False,
                  install_julia:Param("Flag to install code", type=bool)=False,
                  ):
    "Starts Jupyter"
    if in_colab():
        print("Mounting Drive")
        mount_drive()
    remote = RemoteJupyter(port=port,
                           ui=ui,
                           tunnel=tunnel,
                           authtoken=authtoken,
                           subdomain=subdomain,
                           install_code=install_code,
                           install_julia=install_julia
                          )
    remote.launch()