Skip to content

Commit 62b9969

Browse files
Restructure the dummy package
It now installs with ROS2 and pip and offers the `start_dummy` script globally in sourced environments.
1 parent 33f5aea commit 62b9969

20 files changed

+61
-41
lines changed

.gitignore

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
/build/
2-
/install/
3-
/log/
1+
build/
2+
install/
3+
log/
44
/.vscode
55

66
# Ignore test coverage artifacts
77
*.coverage
8+
9+
# Ignore pip install artifacts
10+
*.egg-info/

schunk_gripper_dummy/COLCON_IGNORE

Whitespace-only changes.

schunk_gripper_dummy/MANIFEST.in

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include schunk_gripper_dummy/config/*.json

schunk_gripper_dummy/README.md

+17-21
Original file line numberDiff line numberDiff line change
@@ -4,40 +4,36 @@ A minimalist protocol simulator for system tests.
44
Use this SCHUNK gripper dummy whenever you don't have access to real hardware
55
and still want to test your application.
66

7-
## Dependencies
8-
We need additional Python dependencies.
9-
Install them inside your favorite Python environment with
10-
11-
```bash
12-
pip install --user fastapi uvicorn requests python-multipart
13-
```
14-
157
## Getting started
16-
There's a convenience script `start_dummy` for starting the dummy simulator.
8+
Use the `start_dummy` script for starting the dummy simulator.
179
It will start on localhost with port `8000` by default but you can specify another port via the `port:=<port-id>` syntax.
1810

19-
### Plain python
11+
## Installation with plain python
2012

2113
Although shipped inside a ROS2 package, the dummy itself doesn't need ROS2.
22-
You can simply navigate into the dummy's package and start it with
14+
You can simply navigate into the dummy's package, install it inside your favorite environment with
15+
2316
```bash
24-
./start_dummy port:=8000
17+
pip install .
2518
```
26-
27-
### ROS2
28-
When working in a sourced ROS2 environment, you can start the dummy with
19+
Now you can start the simulator anywhere your environment with
2920
```bash
30-
ros2 run schunk_gripper_dummy start_dummy --ros-args -p port:=8000
21+
start_dummy port:=8000
22+
```
23+
You can inspect and uninstall it with normal pip functionality
24+
```bash
25+
pip show schunk_gripper_dummy
26+
pip uninstall schunk_gripper_dummy
3127
```
3228

33-
## Run tests locally
34-
Inside the dummy's package
29+
## Installation with ROS2
30+
Install them inside your favorite Python environment with
3531

3632
```bash
37-
pip install --user pytest httpx coverage
33+
pip install --user fastapi uvicorn requests python-multipart
3834
```
3935

36+
When working in a sourced ROS2 environment, you can start the dummy with
4037
```bash
41-
coverage run -m pytest tests/
42-
coverage report
38+
ros2 run schunk_gripper_dummy start_dummy --ros-args -p port:=8000
4339
```

schunk_gripper_dummy/src/dummy.py schunk_gripper_dummy/schunk_gripper_dummy/dummy.py

+6-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from threading import Thread
22
import time
3-
import os
4-
from pathlib import Path
3+
import pkg_resources # type: ignore [import-untyped]
54
import json
65
import struct
76
from typing import Tuple
@@ -57,15 +56,12 @@ def __init__(self):
5756
self.reserved_status_bits = [10, 15] + list(range(18, 31))
5857
self.reserved_control_bits = [10, 15] + list(range(17, 30))
5958

60-
enum_config = os.path.join(
61-
Path(__file__).resolve().parents[1], "config/enum.json"
62-
)
63-
metadata_config = os.path.join(
64-
Path(__file__).resolve().parents[1], "config/metadata.json"
65-
)
66-
data_config = os.path.join(
67-
Path(__file__).resolve().parents[1], "config/data.json"
59+
enum_config = pkg_resources.resource_filename(__name__, "config/enum.json")
60+
metadata_config = pkg_resources.resource_filename(
61+
__name__, "config/metadata.json"
6862
)
63+
data_config = pkg_resources.resource_filename(__name__, "config/data.json")
64+
6965
with open(enum_config, "r") as f:
7066
self.enum = json.load(f)
7167
with open(metadata_config, "r") as f:

schunk_gripper_dummy/schunk_gripper_dummy/main.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from src.dummy import Dummy
1+
from schunk_gripper_dummy.dummy import Dummy
22

33
from fastapi import FastAPI, Request, Form, BackgroundTasks
44
from fastapi.middleware.cors import CORSMiddleware

schunk_gripper_dummy/setup.py

+15-2
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,30 @@
11
from setuptools import find_packages, setup
22
import os
3+
from glob import glob
34

45
package_name = "schunk_gripper_dummy"
56

67
setup(
78
name=package_name,
8-
version="0.0.0",
9+
version="0.0.1",
910
packages=find_packages(exclude=["tests"]),
11+
include_package_data=True,
1012
data_files=[
1113
("share/ament_index/resource_index/packages", ["resource/" + package_name]),
1214
("share/" + package_name, ["package.xml"]),
1315
(os.path.join("lib", package_name), ["start_dummy"]),
16+
(
17+
os.path.join("share", package_name, "config"),
18+
glob(package_name + "/config/*.json"),
19+
),
20+
],
21+
install_requires=[
22+
"setuptools",
23+
"fastapi",
24+
"uvicorn",
25+
"requests",
26+
"python-multipart",
1427
],
15-
install_requires=["setuptools"],
1628
zip_safe=True,
1729
maintainer="Stefan Scherzinger",
1830
maintainer_email="[email protected]",
@@ -22,4 +34,5 @@
2234
entry_points={
2335
"console_scripts": [],
2436
},
37+
scripts=["start_dummy"],
2538
)

schunk_gripper_dummy/src/__init__.py

Whitespace-only changes.

schunk_gripper_dummy/tests/README.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
## Run tests locally
2+
Inside the dummy's package
3+
4+
```bash
5+
pip install --user pytest httpx coverage
6+
```
7+
8+
```bash
9+
coverage run -m pytest tests/
10+
coverage report
11+
```

schunk_gripper_dummy/tests/test_dummy.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from src.dummy import Dummy
1+
from schunk_gripper_dummy.dummy import Dummy
22
import pytest
33
import struct
44
import time

schunk_gripper_dummy/tests/test_motion_profile.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from src.dummy import LinearMotion
1+
from schunk_gripper_dummy.dummy import LinearMotion
22
import pytest
33
import time
44

schunk_gripper_dummy/tests/test_plc_communication.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from src.dummy import Dummy
1+
from schunk_gripper_dummy.dummy import Dummy
22
import struct
33
import pytest
44

schunk_gripper_dummy/tests/test_requests.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from src.dummy import Dummy
1+
from schunk_gripper_dummy.dummy import Dummy
22
from schunk_gripper_dummy.main import server, dummy as client_dummy
33
from fastapi.testclient import TestClient
44

0 commit comments

Comments
 (0)