diff --git a/.conda/recipe.yaml b/.conda/recipe.yaml index 7bc17da0..0783f994 100644 --- a/.conda/recipe.yaml +++ b/.conda/recipe.yaml @@ -2,66 +2,83 @@ package: name: unilabos version: 0.10.1 +source: + path: ../unilabos + target_directory: unilabos + build: noarch: python - number: 0 script: - - python -m pip install paho-mqtt opentrons_shared_data - - python -m pip install git+https://github.com/Xuwznln/pylabrobot.git + - set PIP_NO_INDEX= +# - python -m pip install paho-mqtt opentrons_shared_data +# - python -m pip install git+https://github.com/Xuwznln/pylabrobot.git + - if: win + then: + - copy %RECIPE_DIR%\..\MANIFEST.in %SRC_DIR% + - copy %RECIPE_DIR%\..\setup.cfg %SRC_DIR% + - copy %RECIPE_DIR%\..\setup.py %SRC_DIR% + - python -m pip install %SRC_DIR% + - if: unix + then: + - cp $RECIPE_DIR/../MANIFEST.in $SRC_DIR + - cp $RECIPE_DIR/../setup.cfg $SRC_DIR + - cp $RECIPE_DIR/../setup.py $SRC_DIR + - python -m pip install $SRC_DIR + requirements: host: - - python >=3.11 - - pip - - setuptools + - python ==3.11.11 + - pip + - setuptools run: - - conda-forge::python =3.11.11 - - compilers - - cmake - - make - - ninja - - sphinx - - sphinx_rtd_theme - - numpy - - scipy - - pandas - - networkx - - matplotlib - - pint - - pyserial - - pyusb - - pylibftdi - - pymodbus - - python-can - - pyvisa - - opencv - - pydantic - - fastapi - - uvicorn - - gradio - - flask - - websocket - - ipython - - jupyter - - jupyros - - colcon-common-extensions - - robostack-staging::ros-humble-desktop-full - - robostack-staging::ros-humble-control-msgs - - robostack-staging::ros-humble-sensor-msgs - - robostack-staging::ros-humble-trajectory-msgs - - ros-humble-navigation2 - - ros-humble-ros2-control - - ros-humble-robot-state-publisher - - ros-humble-joint-state-publisher - - ros-humble-rosbridge-server - - ros-humble-cv-bridge - - ros-humble-tf2 - - ros-humble-moveit - - ros-humble-moveit-servo - - ros-humble-simulation - - ros-humble-tf-transformations - - transforms3d - - uni-lab::ros-humble-unilabos-msgs + - conda-forge::python ==3.11.11 + - compilers + - cmake + - make + - ninja + - sphinx + - sphinx_rtd_theme + - numpy + - scipy + - pandas + - networkx + - matplotlib + - pint + - pyserial + - pyusb + - pylibftdi + - pymodbus + - python-can + - pyvisa + - opencv + - pydantic + - fastapi + - uvicorn + - gradio + - flask + - websocket + - ipython + - jupyter + - jupyros + - colcon-common-extensions + - robostack-staging::ros-humble-desktop-full + - robostack-staging::ros-humble-control-msgs + - robostack-staging::ros-humble-sensor-msgs + - robostack-staging::ros-humble-trajectory-msgs + - ros-humble-navigation2 + - ros-humble-ros2-control + - ros-humble-robot-state-publisher + - ros-humble-joint-state-publisher + - ros-humble-rosbridge-server + - ros-humble-cv-bridge + - ros-humble-tf2 + - ros-humble-moveit + - ros-humble-moveit-servo + - ros-humble-simulation + - ros-humble-tf-transformations + - transforms3d + - uni-lab::ros-humble-unilabos-msgs about: repository: https://github.com/dptech-corp/Uni-Lab-OS diff --git a/.conda/recipe_new.yaml b/.conda/recipe_new.yaml deleted file mode 100644 index 0a2c7780..00000000 --- a/.conda/recipe_new.yaml +++ /dev/null @@ -1,23 +0,0 @@ -package: - name: unilabos - version: "0.10.1" - -source: - path: ../.. - -build: - noarch: python - script: | - {{ PYTHON }} -m pip install . --no-deps --ignore-installed -vv -# {{ PYTHON }} clean_build_dir.py - -requirements: - host: - - python - - pip - run: - - python - -test: - imports: - - unilabos diff --git a/.github/workflows/multi-platform-build.yml b/.github/workflows/multi-platform-build.yml index 72dafa57..7b703c7b 100644 --- a/.github/workflows/multi-platform-build.yml +++ b/.github/workflows/multi-platform-build.yml @@ -2,16 +2,21 @@ name: Multi-Platform Conda Build on: push: - branches: [ main, dev ] - tags: [ 'v*' ] + branches: [main, dev] + tags: ['v*'] pull_request: - branches: [ main, dev ] + branches: [main, dev] workflow_dispatch: inputs: platforms: description: '选择构建平台 (逗号分隔): linux-64, osx-64, osx-arm64, win-64' required: false default: 'osx-arm64' + upload_to_anaconda: + description: '是否上传到Anaconda.org' + required: false + default: false + type: boolean jobs: build: @@ -19,18 +24,18 @@ jobs: fail-fast: false matrix: include: - - os: ubuntu-latest - platform: linux-64 - env_file: unilabos-linux-64.yaml - - os: macos-13 # Intel - platform: osx-64 - env_file: unilabos-osx-64.yaml - - os: macos-latest # ARM64 - platform: osx-arm64 - env_file: unilabos-osx-arm64.yaml - - os: windows-latest - platform: win-64 - env_file: unilabos-win64.yaml + - os: ubuntu-latest + platform: linux-64 + env_file: unilabos-linux-64.yaml + - os: macos-13 # Intel + platform: osx-64 + env_file: unilabos-osx-64.yaml + - os: macos-latest # ARM64 + platform: osx-arm64 + env_file: unilabos-osx-arm64.yaml + - os: windows-latest + platform: win-64 + env_file: unilabos-win64.yaml runs-on: ${{ matrix.os }} @@ -39,94 +44,98 @@ jobs: shell: bash -l {0} steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 + - uses: actions/checkout@v4 + with: + fetch-depth: 0 - - name: Check if platform should be built - id: should_build - run: | - if [[ "${{ github.event_name }}" != "workflow_dispatch" ]]; then - echo "should_build=true" >> $GITHUB_OUTPUT - elif [[ -z "${{ github.event.inputs.platforms }}" ]]; then - echo "should_build=true" >> $GITHUB_OUTPUT - elif [[ "${{ github.event.inputs.platforms }}" == *"${{ matrix.platform }}"* ]]; then - echo "should_build=true" >> $GITHUB_OUTPUT - else - echo "should_build=false" >> $GITHUB_OUTPUT - fi + - name: Check if platform should be built + id: should_build + run: | + if [[ "${{ github.event_name }}" != "workflow_dispatch" ]]; then + echo "should_build=true" >> $GITHUB_OUTPUT + elif [[ -z "${{ github.event.inputs.platforms }}" ]]; then + echo "should_build=true" >> $GITHUB_OUTPUT + elif [[ "${{ github.event.inputs.platforms }}" == *"${{ matrix.platform }}"* ]]; then + echo "should_build=true" >> $GITHUB_OUTPUT + else + echo "should_build=false" >> $GITHUB_OUTPUT + fi - - name: Setup Miniconda - if: steps.should_build.outputs.should_build == 'true' - uses: conda-incubator/setup-miniconda@v3 - with: - miniconda-version: "latest" - channels: conda-forge,robostack-staging,defaults - channel-priority: strict - activate-environment: build-env - auto-activate-base: false - auto-update-conda: false - show-channel-urls: true + - name: Setup Miniconda + if: steps.should_build.outputs.should_build == 'true' + uses: conda-incubator/setup-miniconda@v3 + with: + miniconda-version: 'latest' + channels: conda-forge,robostack-staging,defaults + channel-priority: strict + activate-environment: build-env + auto-activate-base: false + auto-update-conda: false + show-channel-urls: true - - name: Install boa and build tools - if: steps.should_build.outputs.should_build == 'true' - run: | - conda install -c conda-forge boa conda-build + - name: Install rattler-build and anaconda-client + if: steps.should_build.outputs.should_build == 'true' + run: | + conda install -c conda-forge rattler-build anaconda-client - - name: Show environment info - if: steps.should_build.outputs.should_build == 'true' - run: | - conda info - conda list | grep -E "(boa|conda-build)" - echo "Platform: ${{ matrix.platform }}" - echo "OS: ${{ matrix.os }}" + - name: Show environment info + if: steps.should_build.outputs.should_build == 'true' + run: | + conda info + conda list | grep -E "(rattler-build|anaconda-client)" + echo "Platform: ${{ matrix.platform }}" + echo "OS: ${{ matrix.os }}" - - name: Build conda package - if: steps.should_build.outputs.should_build == 'true' - run: | - if [[ "${{ matrix.platform }}" == "osx-arm64" ]]; then - boa build -m ./recipes/conda_build_config.yaml -m ./recipes/macos_sdk_config.yaml ./recipes/ros-humble-unilabos-msgs - else - boa build -m ./recipes/conda_build_config.yaml ./recipes/ros-humble-unilabos-msgs - fi + - name: Build conda package + if: steps.should_build.outputs.should_build == 'true' + run: | + if [[ "${{ matrix.platform }}" == "osx-arm64" ]]; then + rattler-build build -r ./recipes/msgs/recipe.yaml -c robostack -c robostack-staging -c conda-forge + else + rattler-build build -r ./recipes/msgs/recipe.yaml -c robostack -c robostack-staging -c conda-forge + fi - - name: List built packages - if: steps.should_build.outputs.should_build == 'true' - run: | - echo "Built packages in conda-bld:" - find $CONDA_PREFIX/conda-bld -name "*.tar.bz2" | head -10 - ls -la $CONDA_PREFIX/conda-bld/${{ matrix.platform }}/ || echo "${{ matrix.platform }} directory not found" - ls -la $CONDA_PREFIX/conda-bld/noarch/ || echo "noarch directory not found" - echo "CONDA_PREFIX: $CONDA_PREFIX" - echo "Full path would be: $CONDA_PREFIX/conda-bld/**/*.tar.bz2" + - name: List built packages + if: steps.should_build.outputs.should_build == 'true' + run: | + echo "Built packages in output directory:" + find ./output -name "*.conda" | head -10 + ls -la ./output/${{ matrix.platform }}/ || echo "${{ matrix.platform }} directory not found" + ls -la ./output/noarch/ || echo "noarch directory not found" + echo "Output directory structure:" + find ./output -type f -name "*.conda" - - name: Prepare artifacts for upload - if: steps.should_build.outputs.should_build == 'true' - run: | - mkdir -p ${{ runner.temp }}/conda-packages - find $CONDA_PREFIX/conda-bld -name "*.tar.bz2" -exec cp {} ${{ runner.temp }}/conda-packages/ \; - echo "Copied files to temp directory:" - ls -la ${{ runner.temp }}/conda-packages/ + - name: Prepare artifacts for upload + if: steps.should_build.outputs.should_build == 'true' + run: | + mkdir -p conda-packages-temp + find ./output -name "*.conda" -exec cp {} conda-packages-temp/ \; + echo "Copied files to temp directory:" + ls -la conda-packages-temp/ - - name: Upload conda package artifacts - if: steps.should_build.outputs.should_build == 'true' - uses: actions/upload-artifact@v4 - with: - name: conda-package-${{ matrix.platform }} - path: ${{ runner.temp }}/conda-packages - if-no-files-found: warn - retention-days: 30 + - name: Upload conda package artifacts + if: steps.should_build.outputs.should_build == 'true' + uses: actions/upload-artifact@v4 + with: + name: conda-package-${{ matrix.platform }} + path: conda-packages-temp + if-no-files-found: warn + retention-days: 30 - - name: Create release assets (on tags) - if: steps.should_build.outputs.should_build == 'true' && startsWith(github.ref, 'refs/tags/') - run: | - mkdir -p release-assets - find $CONDA_PREFIX/conda-bld -name "*.tar.bz2" -exec cp {} release-assets/ \; + - name: Login to Anaconda with API token + if: steps.should_build.outputs.should_build == 'true' && (github.event.inputs.upload_to_anaconda == 'true' || (github.ref == 'refs/heads/main' && github.event_name != 'pull_request')) + run: | + anaconda login --token ${{ secrets.ANACONDA_API_TOKEN }} - - name: Upload to release - if: steps.should_build.outputs.should_build == 'true' && startsWith(github.ref, 'refs/tags/') - uses: softprops/action-gh-release@v1 - with: - files: release-assets/* - draft: false - prerelease: false + - name: Upload to Anaconda.org (unilab organization) + if: steps.should_build.outputs.should_build == 'true' && (github.event.inputs.upload_to_anaconda == 'true' || (github.ref == 'refs/heads/main' && github.event_name != 'pull_request')) + run: | + for package in $(find ./output -name "*.conda"); do + echo "Uploading $package to unilab organization..." + anaconda upload --user uni-lab --force "$package" + done + + - name: Logout from Anaconda + if: always() && steps.should_build.outputs.should_build == 'true' && (github.event.inputs.upload_to_anaconda == 'true' || (github.ref == 'refs/heads/main' && github.event_name != 'pull_request')) + run: | + anaconda logout || true diff --git a/.github/workflows/unilabos-conda-build.yml b/.github/workflows/unilabos-conda-build.yml new file mode 100644 index 00000000..9b5fbfb2 --- /dev/null +++ b/.github/workflows/unilabos-conda-build.yml @@ -0,0 +1,94 @@ +name: UniLabOS Conda Build + +on: + push: + branches: [main, dev] + tags: ['v*'] + pull_request: + branches: [main, dev] + workflow_dispatch: + inputs: + upload_to_anaconda: + description: '是否上传到Anaconda.org' + required: false + default: false + type: boolean + +jobs: + build: + runs-on: ubuntu-latest + + defaults: + run: + shell: bash -l {0} + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Setup Miniconda + uses: conda-incubator/setup-miniconda@v3 + with: + miniconda-version: 'latest' + channels: conda-forge,robostack-staging,uni-lab,defaults + channel-priority: strict + activate-environment: build-env + auto-activate-base: false + auto-update-conda: false + show-channel-urls: true + + - name: Install rattler-build and anaconda-client + run: | + conda install -c conda-forge rattler-build anaconda-client + + - name: Show environment info + run: | + conda info + conda list | grep -E "(rattler-build|anaconda-client)" + echo "Building UniLabOS package" + + - name: Build conda package + run: | + rattler-build build -r .conda/recipe.yaml -c uni-lab -c robostack-staging -c conda-forge + + - name: List built packages + run: | + echo "Built packages in output directory:" + find ./output -name "*.conda" | head -10 + ls -la ./output/noarch/ || echo "noarch directory not found" + echo "Output directory structure:" + find ./output -type f -name "*.conda" + + - name: Prepare artifacts for upload + run: | + mkdir -p conda-packages-temp + find ./output -name "*.conda" -exec cp {} conda-packages-temp/ \; + echo "Copied files to temp directory:" + ls -la conda-packages-temp/ + + - name: Upload conda package artifacts + uses: actions/upload-artifact@v4 + with: + name: conda-package-unilabos + path: conda-packages-temp + if-no-files-found: warn + retention-days: 30 + + - name: Login to Anaconda with API token + if: github.event.inputs.upload_to_anaconda == 'true' || (github.ref == 'refs/heads/main' && github.event_name != 'pull_request') + run: | + anaconda login --token ${{ secrets.ANACONDA_API_TOKEN }} + + - name: Upload to Anaconda.org (uni-lab organization) + if: github.event.inputs.upload_to_anaconda == 'true' || (github.ref == 'refs/heads/main' && github.event_name != 'pull_request') + run: | + for package in $(find ./output -name "*.conda"); do + echo "Uploading $package to uni-lab organization..." + anaconda upload --user uni-lab --force "$package" + done + + - name: Logout from Anaconda + if: always() && (github.event.inputs.upload_to_anaconda == 'true' || (github.ref == 'refs/heads/main' && github.event_name != 'pull_request')) + run: | + anaconda logout || true diff --git a/MANIFEST.in b/MANIFEST.in index 4c1e88b8..aa1a5d87 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,5 +1,5 @@ recursive-include unilabos/registry *.yaml -recursive-include unilabos/app/static * -recursive-include unilabos/app/templates * +recursive-include unilabos/app/web/static * +recursive-include unilabos/app/web/templates * recursive-include unilabos/device_mesh/devices * recursive-include unilabos/device_mesh/resources * diff --git a/recipes/ros-humble-unilabos-msgs/bld_ament_cmake.bat b/recipes/msgs/bld_ament_cmake.bat similarity index 90% rename from recipes/ros-humble-unilabos-msgs/bld_ament_cmake.bat rename to recipes/msgs/bld_ament_cmake.bat index 9bf01552..10bdee94 100644 --- a/recipes/ros-humble-unilabos-msgs/bld_ament_cmake.bat +++ b/recipes/msgs/bld_ament_cmake.bat @@ -1,4 +1,4 @@ -:: Generated by vinca http://github.com/RoboStack/vinca. +::Generated by vinca http://github.com/RoboStack/vinca. :: DO NOT EDIT! setlocal EnableDelayedExpansion @@ -19,6 +19,7 @@ set "CMAKE_GENERATOR=Visual Studio %VS_MAJOR% %VS_YEAR%" set "SP_DIR_FORWARDSLASHES=%SP_DIR:\=/%" set PYTHON="%PREFIX%\python.exe" +set PYTHON=%PYTHON:\=\\% cmake ^ -G "%CMAKE_GENERATOR%" ^ @@ -34,8 +35,10 @@ cmake ^ -DCMAKE_OBJECT_PATH_MAX=255 ^ -DPYTHON_INSTALL_DIR=%SP_DIR_FORWARDSLASHES% ^ --compile-no-warning-as-error ^ - %SRC_DIR%\%PKG_NAME%\src\work + %SRC_DIR%\src + if errorlevel 1 exit 1 cmake --build . --config Release --target install + if errorlevel 1 exit 1 diff --git a/recipes/ros-humble-unilabos-msgs/build_ament_cmake.sh b/recipes/msgs/build_ament_cmake.sh similarity index 95% rename from recipes/ros-humble-unilabos-msgs/build_ament_cmake.sh rename to recipes/msgs/build_ament_cmake.sh index 52baa99c..91c9f0fe 100644 --- a/recipes/ros-humble-unilabos-msgs/build_ament_cmake.sh +++ b/recipes/msgs/build_ament_cmake.sh @@ -24,7 +24,7 @@ echo "USING PKG_CONFIG_EXECUTABLE=${PKG_CONFIG_EXECUTABLE}" export ROS_PYTHON_VERSION=`$PYTHON_EXECUTABLE -c "import sys; print('%i.%i' % (sys.version_info[0:2]))"` echo "Using Python ${ROS_PYTHON_VERSION}" # Fix up SP_DIR which for some reason might contain a path to a wrong Python version -FIXED_SP_DIR=$(echo $SP_DIR | sed -E "s/python[0-9]+\.[0-9]+/python$ROS_PYTHON_VERSION/") +FIXED_SP_DIR=$($PYTHON_EXECUTABLE -c "import site; print(site.getsitepackages()[0])") echo "Using site-package dir ${FIXED_SP_DIR}" # see https://github.com/conda-forge/cross-python-feedstock/issues/24 @@ -66,6 +66,6 @@ cmake \ -DBUILD_TESTING=OFF \ -DCMAKE_OSX_DEPLOYMENT_TARGET=$OSX_DEPLOYMENT_TARGET \ --compile-no-warning-as-error \ - $SRC_DIR/$PKG_NAME/src/work + $SRC_DIR/src cmake --build . --config Release --target install diff --git a/recipes/msgs/recipe.yaml b/recipes/msgs/recipe.yaml new file mode 100644 index 00000000..3909ee44 --- /dev/null +++ b/recipes/msgs/recipe.yaml @@ -0,0 +1,76 @@ +package: + name: ros-humble-unilabos-msgs + version: 0.10.1 +source: + path: ../../unilabos_msgs + target_directory: src + +build: + script: + - if: win + then: + - copy %RECIPE_DIR%\bld_ament_cmake.bat %SRC_DIR% + - call %SRC_DIR%\bld_ament_cmake.bat + - if: unix + then: + - cp $RECIPE_DIR/build_ament_cmake.sh $SRC_DIR + - bash $SRC_DIR/build_ament_cmake.sh + +about: + repository: https://github.com/dptech-corp/Uni-Lab-OS + license: BSD-3-Clause + description: "ros-humble-unilabos-msgs is a package that provides message definitions for Uni-Lab-OS." + +requirements: + build: + - if: build_platform != target_platform + then: + - pkg-config + - python ==3.11.11 + - cross-python_${{ target_platform }} + - numpy + - ${{ compiler('cxx') }} + - ${{ compiler('c') }} + - if: linux and x86_64 + then: + - sysroot_linux-64 ==2.17 + - ninja + - setuptools + - cython + - cmake + - if: unix + then: + - make + - coreutils + - if: osx + then: + - tapi + - if: win + then: + - vs2022_win-64 + host: + - numpy + - pip + - if: build_platform == target_platform + then: + - pkg-config + - robostack-staging::ros-humble-action-msgs + - robostack-staging::ros-humble-ament-cmake + - robostack-staging::ros-humble-ament-lint-auto + - robostack-staging::ros-humble-ament-lint-common + - robostack-staging::ros-humble-ros-environment + - robostack-staging::ros-humble-ros-workspace + - robostack-staging::ros-humble-rosidl-default-generators + - robostack-staging::ros-humble-std-msgs + - robostack-staging::ros-humble-geometry-msgs + - robostack-staging::ros2-distro-mutex=0.6 + run: + - robostack-staging::ros-humble-action-msgs + - robostack-staging::ros-humble-ros-workspace + - robostack-staging::ros-humble-rosidl-default-runtime + - robostack-staging::ros-humble-std-msgs + - robostack-staging::ros-humble-geometry-msgs + - robostack-staging::ros2-distro-mutex=0.6 + - if: osx and x86_64 + then: + - __osx >=${{ MACOSX_DEPLOYMENT_TARGET|default('10.14') }} diff --git a/recipes/ros-humble-unilabos-msgs/recipe.yaml b/recipes/ros-humble-unilabos-msgs/recipe.yaml deleted file mode 100644 index 258047cb..00000000 --- a/recipes/ros-humble-unilabos-msgs/recipe.yaml +++ /dev/null @@ -1,61 +0,0 @@ -package: - name: ros-humble-unilabos-msgs - version: 0.10.1 -source: - path: ../../unilabos_msgs - folder: ros-humble-unilabos-msgs/src/work - -build: - script: - sel(win): bld_ament_cmake.bat - sel(unix): build_ament_cmake.sh - number: 5 -about: - home: https://www.ros.org/ - license: BSD-3-Clause - summary: | - Robot Operating System - -extra: - recipe-maintainers: - - ros-forge - -requirements: - build: - - "{{ compiler('cxx') }}" - - "{{ compiler('c') }}" - - sel(linux64): sysroot_linux-64 2.17 - - ninja - - setuptools - - sel(unix): make - - sel(unix): coreutils - - sel(osx): tapi - - sel(build_platform != target_platform): pkg-config - - cmake - - cython - - sel(win): vs2022_win-64 - - sel(build_platform != target_platform): python - - sel(build_platform != target_platform): cross-python_{{ target_platform }} - - sel(build_platform != target_platform): numpy - host: - - numpy - - pip - - sel(build_platform == target_platform): pkg-config - - robostack-staging::ros-humble-action-msgs - - robostack-staging::ros-humble-ament-cmake - - robostack-staging::ros-humble-ament-lint-auto - - robostack-staging::ros-humble-ament-lint-common - - robostack-staging::ros-humble-ros-environment - - robostack-staging::ros-humble-ros-workspace - - robostack-staging::ros-humble-rosidl-default-generators - - robostack-staging::ros-humble-std-msgs - - robostack-staging::ros-humble-geometry-msgs - - robostack-staging::ros2-distro-mutex=0.6.* - run: - - robostack-staging::ros-humble-action-msgs - - robostack-staging::ros-humble-ros-workspace - - robostack-staging::ros-humble-rosidl-default-runtime - - robostack-staging::ros-humble-std-msgs - - robostack-staging::ros-humble-geometry-msgs -# - robostack-staging::ros2-distro-mutex=0.6.* - - sel(osx and x86_64): __osx >={{ MACOSX_DEPLOYMENT_TARGET|default('10.14') }} diff --git a/unilabos/utils/log.py b/unilabos/utils/log.py index 61c95a14..a6801018 100644 --- a/unilabos/utils/log.py +++ b/unilabos/utils/log.py @@ -144,11 +144,29 @@ class ColoredFormatter(logging.Formatter): # 配置日志处理器 -def configure_logger(): - """配置日志记录器""" +def configure_logger(loglevel=None): + """配置日志记录器 + + Args: + loglevel: 日志级别,可以是字符串('DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL') + 或logging模块的常量(如logging.DEBUG) + """ # 获取根日志记录器 root_logger = logging.getLogger() - root_logger.setLevel(logging.DEBUG) # 修改为DEBUG以显示所有级别 + + # 设置日志级别 + if loglevel is not None: + if isinstance(loglevel, str): + # 将字符串转换为logging级别 + numeric_level = getattr(logging, loglevel.upper(), None) + if not isinstance(numeric_level, int): + print(f"警告: 无效的日志级别 '{loglevel}',使用默认级别 DEBUG") + numeric_level = logging.DEBUG + else: + numeric_level = loglevel + root_logger.setLevel(numeric_level) + else: + root_logger.setLevel(logging.DEBUG) # 默认级别 # 移除已存在的处理器 for handler in root_logger.handlers[:]: @@ -156,7 +174,7 @@ def configure_logger(): # 创建控制台处理器 console_handler = logging.StreamHandler() - console_handler.setLevel(logging.DEBUG) # 修改为DEBUG以显示所有级别 + console_handler.setLevel(root_logger.level) # 使用与根记录器相同的级别 # 使用自定义的颜色格式化器 color_formatter = ColoredFormatter() diff --git a/unilabos_msgs/package.xml b/unilabos_msgs/package.xml index 4ccb3a9d..819cc8c9 100644 --- a/unilabos_msgs/package.xml +++ b/unilabos_msgs/package.xml @@ -2,7 +2,7 @@ unilabos_msgs - 0.0.5 + 0.10.1 ROS2 Messages package for unilabos devices Junhan Chang MIT