Skip to content

Commit 7997d7b

Browse files
test lab
1 parent 128890c commit 7997d7b

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

colabcode/code.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,22 @@
2020

2121
class ColabCode:
2222
def __init__(
23-
self, port=10000, password=None, authtoken=None, mount_drive=False, code=True
23+
self,
24+
port=10000,
25+
password=None,
26+
authtoken=None,
27+
mount_drive=False,
28+
code=True,
29+
lab=False,
2430
):
2531
self.port = port
2632
self.password = password
2733
self.authtoken = authtoken
2834
self._mount = mount_drive
2935
self._code = code
36+
self._lab = lab
37+
if self._lab:
38+
self._run_lab()
3039
if self._code:
3140
self._install_code()
3241
self._install_extensions()
@@ -61,6 +70,24 @@ def _start_server(self):
6170
else:
6271
print(f"Public URL: {url}")
6372

73+
def _run_lab(self):
74+
os.system(f"fuser -n tcp -k {self.port}")
75+
if self._mount and colab_env:
76+
drive.mount("/content/drive")
77+
if self.password:
78+
lab_cmd = f"jupyter-lab --ip='localhost' --no-browser --NotebookApp.token='' --NotebookApp.password='{self.password}'"
79+
else:
80+
lab_cmd = "jupyter-lab --ip='localhost' --no-browser --NotebookApp.token='' --NotebookApp.password=''"
81+
with subprocess.Popen(
82+
[lab_cmd],
83+
shell=True,
84+
stdout=subprocess.PIPE,
85+
bufsize=1,
86+
universal_newlines=True,
87+
) as proc:
88+
for line in proc.stdout:
89+
print(line, end="")
90+
6491
def _run_code(self):
6592
os.system(f"fuser -n tcp -k {self.port}")
6693
if self._mount and colab_env:

setup.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
setup(
1010
name="colabcode",
1111
scripts=["scripts/colabcode"],
12-
version="0.1.2",
12+
version="0.2.0",
1313
description="ColabCode - Run codeserver on Colab!",
1414
long_description=long_description,
1515
long_description_content_type="text/markdown",
@@ -19,7 +19,12 @@
1919
license="MIT License",
2020
packages=find_packages(),
2121
include_package_data=True,
22-
install_requires=["pyngrok>=5.0.0", "nest_asyncio==1.4.3", "uvicorn==0.13.1"],
22+
install_requires=[
23+
"pyngrok>=5.0.0",
24+
"nest_asyncio==1.4.3",
25+
"uvicorn==0.13.1",
26+
"jupyterlab==3.0.7",
27+
],
2328
platforms=["linux", "unix"],
2429
python_requires=">3.5.2",
2530
)

0 commit comments

Comments
 (0)