Skip to content

Commit 80a8975

Browse files
Mark Weinreuterwiewo
authored andcommitted
Migrate the rll_stack python packages to Python3
All Python-packages in rll_stack (except for rll_worker) can now be executed with Python3. Furthermore, they do not require a full ROS installation but can be run as a standalone application. Nevertheless, they can still be installed as catkin packages and started via roslaunch. The Shebang-lines for these scripts has been changed to python3 which is detected by roslaunch and treated correctly.
1 parent 2eecfe5 commit 80a8975

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1349
-1071
lines changed

.ci/after_build_target_workspace.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
# Install dependencies required for both the Python2 test setup and the Python3 server environment
6+
apt install -y python3-pip
7+
8+
pip2 install -r rll_common/requirements.txt
9+
pip2 install -r rll_test/requirements.txt
10+
11+
pip3 install -r rll_server/requirements.txt
12+
13+
# Creating docker daemon config file
14+
# Setting log level to fatal to prevent broken pipe during log size test
15+
echo -e '{
16+
"storage-driver": "aufs",
17+
"insecure-registries": ["rll-dockerhub.ipr.kit.edu"],
18+
"log-level": "fatal"
19+
}' >> /etc/docker/daemon.json
20+
21+
# Setting ros networking environment variables in bashrc
22+
printf "export ROS_IP=127.0.0.1\nexport ROS_MASTER_URI=http://$ROS_IP:11311\n" > ~/.bashrc
23+
24+
# Starting docker daemon
25+
dockerd &
26+
# Starting and checking mongo daemon to give docker enough time to start
27+
service mongodb start
28+
service mongodb status
29+
30+
# The rll_server is run with Python3 and not via roslaunch -> ROS_PACKAGE_PATH is not set
31+
# add rll_common, rll_server to the ROS_PACKAGE_PATH in order for rospkg to find our configs
32+
# add rll_common to the PYTHONPATH in order for edit_projects to import files from this module
33+
ROS_PACKAGE_PATH=$(pwd)/rll_common:$(pwd)/rll_server PYTHONPATH=$(pwd)/rll_common/src:${PYTHONPATH} python3 rll_common/scripts/edit_projects.py set_defaults
34+
35+
# Checking docker daemon status
36+
docker info
37+
38+

.ci/after_script.sh

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,17 @@
22

33
set -e
44

5-
pip -q install flake8
6-
python -m flake8
7-
pip -q install 'pylint<2.0.0'
8-
. /root/target_ws/install/setup.bash
9-
find * -iname '*.py' | xargs python -m pylint
5+
pip2 -q install flake8
6+
pip2 -q install 'pylint<2.0.0'
7+
8+
# Source environment to ensure the packages are found
9+
. /root/target_ws/install/setup.bash
10+
11+
# rll_worker is a python2 ROS dependent package -> run pylint and flake8 here
12+
python2 -m flake8 rll_worker/
13+
find rll_worker -iname '*.py' | xargs python2 -m pylint
14+
15+
# the rll_common can be imported under Python2 -> check the package files as well
16+
python2 -m flake8 rll_common/src/rll_common
17+
# Python3 pylint flag case a bad-option-value -> ignore those errors
18+
python2 -m pylint rll_common/src/rll_common -d bad-option-value

.ci/before_script.sh

Lines changed: 0 additions & 28 deletions
This file was deleted.

.gitignore

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ build/*/MinSizeRel/*
3232
build/*/RelWithDebInfo/*
3333
build
3434
*.pyc
35+
*.egg-info
3536

3637
*#
3738
*.#
@@ -44,7 +45,6 @@ build
4445
*.bag
4546
*.o
4647
*.md5sum
47-
*.pyc
4848

4949
# Qt files
5050
*.pro.user
@@ -71,3 +71,10 @@ CVS/*
7171
/config
7272
*.kdev_include_paths
7373
*.orig
74+
75+
.idea/
76+
.vscode/
77+
venv/
78+
*.log
79+
.mypy_reports/
80+
.mypy_cache/

.gitlab-ci.yml

Lines changed: 78 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,43 +8,93 @@ image: docker:git # docker and git clients
88
services:
99
- docker:dind
1010

11-
# The docker runner does not expose /tmp to the docker-in-docker service
12-
# This config ensures that the temp folder is located inside the project directory (e.g. for prerelease tests or SSH agent forwarding)
13-
variables:
14-
TMPDIR: "${CI_PROJECT_DIR}.tmp"
15-
UPSTREAM_WORKSPACE: ".ci.rosinstall"
16-
17-
ROS_DISTRO: "melodic"
18-
ROS_REPO: "ros"
19-
20-
# rosinstall file content to ensure the rll_sdk dependency is installed
21-
PROJECT_ROSINSTALL_FILENAME: ".ci.rosinstall" # Used to generate the file if it does not exist
22-
ROSINSTALL_SDK_TEMPLATE: "{repositories: {rll_sdk: {type: git, url: 'https://gitlab.ipr.kit.edu/rll/rll_sdk.git', version: master}}}"
23-
24-
before_script:
25-
- apk add --update bash coreutils tar # install industrial_ci dependencies
26-
- git clone --quiet --depth 1 https://github.com/ros-industrial/industrial_ci.git .industrial_ci
27-
# create the .rosinstall file if it does not exist
28-
- test ! -f ${PROJECT_ROSINSTALL_FILENAME} && echo ${ROSINSTALL_SDK_TEMPLATE} >> ${PROJECT_ROSINSTALL_FILENAME}
29-
- sed -i 's/https\:\/\/gitlab\.ipr\.kit\.edu/https\:\/\/gitlab-ci-token\:'${CI_JOB_TOKEN}'\@gitlab\.ipr\.kit\.edu/g' ${CI_PROJECT_DIR}/${PROJECT_ROSINSTALL_FILENAME}
30-
# Creating rll_stack config files from samples
31-
- cp rll_common/config/common.yaml.sample rll_common/config/common.yaml
32-
- cp rll_server/config/server.yaml.sample rll_server/config/server.yaml
33-
- cp rll_worker/config/worker.yaml.sample rll_worker/config/worker.yaml
34-
# download config files if they do not exist
35-
- test ! -f .flake8 && wget https://gitlab.ipr.kit.edu/rll/rll_sdk/raw/master/.flake8
36-
- test ! -f .pylintrc && wget https://gitlab.ipr.kit.edu/rll/rll_sdk/raw/master/.pylintrc
37-
3811
melodic-build-tests:
3912
variables:
13+
# The docker runner does not expose /tmp to the docker-in-docker service
14+
# This config ensures that the temp folder is located inside the project directory (e.g. for prerelease tests or SSH agent forwarding)
15+
TMPDIR: "${CI_PROJECT_DIR}.tmp"
16+
UPSTREAM_WORKSPACE: ".ci.repos"
17+
ROS_DISTRO: "melodic"
18+
ROS_REPO: "ros"
19+
20+
# repos file content to ensure the rll_sdk dependency is installed (this is also used as the upstream workspace)
21+
PROJECT_REPOS_FILENAME: ".ci.repos" # Used to generate the file if it does not exist
22+
REPOS_SDK_TEMPLATE: "{repositories: {rll_sdk: {type: git, url: 'https://gitlab.ipr.kit.edu/rll/rll_sdk.git', version: master}}}"
23+
4024
CATKIN_LINT: "pedantic"
4125
CATKIN_LINT_ARGS: "--ignore unknown_package --ignore unknown_depend"
26+
VERBOSE_TESTS: "true"
4227
# -e = setting ROS_IP variable inside the container
4328
# -v = turning /var/lib/docker into a volume which is necessary for writing to disk while using aufs storage driver
4429
# --privileged is needed for running docker in docker (which we do)
4530
DOCKER_RUN_OPTS: "-e ROS_IP=172.18.0.2 --privileged -v aufsvol:/var/lib/docker"
46-
AFTER_BUILD_TARGET_WORKSPACE: .ci/before_script.sh
31+
AFTER_BUILD_TARGET_WORKSPACE: .ci/after_build_target_workspace.sh
4732
AFTER_SCRIPT: .ci/after_script.sh
33+
34+
before_script:
35+
- apk add --update bash coreutils tar # install industrial_ci dependencies
36+
- git clone --quiet --depth 1 https://github.com/ros-industrial/industrial_ci.git .industrial_ci
37+
# create the .repos file if it does not exist
38+
- test ! -f ${PROJECT_REPOS_FILENAME} && echo ${REPOS_SDK_TEMPLATE} >> ${PROJECT_REPOS_FILENAME}
39+
- sed -i 's/https\:\/\/gitlab\.ipr\.kit\.edu/https\:\/\/gitlab-ci-token\:'${CI_JOB_TOKEN}'\@gitlab\.ipr\.kit\.edu/g' ${CI_PROJECT_DIR}/${PROJECT_REPOS_FILENAME}
40+
41+
# Create rll_stack config files from samples
42+
- cp rll_common/config/common.yaml.sample rll_common/config/common.yaml
43+
- cp rll_server/config/server.yaml.sample rll_server/config/server.yaml
44+
- cp rll_worker/config/worker.yaml.sample rll_worker/config/worker.yaml
45+
- test ! -f .pylintrc && wget https://gitlab.ipr.kit.edu/rll/rll_sdk/raw/master/.pylintrc
46+
47+
48+
49+
4850
script: .industrial_ci/gitlab.sh
4951
tags:
5052
- docker
53+
54+
py3_pylint:
55+
before_script:
56+
- apk add --no-cache --update python3 python3-dev py3-pip gcc musl-dev libffi-dev build-base
57+
- pip3 install pylint
58+
- pip3 install -r rll_server/requirements.txt
59+
# Install the python modules from their directories (note the trailing slash)
60+
- pip3 install rll_common/ rll_server/ rll_test/
61+
- test ! -f .pylintrc && wget https://gitlab.ipr.kit.edu/rll/rll_sdk/raw/master/.pylintrc -O .pylintrc
62+
63+
script:
64+
# Run pylint for every Python3 sub-project separately to get better statistics
65+
# for directories with an __init__.py you can pass the directory, otherwise specify separate files
66+
# Tornado handlers set class attributes outside of the __init__ function: W0201 disables this check
67+
#
68+
- pylint --rcfile=.pylintrc -d W0201 rll_server/src/rll_server/ rll_server/scripts/*.py
69+
- pylint --rcfile=.pylintrc rll_common/src/rll_common/ rll_common/scripts/*.py
70+
- pylint --rcfile=.pylintrc rll_test/src/rll_test/ rll_test/scripts/*.py
71+
72+
73+
py3_flake8:
74+
before_script:
75+
- apk add --no-cache --update python3 python3-dev py3-pip musl-dev libffi-dev build-base
76+
- pip3 install flake8
77+
- pip3 install -r rll_server/requirements.txt
78+
- pip3 install rll_common/ rll_server/ rll_test/
79+
- test ! -f .flake8 && wget https://gitlab.ipr.kit.edu/rll/rll_sdk/raw/master/.flake8
80+
81+
script:
82+
- python3 -m flake8 rll_server/
83+
- python3 -m flake8 rll_common/
84+
- python3 -m flake8 rll_test/
85+
86+
mypy:
87+
before_script:
88+
# If you want to generate reports, you need to add the commented out dependencies for lxml
89+
- apk add --no-cache --update python3 python3-dev py3-pip musl-dev libffi-dev build-base # libxml2-dev libxslt-dev
90+
- pip3 install mypy # lxml
91+
- pip3 install -r rll_server/requirements.txt
92+
- pip3 install rll_common/ rll_server/ rll_test/ rll_worker/
93+
94+
allow_failure: true
95+
script:
96+
# Run mypy for every sub-project separately
97+
- mypy rll_server/src/ rll_server/scripts/
98+
- mypy rll_common/src/ rll_common/scripts/
99+
- mypy rll_test/src/ rll_test/scripts/
100+
- mypy --py2 rll_worker/src/ rll_worker/scripts

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ information on the test framework and the Docker containers.
2525

2626
Please note that the RLL stack is only tested with ROS Kinetic and
2727
Melodic.
28+
2829

2930
1. Create a workspace and clone the core repositories:
3031

@@ -45,6 +46,10 @@ Melodic.
4546

4647
This will also install a MongoDB database for storing job, user
4748
and other system data.
49+
50+
The `rll_server` is a Python3 application and requires some
51+
additional dependencies. Please follow the instructions in the
52+
[Readme](rll_server/Readme.md) to install these dependencies.
4853

4954
3. Build the workspace and source it:
5055

mypy.ini

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Global options:
2+
[mypy]
3+
python_version = 3.6
4+
# Warn if config options are invalid
5+
warn_unused_configs = True
6+
pretty = True
7+
8+
follow_imports = silent
9+
ignore_missing_imports = True
10+
local_partial_types = False
11+
check_untyped_defs = True
12+
strict_optional = True
13+
14+
# not every def has to have a type comment
15+
allow_untyped_defs = True
16+
allow_untyped_globals = False
17+
18+
# Generate reports, the html report is really helpful
19+
# it highlights every line and its type checking status
20+
# html_report = .mypy_reports
21+
#txt_report = .mypy_reports
22+
23+
24+
# Enable stricter options for specific modules/files
25+
26+
# Module based options
27+
[mypy-rll_server.*]
28+
#allow_untyped_defs = False
29+
ignore_missing_imports = False
30+
follow_imports = normal
31+
32+
[mypy-rll_worker.*]
33+
#allow_untyped_defs = False
34+
ignore_missing_imports = False
35+
follow_imports = normal

rll_common/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ catkin_install_python(PROGRAMS scripts/edit_projects.py scripts/jobdata_cleanup.
1414

1515
#catkin_lint: ignore_once missing_file
1616
install(FILES
17-
config/common.yaml config/demos.yaml config/projects.yaml
17+
config/common.yaml config/demos.yaml config/logging.yaml config/projects.yaml
1818
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}/config OPTIONAL)

rll_common/config/logging.yaml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
version: 1
2+
3+
formatters:
4+
default:
5+
format: "%(asctime)s %(levelname)s %(name)s: %(message)s"
6+
extended:
7+
format: "%(asctime)s %(levelname)s %(name)s, line:%(lineno)d: %(message)s"
8+
9+
handlers:
10+
console:
11+
class: logging.StreamHandler
12+
level: DEBUG
13+
stream: "ext://sys.stdout"
14+
formatter: default
15+
16+
file_handler:
17+
class: logging.FileHandler
18+
level: INFO
19+
filename: "/tmp/{log_name}.log"
20+
formatter: extended
21+
22+
error_console_handler:
23+
class: logging.StreamHandler
24+
stream: "ext://sys.stderr"
25+
level: ERROR
26+
formatter: extended
27+
28+
root:
29+
handlers: [file_handler, error_console_handler, console]
30+
level: DEBUG
31+
propagate: false
32+
33+
disable_existing_loggers: false

rll_common/requirements.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
tornado<5
21
docker
3-
motor<1.3
4-
bcrypt
5-
ansi2html
6-
flake8
2+
rospkg
3+
pymongo
4+
PyYAML
5+
typing
6+
future

0 commit comments

Comments
 (0)