diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml new file mode 100644 index 0000000..c934718 --- /dev/null +++ b/.github/workflows/main.yaml @@ -0,0 +1,112 @@ +name: Test Colcon Build +on: + pull_request: + branches: + - main + push: + +jobs: + lint_and_format: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + with: + submodules: recursive + token: ${{ secrets.GH_PAT }} + + - name: Install clang-format + run: | + sudo apt-get update + sudo apt-get install -y clang-format + + - name: Check formatting + run: | + find src -iname *.h -o -iname *.hpp -o -iname *.cpp -o -iname *.c | xargs clang-format --dry-run --Werror + + - name: Install Ruff + run: pip install ruff + + - name: Check Python formatting + run: ruff format --check . + + - name: Check Python linting + run: ruff check . + + # Currently this takes 3+ minutes, but I'm keeping this here if we ever need it + # build: + # needs: format + # runs-on: ubuntu-22.04 + # container: + # image: ros:humble-ros-base + + # steps: + # - name: Checkout code + # uses: actions/checkout@v3 + # with: + # submodules: recursive + # token: ${{ secrets.GH_PAT }} + + # - name: Cache Python dependencies + # uses: actions/cache@v3 + # id: cache-venv + # with: + # path: .venv + # key: venv-${{ runner.os }}-${{ hashFiles('requirements/all_requirements.txt') }} + # restore-keys: | + # venv-${{ runner.os }}- + + # - name: Cache rosdep packages + # uses: actions/cache@v3 + # id: cache-rosdep + # with: + # path: | + # /var/cache/apt/archives + # /var/lib/apt/lists + # key: rosdep-${{ runner.os }}-${{ hashFiles('src/**/package.xml') }} + # restore-keys: | + # rosdep-${{ runner.os }}- + + # - name: Install Python Venv (if cache miss) + # if: steps.cache-venv.outputs.cache-hit != 'true' + # shell: bash + # run: | + # # Install python3-venv if not available + # apt-get update + # apt-get install -y python3-venv + + # # Create virtual environment + # python3 -m venv .venv + + # # Activate and install dependencies + # source .venv/bin/activate + # pip install --upgrade pip + # pip install -r requirements/all_requirements.txt + + # - name: Install rosdep dependencies + # run: | + # # Ensure apt cache is preserved + # rm -f /etc/apt/apt.conf.d/docker-clean + + # # Update rosdep + # apt-get update + # rosdep update + + # # Install dependencies from all packages in src/ + # rosdep install --from-paths src --ignore-src -r -y + + # - name: Build with colcon + # shell: bash + # run: | + # # Activate venv and source ROS2 and workspace environment + # source .venv/bin/activate + # source /opt/ros/humble/setup.bash + + # # Make sure build works (ignore hardware specific packages) + # colcon build --packages-ignore \ + # camera_node \ + # tr-camera-basler \ + # lidar_node \ + # yolox_ros_cpp \ + # yolox_ros \ + # yolox_cpp \ No newline at end of file diff --git a/.gitignore b/.gitignore index c952ef4..75eeaf1 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ rosbag2* # clangd cache .cache/ +.ruff_cache/ \ No newline at end of file diff --git a/.md/cpp_python_lsp_setup.md b/.md/cpp_python_lsp_setup.md index d42bc4a..11e71e7 100644 --- a/.md/cpp_python_lsp_setup.md +++ b/.md/cpp_python_lsp_setup.md @@ -34,12 +34,17 @@ optionally also add the following to save on format "editor.formatOnSave": true, ``` +If you want to auto-format using the terminal, run: +``` +find . -name "*.cpp" -o -name "*.h" | xargs clang-format -i -style=file +``` + ## Python 1. Install the `Python` and `Pylance` extensions by microsoft 2. install `Robot Developer Extensions for Ros2` by `Ranch Hand Robotics LLC` ![extension](ros2_vscode_extension.png) - +3. Install `Ruff` by Astral Software 3. run `ROS2: Update Python Path` (you may need to run this periodically when you add new files or make major changes) 4. you can verify it worked by checking `.vscode/settings.json` and seeing it has added python auto complete and analysis extra paths. 5. you should now have type hints for ros msg definitions and custom msg definitions like tr_messages inside python! diff --git a/requirements/all_requirements.txt b/requirements/all_requirements.txt new file mode 100644 index 0000000..b0dae8f --- /dev/null +++ b/requirements/all_requirements.txt @@ -0,0 +1,20 @@ +# colcon build deps +catkin_pkg==1.1.0 +empy==3.3.4 +lark==1.3.1 +catkin-pkg==1.1.0 +PyYAML==6.0.3 +setuptools==80.9.0 +jinja2==3.1.6 +typeguard==4.4.4 + +# for messages +numpy==1.26.4 + +# for sim_node +mani_skill==3.0.0b21 +torch==2.9.1 +pynput==1.8.1 + +# for linting & formatting +ruff==0.14.14 \ No newline at end of file diff --git a/requirements.txt b/requirements/requirements.txt similarity index 51% rename from requirements.txt rename to requirements/requirements.txt index 355308b..9e95335 100644 --- a/requirements.txt +++ b/requirements/requirements.txt @@ -1,13 +1,12 @@ -# simulation deps -mani_skill -torch -pynput==1.8.1 -coacd - # colcon build deps catkin_pkg empy==3.3.4 lark catkin-pkg PyYAML -setuptools \ No newline at end of file +setuptools +jinja2 +typeguard + +# for linting & formatting +ruff==0.14.14 \ No newline at end of file diff --git a/ruff.toml b/ruff.toml new file mode 100644 index 0000000..183edfa --- /dev/null +++ b/ruff.toml @@ -0,0 +1,8 @@ +line-length = 88 +indent-width = 4 + +[format] +quote-style = "double" +indent-style = "space" +skip-magic-trailing-comma = false +line-ending = "auto"