fix startup env check.

add auto install during one-key installation
This commit is contained in:
Xuwznln
2025-10-13 01:35:28 +08:00
parent 9aeffebde1
commit fb93b1cd94
3 changed files with 58 additions and 39 deletions

View File

@@ -73,7 +73,6 @@ jobs:
channels: conda-forge,robostack-staging,uni-lab,defaults channels: conda-forge,robostack-staging,uni-lab,defaults
channel-priority: flexible channel-priority: flexible
activate-environment: unilab activate-environment: unilab
auto-activate-base: true
auto-update-conda: false auto-update-conda: false
show-channel-urls: true show-channel-urls: true
@@ -82,7 +81,7 @@ jobs:
run: | run: |
echo Installing unilabos and dependencies to unilab environment... echo Installing unilabos and dependencies to unilab environment...
echo Using mamba for faster and more reliable dependency resolution... echo Using mamba for faster and more reliable dependency resolution...
mamba install uni-lab::unilabos conda-pack -c uni-lab -c robostack-staging -c conda-forge -y mamba install -n unilab uni-lab::unilabos conda-pack -c uni-lab -c robostack-staging -c conda-forge -y
- name: Install conda-pack, unilabos and dependencies (Unix) - name: Install conda-pack, unilabos and dependencies (Unix)
if: steps.should_build.outputs.should_build == 'true' && matrix.platform != 'win-64' if: steps.should_build.outputs.should_build == 'true' && matrix.platform != 'win-64'
@@ -90,15 +89,15 @@ jobs:
run: | run: |
echo "Installing unilabos and dependencies to unilab environment..." echo "Installing unilabos and dependencies to unilab environment..."
echo "Using mamba for faster and more reliable dependency resolution..." echo "Using mamba for faster and more reliable dependency resolution..."
mamba install uni-lab::unilabos conda-pack -c uni-lab -c robostack-staging -c conda-forge -y mamba install -n unilab uni-lab::unilabos conda-pack -c uni-lab -c robostack-staging -c conda-forge -y
- name: Get latest ros-humble-unilabos-msgs version (Windows) - name: Get latest ros-humble-unilabos-msgs version (Windows)
if: steps.should_build.outputs.should_build == 'true' && matrix.platform == 'win-64' if: steps.should_build.outputs.should_build == 'true' && matrix.platform == 'win-64'
id: msgs_version_win id: msgs_version_win
run: | run: |
echo Checking installed ros-humble-unilabos-msgs version... echo Checking installed ros-humble-unilabos-msgs version...
conda list ros-humble-unilabos-msgs conda list -n unilab ros-humble-unilabos-msgs
for /f "tokens=2" %%i in ('conda list ros-humble-unilabos-msgs --json ^| python -c "import sys, json; pkgs=json.load(sys.stdin); print(pkgs[0]['version'] if pkgs else 'not-found')"') do set VERSION=%%i for /f "tokens=2" %%i in ('conda list -n unilab ros-humble-unilabos-msgs --json ^| python -c "import sys, json; pkgs=json.load(sys.stdin); print(pkgs[0]['version'] if pkgs else 'not-found')"') do set VERSION=%%i
echo installed_version=%VERSION% >> %GITHUB_OUTPUT% echo installed_version=%VERSION% >> %GITHUB_OUTPUT%
echo Installed ros-humble-unilabos-msgs version: %VERSION% echo Installed ros-humble-unilabos-msgs version: %VERSION%
@@ -108,7 +107,7 @@ jobs:
shell: bash shell: bash
run: | run: |
echo "Checking installed ros-humble-unilabos-msgs version..." echo "Checking installed ros-humble-unilabos-msgs version..."
VERSION=$(conda list ros-humble-unilabos-msgs --json | python -c "import sys, json; pkgs=json.load(sys.stdin); print(pkgs[0]['version'] if pkgs else 'not-found')") VERSION=$(conda list -n unilab ros-humble-unilabos-msgs --json | python -c "import sys, json; pkgs=json.load(sys.stdin); print(pkgs[0]['version'] if pkgs else 'not-found')")
echo "installed_version=$VERSION" >> $GITHUB_OUTPUT echo "installed_version=$VERSION" >> $GITHUB_OUTPUT
echo "Installed ros-humble-unilabos-msgs version: $VERSION" echo "Installed ros-humble-unilabos-msgs version: $VERSION"
@@ -119,7 +118,7 @@ jobs:
mamba search ros-humble-unilabos-msgs -c uni-lab -c robostack-staging -c conda-forge || echo Search completed mamba search ros-humble-unilabos-msgs -c uni-lab -c robostack-staging -c conda-forge || echo Search completed
echo. echo.
echo Updating ros-humble-unilabos-msgs to latest version... echo Updating ros-humble-unilabos-msgs to latest version...
mamba update ros-humble-unilabos-msgs -c uni-lab -c robostack-staging -c conda-forge -y || echo Already at latest version mamba update -n unilab ros-humble-unilabos-msgs -c uni-lab -c robostack-staging -c conda-forge -y || echo Already at latest version
- name: Check for newer ros-humble-unilabos-msgs (Unix) - name: Check for newer ros-humble-unilabos-msgs (Unix)
if: steps.should_build.outputs.should_build == 'true' && matrix.platform != 'win-64' if: steps.should_build.outputs.should_build == 'true' && matrix.platform != 'win-64'
@@ -129,28 +128,28 @@ jobs:
mamba search ros-humble-unilabos-msgs -c uni-lab -c robostack-staging -c conda-forge || echo "Search completed" mamba search ros-humble-unilabos-msgs -c uni-lab -c robostack-staging -c conda-forge || echo "Search completed"
echo "" echo ""
echo "Updating ros-humble-unilabos-msgs to latest version..." echo "Updating ros-humble-unilabos-msgs to latest version..."
mamba update ros-humble-unilabos-msgs -c uni-lab -c robostack-staging -c conda-forge -y || echo "Already at latest version" mamba update -n unilab ros-humble-unilabos-msgs -c uni-lab -c robostack-staging -c conda-forge -y || echo "Already at latest version"
- name: Install latest unilabos from source (Windows) - name: Install latest unilabos from source (Windows)
if: steps.should_build.outputs.should_build == 'true' && matrix.platform == 'win-64' if: steps.should_build.outputs.should_build == 'true' && matrix.platform == 'win-64'
run: | run: |
echo Uninstalling existing unilabos... echo Uninstalling existing unilabos...
pip uninstall unilabos -y || echo unilabos not installed via pip conda run -n unilab pip uninstall unilabos -y || echo unilabos not installed via pip
echo Installing unilabos from source (branch: ${{ github.event.inputs.branch }})... echo Installing unilabos from source (branch: ${{ github.event.inputs.branch }})...
pip install . conda run -n unilab pip install .
echo Verifying installation... echo Verifying installation...
pip show unilabos conda run -n unilab pip show unilabos
- name: Install latest unilabos from source (Unix) - name: Install latest unilabos from source (Unix)
if: steps.should_build.outputs.should_build == 'true' && matrix.platform != 'win-64' if: steps.should_build.outputs.should_build == 'true' && matrix.platform != 'win-64'
shell: bash shell: bash
run: | run: |
echo "Uninstalling existing unilabos..." echo "Uninstalling existing unilabos..."
pip uninstall unilabos -y || echo "unilabos not installed via pip" conda run -n unilab pip uninstall unilabos -y || echo "unilabos not installed via pip"
echo "Installing unilabos from source (branch: ${{ github.event.inputs.branch }})..." echo "Installing unilabos from source (branch: ${{ github.event.inputs.branch }})..."
pip install . conda run -n unilab pip install .
echo "Verifying installation..." echo "Verifying installation..."
pip show unilabos conda run -n unilab pip show unilabos
- name: Display environment info (Windows) - name: Display environment info (Windows)
if: steps.should_build.outputs.should_build == 'true' && matrix.platform == 'win-64' if: steps.should_build.outputs.should_build == 'true' && matrix.platform == 'win-64'
@@ -159,10 +158,10 @@ jobs:
conda env list conda env list
echo. echo.
echo === Installed Packages === echo === Installed Packages ===
conda list | findstr /C:"unilabos" /C:"ros-humble-unilabos-msgs" || conda list conda list -n unilab | findstr /C:"unilabos" /C:"ros-humble-unilabos-msgs" || conda list -n unilab
echo. echo.
echo === Python Packages === echo === Python Packages ===
pip list | findstr unilabos || pip list conda run -n unilab pip list | findstr unilabos || conda run -n unilab pip list
- name: Display environment info (Unix) - name: Display environment info (Unix)
if: steps.should_build.outputs.should_build == 'true' && matrix.platform != 'win-64' if: steps.should_build.outputs.should_build == 'true' && matrix.platform != 'win-64'
@@ -172,22 +171,22 @@ jobs:
conda env list conda env list
echo "" echo ""
echo "=== Installed Packages ===" echo "=== Installed Packages ==="
conda list | grep -E "(unilabos|ros-humble-unilabos-msgs)" || conda list conda list -n unilab | grep -E "(unilabos|ros-humble-unilabos-msgs)" || conda list -n unilab
echo "" echo ""
echo "=== Python Packages ===" echo "=== Python Packages ==="
pip list | grep unilabos || pip list conda run -n unilab pip list | grep unilabos || conda run -n unilab pip list
- name: Verify environment integrity (Windows) - name: Verify environment integrity (Windows)
if: steps.should_build.outputs.should_build == 'true' && matrix.platform == 'win-64' if: steps.should_build.outputs.should_build == 'true' && matrix.platform == 'win-64'
run: | run: |
echo Verifying Python version... echo Verifying Python version...
python -c "import sys; print(f'Python version: {sys.version}')" conda run -n unilab python -c "import sys; print(f'Python version: {sys.version}')"
echo Verifying unilabos import... echo Verifying unilabos import...
python -c "import unilabos; print(f'UniLabOS version: {unilabos.__version__}')" || echo Warning: Could not import unilabos conda run -n unilab python -c "import unilabos; print(f'UniLabOS version: {unilabos.__version__}')" || echo Warning: Could not import unilabos
echo Checking critical packages... echo Checking critical packages...
python -c "import rclpy; print('ROS2 rclpy: OK')" conda run -n unilab python -c "import rclpy; print('ROS2 rclpy: OK')"
echo Running comprehensive verification script... echo Running comprehensive verification script with auto-install...
python scripts\verify_installation.py || echo Warning: Verification script reported issues conda run -n unilab python scripts\verify_installation.py --auto-install || echo Warning: Verification script reported issues
echo Environment verification complete! echo Environment verification complete!
- name: Verify environment integrity (Unix) - name: Verify environment integrity (Unix)
@@ -195,13 +194,13 @@ jobs:
shell: bash shell: bash
run: | run: |
echo "Verifying Python version..." echo "Verifying Python version..."
python -c "import sys; print(f'Python version: {sys.version}')" conda run -n unilab python -c "import sys; print(f'Python version: {sys.version}')"
echo "Verifying unilabos import..." echo "Verifying unilabos import..."
python -c "import unilabos; print(f'UniLabOS version: {unilabos.__version__}')" || echo "Warning: Could not import unilabos" conda run -n unilab python -c "import unilabos; print(f'UniLabOS version: {unilabos.__version__}')" || echo "Warning: Could not import unilabos"
echo "Checking critical packages..." echo "Checking critical packages..."
python -c "import rclpy; print('ROS2 rclpy: OK')" conda run -n unilab python -c "import rclpy; print('ROS2 rclpy: OK')"
echo "Running comprehensive verification script..." echo "Running comprehensive verification script with auto-install..."
python scripts/verify_installation.py || echo "Warning: Verification script reported issues" conda run -n unilab python scripts/verify_installation.py --auto-install || echo "Warning: Verification script reported issues"
echo "Environment verification complete!" echo "Environment verification complete!"
- name: Pack conda environment (Windows) - name: Pack conda environment (Windows)

View File

@@ -8,7 +8,10 @@ This script verifies that UniLabOS and its dependencies are correctly installed.
Run this script after installing the conda-pack environment to ensure everything works. Run this script after installing the conda-pack environment to ensure everything works.
Usage: Usage:
python verify_installation.py python verify_installation.py [--auto-install]
Options:
--auto-install Automatically install missing packages
Or in the conda environment: Or in the conda environment:
conda activate unilab conda activate unilab
@@ -17,14 +20,15 @@ Usage:
import sys import sys
import os import os
import argparse
# IMPORTANT: Set UTF-8 encoding BEFORE any other imports # IMPORTANT: Set UTF-8 encoding BEFORE any other imports
# This ensures all subsequent imports (including unilabos) can output UTF-8 characters # This ensures all subsequent imports (including unilabos) can output UTF-8 characters
if sys.platform == "win32": if sys.platform == "win32":
# Method 1: Reconfigure stdout/stderr to use UTF-8 with error handling # Method 1: Reconfigure stdout/stderr to use UTF-8 with error handling
try: try:
sys.stdout.reconfigure(encoding="utf-8", errors="replace") sys.stdout.reconfigure(encoding="utf-8", errors="replace") # type: ignore
sys.stderr.reconfigure(encoding="utf-8", errors="replace") sys.stderr.reconfigure(encoding="utf-8", errors="replace") # type: ignore
except (AttributeError, OSError): except (AttributeError, OSError):
pass pass
@@ -49,7 +53,7 @@ CHECK_MARK = "[OK]"
CROSS_MARK = "[FAIL]" CROSS_MARK = "[FAIL]"
def check_package(package_name: str, display_name: str = None) -> bool: def check_package(package_name: str, display_name: str | None = None) -> bool:
""" """
Check if a package can be imported. Check if a package can be imported.
@@ -87,9 +91,25 @@ def check_python_version() -> bool:
def main(): def main():
"""Run all verification checks.""" """Run all verification checks."""
# Parse command line arguments
parser = argparse.ArgumentParser(
description="Verify UniLabOS installation",
formatter_class=argparse.RawDescriptionHelpFormatter,
)
parser.add_argument(
"--auto-install",
action="store_true",
help="Automatically install missing packages",
)
args = parser.parse_args()
print("=" * 60) print("=" * 60)
print("UniLabOS Installation Verification") print("UniLabOS Installation Verification")
print("=" * 60) print("=" * 60)
if args.auto_install:
print("Mode: Auto-install missing packages")
else:
print("Mode: Verification only")
print() print()
all_passed = True all_passed = True
@@ -113,14 +133,16 @@ def main():
print(f" {CHECK_MARK} UniLabOS installed") print(f" {CHECK_MARK} UniLabOS installed")
# Check environment without auto-install (verification only) # Check environment with optional auto-install
# Set show_details=False to suppress detailed Chinese output that may cause encoding issues # Set show_details=False to suppress detailed Chinese output that may cause encoding issues
env_check_passed = check_environment(auto_install=False, show_details=False) env_check_passed = check_environment(auto_install=args.auto_install, show_details=False)
if env_check_passed: if env_check_passed:
print(f" {CHECK_MARK} All required packages available") print(f" {CHECK_MARK} All required packages available")
else: else:
print(f" {CROSS_MARK} Some optional packages are missing") print(f" {CROSS_MARK} Some optional packages are missing")
if not args.auto_install:
print(" Hint: Run with --auto-install to automatically install missing packages")
except ImportError: except ImportError:
print(f" {CROSS_MARK} UniLabOS not installed") print(f" {CROSS_MARK} UniLabOS not installed")
all_passed = False all_passed = False

View File

@@ -11,18 +11,14 @@ from typing import Dict, Any, List
import networkx as nx import networkx as nx
import yaml import yaml
from unilabos.ros.nodes.resource_tracker import ResourceTreeSet, ResourceDict
# 首先添加项目根目录到路径 # 首先添加项目根目录到路径
current_dir = os.path.dirname(os.path.abspath(__file__)) current_dir = os.path.dirname(os.path.abspath(__file__))
unilabos_dir = os.path.dirname(os.path.dirname(current_dir)) unilabos_dir = os.path.dirname(os.path.dirname(current_dir))
if unilabos_dir not in sys.path: if unilabos_dir not in sys.path:
sys.path.append(unilabos_dir) sys.path.append(unilabos_dir)
from unilabos.config.config import load_config, BasicConfig, HTTPConfig
from unilabos.utils.banner_print import print_status, print_unilab_banner from unilabos.utils.banner_print import print_status, print_unilab_banner
from unilabos.resources.graphio import modify_to_backend_format from unilabos.config.config import load_config, BasicConfig, HTTPConfig
def load_config_from_file(config_path): def load_config_from_file(config_path):
if config_path is None: if config_path is None:
@@ -268,6 +264,8 @@ def main():
from unilabos.app.web import http_client from unilabos.app.web import http_client
from unilabos.app.web import start_server from unilabos.app.web import start_server
from unilabos.app.register import register_devices_and_resources from unilabos.app.register import register_devices_and_resources
from unilabos.resources.graphio import modify_to_backend_format
from unilabos.ros.nodes.resource_tracker import ResourceTreeSet, ResourceDict
# 显示启动横幅 # 显示启动横幅
print_unilab_banner(args_dict) print_unilab_banner(args_dict)