Skip to content

Commit e9aa5e4

Browse files
authored
Workspace Extension Functionality (#36)
* Added Workspaces * Version 0.2.2 - Bug Fix - Fixed recursion error for workspaces - Fixed workspace description typo in settings - Fixed viz-robotmodel.png not found * Minor Changes - Restored saved settings to default state - Fixed typo in settings schema - Removed unused import in Pkgs Module
1 parent 8c8a1c5 commit e9aa5e4

File tree

9 files changed

+66
-21
lines changed

9 files changed

+66
-21
lines changed

MANIFEST.in

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ include LICENSE
22
include README.md
33
include pyproject.toml
44

5-
include jupyterlab_ros_server/jupyterlab_ros_server.json
5+
include jupyter_ros_server/jupyter_ros_server.json
66

7-
graft jupyterlab_ros_server/static
8-
graft jupyterlab_ros_server/public
9-
graft jupyterlab_ros_server/labextension
7+
graft jupyter_ros_server/static
8+
graft jupyter_ros_server/public
9+
graft jupyter_ros_server/labextension

js/schema/settings.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414
"title": "Master launch file",
1515
"description": "Absolute path of your launch file to initialize ROS master.\nKeep it empty to use the default one.",
1616
"default": ""
17+
},
18+
"workspaces": {
19+
"type": "string",
20+
"title": "Workspace Paths",
21+
"description": "Absolute paths to the workspaces separated by colons.\nExample:\n/home/jovyan/ws1:/home/jovyan/ws2:/home/jovyan/ws3\nKeep it empty to use load the workspaces sourced before jupyter lab was started.",
22+
"default": ""
1723
}
1824
}
1925
}

js/src/settings/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,10 @@ export const settings: JupyterFrontEndPlugin<void> = {
6464
const loadSetting = (setting: ISettingRegistry.ISettings): void => {
6565
const env = setting.get('env').composite as string;
6666
const master = setting.get('master').composite as string;
67+
const workspaces = setting.get('workspaces').composite as string;
6768

68-
if ( env != "" || master != "" ) {
69-
const msg = { method: 'PUT', body: JSON.stringify({ env, master }) };
69+
if ( env != "" || master != "" || workspaces != "" ) {
70+
const msg = { method: 'PUT', body: JSON.stringify({ env, master, workspaces }) };
7071

7172
ServerConnection.makeRequest(url, msg, server)
7273
.then( resp => {})

jupyter_ros_server/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.2.1"
1+
__version__ = "0.2.2"

jupyter_ros_server/api/pkgs.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,32 @@
88

99
import rospkg
1010

11-
from ..lib import getEnv, getMaster, save
11+
from ..lib import getEnv, getMaster, save, getWorkspaces, ROS_PACKAGE_PATH
12+
13+
14+
1215

1316
class Pkgs(IPythonHandler):
14-
rospack = rospkg.RosPack()
17+
18+
def get_wsl():
19+
current_workspace = getWorkspaces()
20+
current_workspace_list = current_workspace.split(':') if ":" in current_workspace else [current_workspace]
21+
current_workspace_list = [ws.strip() for ws in current_workspace_list if len(ws.strip()) > 0]
22+
if ROS_PACKAGE_PATH not in current_workspace_list:
23+
current_workspace_list.append(ROS_PACKAGE_PATH)
24+
return current_workspace_list
25+
26+
startup_ws = get_wsl()
27+
rospack = rospkg.RosPack(startup_ws)
1528

1629
@tornado.web.authenticated
1730
def get(self, *args, **kwargs):
1831
cls = self.__class__
32+
current_workspace_list = cls.get_wsl()
33+
if current_workspace_list != cls.startup_ws:
34+
cls.rospack = rospkg.RosPack(current_workspace_list)
35+
cls.startup_ws = current_workspace_list
36+
print("[PKGS] : ws updated: ", " | ".join(cls.startup_ws))
1937

2038
if not args:
2139
self.write("Error - no argument supplied")
@@ -24,8 +42,8 @@ def get(self, *args, **kwargs):
2442

2543
print("[PKGS] get:", args[0])
2644

45+
2746
argslist = args[0].split('/')
28-
2947
package = argslist[0]
3048
file = '/'.join(argslist[1:])
3149
path = ""

jupyter_ros_server/api/setting.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,17 @@
33
import tornado
44
from notebook.base.handlers import APIHandler
55

6-
from ..lib import getEnv, getMaster, save
6+
from ..lib import getEnv, getMaster, getWorkspaces, save
77

88
class Setting(APIHandler):
99

1010
@tornado.web.authenticated
1111
def get(self):
12-
self.finish(json.dumps( { 'env': getEnv(), 'master': getMaster() } ))
12+
self.finish(json.dumps( { 'env': getEnv(), 'master': getMaster(), 'workspaces' : getWorkspaces()} ))
1313

1414
@tornado.web.authenticated
1515
def put(self):
1616
msg = self.get_json_body()
17-
save(msg['env'], msg['master'])
17+
save(msg['env'], msg['master'], msg['workspaces'])
18+
print(msg)
1819
self.finish()

jupyter_ros_server/lib/settings.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,58 @@
1-
from os import path
1+
from os import path,environ
22
import json
3+
from tkinter import W
34

45
ROOT = path.dirname(path.dirname(__file__))
56
PUBLIC = path.join(ROOT, 'public')
67
SETTINGS = path.join(ROOT, 'static/settings.json')
78
MASTER = path.join(ROOT, 'static/roslab.launch')
9+
ROS_PACKAGE_PATH = environ.get("ROS_PACKAGE_PATH", default="").strip()
10+
811

912
def getEnv():
1013
try:
1114
with open(SETTINGS) as settings:
1215
data = json.load(settings)
1316

1417
except Exception :
15-
data = { "env": "", "master": "" }
18+
data = { "env": "", "master": "", "workspaces": ""}
1619

1720
return data['env']
1821

22+
def getWorkspaces():
23+
try:
24+
with open(SETTINGS) as settings:
25+
data = json.load(settings)
26+
27+
except Exception :
28+
data = { "env": "", "master": "", "workspaces": ""}
29+
30+
return data['workspaces'] if data['workspaces'] != "" else ROS_PACKAGE_PATH
31+
32+
1933
def getMaster():
2034
try:
2135
with open(SETTINGS) as settings:
2236
data = json.load(settings)
2337

2438
except Exception :
25-
data = { "env": "", "master": "" }
39+
data = { "env": "", "master": "", "workspaces": ""}
2640

2741
return data['master'] if data['master'] != "" else MASTER
2842

29-
def save(env, master):
43+
def save(env, master, workspaces):
3044
try:
3145
with open(SETTINGS, 'r') as settings:
3246
data = json.load(settings)
3347

3448
except Exception :
35-
data = { "env": "", "master": "" }
49+
data = { "env": "", "master": "" , "workspaces": ""}
3650

3751
data['env'] = env
3852
data['master'] = master
53+
data['workspaces'] = workspaces
3954

4055
with open(SETTINGS, 'w+') as settings:
4156
json.dump(data, settings)
4257

43-
save("", "")
58+
save("", "", ROS_PACKAGE_PATH)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"env": "", "master": ""}
1+
{"env": "", "master": "", "workspaces": ""}

setup.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,11 @@
6363
'license': "BSD-3-Clause",
6464
'url': "https://github.com/RoboStack/jupyterlab-ros",
6565
'include_package_data': True,
66-
'packages': find_packages(),
66+
'packages': find_packages(
67+
where=HERE,
68+
include=["*"],
69+
exclude=[],
70+
),
6771
'cmdclass': cmdclass,
6872
'install_requires': [
6973
'rosbridge-library',

0 commit comments

Comments
 (0)