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

Configure mypy in workspace #156

Merged
merged 27 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
13428c8
Add mypy type checker
DFriend01 Jul 25, 2023
d3458a8
Create type checking vscode task and remove mypy extension
DFriend01 Jul 25, 2023
5464dfa
Modify mypy task to lint entire ROS packages rather than a single file
DFriend01 Jul 25, 2023
3e08cd1
Specify interpreter path for python extensions (#155)
DFriend01 Jul 25, 2023
fc2fdfa
Format all Python strings to be double quotes (#158)
patrick-5546 Jul 30, 2023
294fddb
Add github copilot extension (#159)
DFriend01 Aug 17, 2023
99c8be7
Delete deprecated python setting
patrick-5546 Aug 30, 2023
94c22cd
Enable mypy extension
patrick-5546 Aug 30, 2023
5ee7c22
Add mypy task TODO
patrick-5546 Aug 30, 2023
77a4432
Install ament_mypy
patrick-5546 Aug 30, 2023
35dee71
Add mypy to CI
patrick-5546 Aug 30, 2023
ef0518c
Update TODO
patrick-5546 Aug 30, 2023
db5cb56
Merge remote-tracking branch 'origin/main' into user/dfriend01/add-mypy
patrick-5546 Aug 30, 2023
755e387
Fix mypy CI
patrick-5546 Aug 30, 2023
7c4776a
Merge branch 'main' into user/dfriend01/add-mypy
patrick-5546 Aug 31, 2023
971f09b
Uncomment mypy task
patrick-5546 Sep 14, 2023
2e68e86
Merge remote-tracking branch 'origin/main' into user/dfriend01/add-mypy
patrick-5546 Oct 10, 2023
9c026d7
Update base-dev image tag
patrick-5546 Oct 10, 2023
27bc60a
Create mypy vscode tasks for each python pkg
patrick-5546 Oct 11, 2023
a8e6ff7
Add mypy global_launch task
patrick-5546 Oct 11, 2023
34d5cee
Fix global_launch mypy error
patrick-5546 Oct 11, 2023
c2c2f52
Loop over valid sub directories
patrick-5546 Oct 11, 2023
d32860f
Fix ament linter script
patrick-5546 Oct 11, 2023
e527670
Uses CI script in tasks
patrick-5546 Oct 11, 2023
2b09de6
Exit with error if any lint run has errors
patrick-5546 Oct 11, 2023
ee8c07e
Add to dictionary
patrick-5546 Oct 11, 2023
b190cfc
Fix mypy extension errors
patrick-5546 Oct 11, 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
2 changes: 1 addition & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ghcr.io/ubcsailbot/sailbot_workspace/dev:py-plotly
FROM ghcr.io/ubcsailbot/sailbot_workspace/dev:add-ament-mypy-v2

# Copy configuration files (e.g., .vimrc) from config/ to the container's home directory
ARG USERNAME=ros
Expand Down
3 changes: 2 additions & 1 deletion .devcontainer/base-dev/base-dev.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,15 @@ RUN apt-get update && apt-get install -y \
wget \
# Install ros distro testing packages
ros-humble-ament-lint \
ros-humble-ament-mypy \
ros-humble-launch-testing \
ros-humble-launch-testing-ament-cmake \
ros-humble-launch-testing-ros \
python3-autopep8 \
&& rm -rf /var/lib/apt/lists/* \
&& rosdep init || echo "rosdep already initialized" \
# Update pydocstyle
&& pip3 install --upgrade pydocstyle
&& pip3 install --upgrade pydocstyle mypy

ARG USERNAME=ros
ARG USER_UID=1000
Expand Down
46 changes: 30 additions & 16 deletions .devcontainer/config/sailbot_workspace.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,14 @@
"DCMAKE",
"deque",
"devcontainer",
"dtype",
"gaurav",
"ints",
"isort",
"kmph",
"mkdocs",
"mongocxx",
"mypy",
"noqa",
"OMPL",
"pallete",
Expand Down Expand Up @@ -159,7 +161,6 @@
],
"flake8.interpreter": ["/usr/bin/python3"],
// formatter: black and isort extensions
"python.formatting.provider": "none",
"black-formatter.interpreter": ["/usr/bin/python3"],
"black-formatter.args": [
"--line-length=99",
Expand All @@ -172,6 +173,11 @@
"--ignore=/workspaces/sailbot_workspace/src/raye-local-pathfinding",
],
"python.testing.pytestEnabled": true,
// type checker: mypy
"mypy-type-checker.args": [
"--ignore-missing-imports",
],
"mypy-type-checker.interpreter": ["/usr/bin/python3"],

// c/c++
"[cpp]": {
Expand Down Expand Up @@ -352,15 +358,13 @@
{
"label": "lint_cmake",
"detail": "Run lint on cmake files.",
"type": "ament",
"task": "lint_cmake",
"path": "src/",
"type": "shell",
"command": "LINTER=lint_cmake LOCAL_RUN=true .github/actions/ament-lint/run.sh",
"problemMatcher": [
"$ament_lint_cmake"
],
"presentation": {
"panel": "dedicated",
"reveal": "silent",
"clear": true
}
},
Expand All @@ -372,38 +376,45 @@
"problemMatcher": [],
"presentation": {
"panel": "dedicated",
"reveal": "always",
"clear": true
}
},
{
"label": "flake8",
"detail": "Run flake8 on python files.",
"type": "ament",
"task": "flake8",
"path": "src/",
"commandOptions": "--exclude=src/virtual_iridium,src/raye-local-pathfinding",
"type": "shell",
"command": "LINTER=flake8 LOCAL_RUN=true .github/actions/ament-lint/run.sh",
"problemMatcher": [
"$ament_flake8"
],
"presentation": {
"panel": "dedicated",
"reveal": "silent",
"clear": true
}
},
{
"label": "mypy",
"detail": "Run mypy on python files.",
"type": "shell",
"command": "LINTER=mypy LOCAL_RUN=true .github/actions/ament-lint/run.sh",
"problemMatcher": [
"$ament_mypy",
],
"presentation": {
"panel": "dedicated",
"clear": true
}
},
{
"label": "xmllint",
"detail": "Run xmllint on xml files.",
"type": "ament",
"task": "xmllint",
"path": "src/",
"type": "shell",
"command": "LINTER=xmllint LOCAL_RUN=true .github/actions/ament-lint/run.sh",
"problemMatcher": [
"$ament_xmllint",
],
"presentation": {
"panel": "dedicated",
"reveal": "silent",
"clear": true
}
},
Expand All @@ -413,6 +424,7 @@
"dependsOn": [
"lint_cmake",
"flake8",
"mypy",
"xmllint",
],
"problemMatcher": []
Expand All @@ -438,10 +450,12 @@
{
"id": "package",
"type": "pickString",
"description": "Package to build",
"description": "Package to select",
"options": [
"boat_simulator",
"controller",
"custom_interfaces",
"global_launch",
"local_pathfinding",
"network_systems",
]
Expand Down
1 change: 1 addition & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
"ms-python.vscode-pylance",
"ms-toolsai.jupyter",
"ms-vsliveshare.vsliveshare",
"ms-python.mypy-type-checker",
"njpwerner.autodocstring",
"stevejpurves.cucumber",
"streetsidesoftware.code-spell-checker",
Expand Down
23 changes: 18 additions & 5 deletions .github/actions/ament-lint/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ function get_search_command {
case ${LINTER} in
lint_cmake) CMD='find ${VALID_SRC_DIRS_ARG} -type f \( -name "CMakeLists.txt" -o -name "*.cmake" -o -name "*.cmake.in" \)' ;;
flake8) CMD='find ${VALID_SRC_DIRS_ARG} -type f -name "*.py"' ;;
mypy) CMD='find ${VALID_SRC_DIRS_ARG} -type f -name "*.py"' ;;
xmllint) CMD='find ${VALID_SRC_DIRS_ARG} -type f -name "*.xml"' ;;
*) error "ERROR: Invalid linter ${LINTER} specified in ament-lint action"; exit 1 ;;
esac
Expand All @@ -42,10 +43,22 @@ function lint {
fi
}

source /opt/ros/${ROS_DISTRO}/setup.bash
./setup.sh
cd src
if [[ $LOCAL_RUN != "true" ]]; then
source /opt/ros/${ROS_DISTRO}/setup.bash
./setup.sh
fi

# Exclude repos and files we don't want to lint
VALID_SRC_DIRS=$(ls | grep -v -e virtual_iridium -e docs -e raye-local-pathfinding -e polaris.repos)
lint ${VALID_SRC_DIRS}
VALID_SRC_DIRS=$(ls src | grep -v -e virtual_iridium -e docs -e raye-local-pathfinding -e website -e notebooks -e polaris.repos)
lint_errors=0

# Loop over each directory and lint it
for dir in $VALID_SRC_DIRS; do
echo "Run $LINTER on src/$dir"
lint src/$dir || { warn "WARNING: $LINTER errors in src/$dir, continuing with others"; lint_errors=1; }
done

# Exit with an error if any lint command failed
if [ "$lint_errors" -ne 0 ]; then
exit 1
fi
4 changes: 2 additions & 2 deletions .github/workflows/test_definitions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ jobs:
strategy:
fail-fast: false
matrix:
# ament_lint_common, except for copyright, cppcheck, cpplint, uncrustify, and pep257
linter: [lint_cmake, flake8, xmllint]
# mypy and ament_lint_common, except for copyright, cppcheck, cpplint, uncrustify, and pep257
linter: [lint_cmake, flake8, mypy, xmllint]
name: ament_${{ matrix.linter }}
runs-on: ubuntu-latest
if: ${{ inputs.ros-ci }}
Expand Down
8 changes: 5 additions & 3 deletions src/global_launch/main_launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import os
from typing import List

from launch import LaunchDescription, LaunchDescriptionEntity
from launch import LaunchDescription
from launch.actions import (
DeclareLaunchArgument,
IncludeLaunchDescription,
Expand All @@ -20,7 +20,9 @@
DEVELOPMENT_ROS_PACKAGES = ["boat_simulator", "local_pathfinding", "network_systems"]

# Global launch arguments and constants.
ROS_PACKAGES_DIR = os.path.join(os.getenv("ROS_WORKSPACE"), "src")
ROS_PACKAGES_DIR = os.path.join(
os.getenv("ROS_WORKSPACE", default="/workspaces/sailbot_workspace"), "src"
)
GLOBAL_LAUNCH_ARGUMENTS = [
DeclareLaunchArgument(
name="config",
Expand Down Expand Up @@ -65,7 +67,7 @@ def generate_launch_description() -> LaunchDescription:
return launch_description


def setup_launch(context: LaunchContext) -> List[LaunchDescriptionEntity]:
def setup_launch(context: LaunchContext) -> List[IncludeLaunchDescription]:
"""Collects launch descriptions from all local launch files.

Args:
Expand Down