Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Julia's Pluto and go programming language in colabcode #111

Open
wants to merge 28 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
f6faf7e
Upgrade code server version
rameshputalapattu Jan 18, 2022
24c02a1
Added code for auto install of julia and go
rameshputalapattu Jan 19, 2022
5939d0a
calling the julia and go installs
rameshputalapattu Jan 19, 2022
f66f591
added directory option to tar
rameshputalapattu Jan 19, 2022
d7790b5
create soft links for go and julia executables
rameshputalapattu Jan 19, 2022
a82b75a
Added go and julia vs code extensions
rameshputalapattu Jan 19, 2022
4826fdd
upgrade go to 1.8
rameshputalapattu Mar 19, 2022
7bc4d29
added option to install and run Pluto for julia
rameshputalapattu Mar 21, 2022
a9e8e3d
added start server step for pluto
rameshputalapattu Mar 21, 2022
a527af4
debugging pluto
rameshputalapattu Mar 21, 2022
0d71dfd
fix for pluto run command
rameshputalapattu Mar 21, 2022
450d1d3
fix to the julia pluto run command
rameshputalapattu Mar 21, 2022
bc65057
further debugging for pluto
rameshputalapattu Mar 21, 2022
ab36fe9
more debug messages
rameshputalapattu Mar 21, 2022
64e9962
more debug messages
rameshputalapattu Mar 21, 2022
8929045
capturing error messages
rameshputalapattu Mar 21, 2022
6b12abd
more debugging error captures
rameshputalapattu Mar 21, 2022
c9aa6bb
added more debugging
rameshputalapattu Mar 21, 2022
70a6a07
setting shell=False
rameshputalapattu Mar 21, 2022
9c310ef
different approach to capture stderr
rameshputalapattu Mar 21, 2022
5df568b
reading messages from stdout
rameshputalapattu Mar 21, 2022
90f7bc5
caotyre the right url
rameshputalapattu Mar 21, 2022
2654492
a minor correction
rameshputalapattu Mar 21, 2022
0115a5d
More changes
rameshputalapattu Mar 21, 2022
2f52f53
url instance variable changed to string
rameshputalapattu Mar 21, 2022
cad7afc
get the public url of ngrok tunnel
rameshputalapattu Mar 21, 2022
2fc21dc
cleaned up. Pluto works now
rameshputalapattu Mar 21, 2022
3e1355f
upgraded code server and golang versions
rameshputalapattu May 31, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 78 additions & 2 deletions colabcode/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
colab_env = False


EXTENSIONS = ["ms-python.python", "ms-toolsai.jupyter", "mechatroner.rainbow-csv", "vscode-icons-team.vscode-icons"]
CODESERVER_VERSION = "3.10.2"
EXTENSIONS = ["ms-python.python", "ms-toolsai.jupyter", "mechatroner.rainbow-csv", "vscode-icons-team.vscode-icons",
"julialang.language-julia", "golang.go",
]
CODESERVER_VERSION = "4.13.0"


class ColabCode:
Expand All @@ -28,21 +30,37 @@ def __init__(
mount_drive=False,
code=True,
lab=False,
pluto=False
):
self.port = port
self.password = password
self.authtoken = authtoken
self._mount = mount_drive
self._code = code
self._lab = lab
self._pluto = pluto
self.url = None
if self._lab:
self._start_server()
self._run_lab()
if self._code:
self._install_code()
self._install_go()
self._install_julia()
self._install_extensions()
self._start_server()
self._run_code()

if self._pluto:
print("installing julia")
self._install_julia()
print("installing pluto")
self._install_pluto()
print("starting server")
self._start_server()
print("running pluto")
self._run_pluto()


@staticmethod
def _install_code():
Expand All @@ -51,6 +69,18 @@ def _install_code():
["sh", "install.sh", "--version", f"{CODESERVER_VERSION}"],
stdout=subprocess.PIPE,
)

@staticmethod
def _install_go():
subprocess.run(["wget","https://go.dev/dl/go1.20.4.linux-amd64.tar.gz"],stdout=subprocess.PIPE)
subprocess.run([ "tar","xvfz","go1.20.4.linux-amd64.tar.gz","--directory","/opt"],stdout=subprocess.PIPE)
subprocess.run(["ln","-s","/opt/go/bin/go","/usr/bin/go"])

@staticmethod
def _install_julia():
subprocess.run(["wget","https://julialang-s3.julialang.org/bin/linux/x64/1.7/julia-1.7.1-linux-x86_64.tar.gz"],stdout=subprocess.PIPE)
subprocess.run([ "tar","xvfz","julia-1.7.1-linux-x86_64.tar.gz","--directory","/opt"],stdout=subprocess.PIPE)
subprocess.run(["ln","-s","/opt/julia-1.7.1/bin/julia","/usr/bin/julia"])

@staticmethod
def _install_extensions():
Expand All @@ -65,6 +95,7 @@ def _start_server(self):
public_url = tunnel.public_url
ngrok.disconnect(public_url)
url = ngrok.connect(addr=self.port, bind_tls=True)
self.url = url.public_url
if self._code:
print(f"Code Server can be accessed on: {url}")
else:
Expand Down Expand Up @@ -92,6 +123,51 @@ def _run_lab(self):
for line in proc.stdout:
print(line, end="")

@staticmethod
def _install_pluto():
pluto_install_cmd_list = ["julia","-e",'using Pkg;Pkg.add("Pluto")']
print("installing Pluto")
print(pluto_install_cmd_list)
with subprocess.Popen(
pluto_install_cmd_list,
shell=False,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
bufsize=1,
universal_newlines=True,
) as proc:
stdout,stderr = proc.communicate()

print("error is="+stderr)

def _run_pluto(self):

os.system(f"fuser -n tcp -k {self.port}")
if self._mount and colab_env:
drive.mount("/content/drive")
pluto_run_cmd_list = ["julia","-e",f'import Pluto;Pluto.run(port={self.port},launch_browser=false)']
print(pluto_run_cmd_list)
with subprocess.Popen(
pluto_run_cmd_list,
shell=False,
stdout=subprocess.PIPE,
stderr = subprocess.PIPE,
bufsize=1,
universal_newlines=True,
) as proc:

for line in proc.stdout:
if "localhost" in line:

print(line.replace(f"http://localhost:{self.port}",self.url),end="")








def _run_code(self):
os.system(f"fuser -n tcp -k {self.port}")
if self._mount and colab_env:
Expand Down