diff --git a/.github/workflows/pr-test-rust.yml b/.github/workflows/pr-test-rust.yml index 8a70f415e..ddd10339e 100644 --- a/.github/workflows/pr-test-rust.yml +++ b/.github/workflows/pr-test-rust.yml @@ -191,10 +191,10 @@ jobs: - name: Run Python unit tests run: | - cd sgl-model-gateway + cd sgl-model-gateway/bindings/python source "$HOME/.cargo/env" python3 -m pip install pytest pytest-cov pytest-xdist - pytest -q py_test/unit --cov=sglang_router --cov-config=bindings/python/.coveragerc --cov-report=term-missing --cov-fail-under=80 + pytest -q tests --cov=sglang_router --cov-config=.coveragerc --cov-report=term-missing --cov-fail-under=80 - name: Run Python integration tests run: | diff --git a/.github/workflows/release-docker-gateway.yml b/.github/workflows/release-docker-gateway.yml index 9f0b64614..3b5e5a68f 100644 --- a/.github/workflows/release-docker-gateway.yml +++ b/.github/workflows/release-docker-gateway.yml @@ -29,7 +29,7 @@ jobs: - name: Build and Push run: | - version=$(cat sgl-model-gateway/bindings/python/sglang_router/version.py | cut -d'"' -f2) + version=$(cat sgl-model-gateway/bindings/python/src/sglang_router/version.py | cut -d'"' -f2) tag=v${version} docker buildx build . -f docker/gateway.Dockerfile \ diff --git a/sgl-model-gateway/bindings/python/README.md b/sgl-model-gateway/bindings/python/README.md index 67f9e4e77..5f913e241 100644 --- a/sgl-model-gateway/bindings/python/README.md +++ b/sgl-model-gateway/bindings/python/README.md @@ -6,16 +6,22 @@ This directory contains the Python bindings for the SGLang Router, built using [ ``` bindings/python/ -├── src/ # Rust source code for Python bindings -│ └── lib.rs # PyO3 bindings implementation -├── sglang_router/ # Python source code -│ ├── __init__.py -│ ├── version.py -│ ├── launch_server.py -│ ├── launch_router.py -│ ├── router.py -│ ├── router_args.py -│ └── mini_lb.py +├── src/ # Source code (src layout) +│ ├── lib.rs # Rust/PyO3 bindings implementation +│ └── sglang_router/ # Python source code +│ ├── __init__.py +│ ├── version.py +│ ├── launch_server.py +│ ├── launch_router.py +│ ├── router.py +│ ├── router_args.py +│ └── mini_lb.py +├── tests/ # Python unit tests +│ ├── conftest.py +│ ├── test_validation.py +│ ├── test_arg_parser.py +│ ├── test_router_config.py +│ └── test_startup_sequence.py ├── Cargo.toml # Rust package configuration for bindings ├── pyproject.toml # Python package configuration ├── setup.py # Setup configuration @@ -51,15 +57,15 @@ pip install dist/sglang_router-*.whl ## Testing ```bash -# Run Python tests -cd sgl-model-gateway -pytest py_test/ +# Run Python unit tests (after maturin develop) +cd sgl-model-gateway/bindings/python +pytest tests/ ``` ## Configuration - **pyproject.toml**: Defines package metadata, dependencies, and build configuration -- **python-source**: Set to "." to indicate Python source is in the same directory as pyproject.toml +- **python-source**: Set to `"src"` indicating Python source uses the src layout - **module-name**: `sglang_router.sglang_router_rs` - the Rust extension module name ## Notes diff --git a/sgl-model-gateway/bindings/python/pyproject.toml b/sgl-model-gateway/bindings/python/pyproject.toml index 918bd4175..e817986f4 100644 --- a/sgl-model-gateway/bindings/python/pyproject.toml +++ b/sgl-model-gateway/bindings/python/pyproject.toml @@ -39,6 +39,7 @@ dependencies = [ [project.optional-dependencies] dev = [ "requests>=2.25.0", + "pytest>=7.0.0", ] [project.scripts] @@ -48,7 +49,16 @@ sglang-router = "sglang_router.cli:main" [tool.maturin] -python-source = "." +python-source = "src" module-name = "sglang_router.sglang_router_rs" # Exclude bindings/python/README.md to use root README only exclude = ["README.md"] + +[tool.pytest.ini_options] +testpaths = ["tests"] +python_files = ["test_*.py"] +python_classes = ["Test*"] +python_functions = ["test_*"] +markers = [ + "unit: mark test as a unit test (no GPU required)", +] diff --git a/sgl-model-gateway/bindings/python/sglang_router/__init__.py b/sgl-model-gateway/bindings/python/src/sglang_router/__init__.py similarity index 100% rename from sgl-model-gateway/bindings/python/sglang_router/__init__.py rename to sgl-model-gateway/bindings/python/src/sglang_router/__init__.py diff --git a/sgl-model-gateway/bindings/python/sglang_router/__main__.py b/sgl-model-gateway/bindings/python/src/sglang_router/__main__.py similarity index 100% rename from sgl-model-gateway/bindings/python/sglang_router/__main__.py rename to sgl-model-gateway/bindings/python/src/sglang_router/__main__.py diff --git a/sgl-model-gateway/bindings/python/sglang_router/cli.py b/sgl-model-gateway/bindings/python/src/sglang_router/cli.py similarity index 100% rename from sgl-model-gateway/bindings/python/sglang_router/cli.py rename to sgl-model-gateway/bindings/python/src/sglang_router/cli.py diff --git a/sgl-model-gateway/bindings/python/sglang_router/launch_router.py b/sgl-model-gateway/bindings/python/src/sglang_router/launch_router.py similarity index 100% rename from sgl-model-gateway/bindings/python/sglang_router/launch_router.py rename to sgl-model-gateway/bindings/python/src/sglang_router/launch_router.py diff --git a/sgl-model-gateway/bindings/python/sglang_router/launch_server.py b/sgl-model-gateway/bindings/python/src/sglang_router/launch_server.py similarity index 100% rename from sgl-model-gateway/bindings/python/sglang_router/launch_server.py rename to sgl-model-gateway/bindings/python/src/sglang_router/launch_server.py diff --git a/sgl-model-gateway/bindings/python/sglang_router/mini_lb.py b/sgl-model-gateway/bindings/python/src/sglang_router/mini_lb.py similarity index 100% rename from sgl-model-gateway/bindings/python/sglang_router/mini_lb.py rename to sgl-model-gateway/bindings/python/src/sglang_router/mini_lb.py diff --git a/sgl-model-gateway/bindings/python/sglang_router/router.py b/sgl-model-gateway/bindings/python/src/sglang_router/router.py similarity index 100% rename from sgl-model-gateway/bindings/python/sglang_router/router.py rename to sgl-model-gateway/bindings/python/src/sglang_router/router.py diff --git a/sgl-model-gateway/bindings/python/sglang_router/router_args.py b/sgl-model-gateway/bindings/python/src/sglang_router/router_args.py similarity index 100% rename from sgl-model-gateway/bindings/python/sglang_router/router_args.py rename to sgl-model-gateway/bindings/python/src/sglang_router/router_args.py diff --git a/sgl-model-gateway/bindings/python/sglang_router/version.py b/sgl-model-gateway/bindings/python/src/sglang_router/version.py similarity index 100% rename from sgl-model-gateway/bindings/python/sglang_router/version.py rename to sgl-model-gateway/bindings/python/src/sglang_router/version.py diff --git a/sgl-model-gateway/bindings/python/tests/conftest.py b/sgl-model-gateway/bindings/python/tests/conftest.py new file mode 100644 index 000000000..31ceb7140 --- /dev/null +++ b/sgl-model-gateway/bindings/python/tests/conftest.py @@ -0,0 +1,14 @@ +""" +Pytest configuration for sglang_router Python binding tests. + +These are unit tests that run without GPU resources or external dependencies. +""" + +import pytest + + +def pytest_configure(config): + """Configure pytest markers.""" + config.addinivalue_line( + "markers", "unit: mark test as a unit test (no GPU required)" + ) diff --git a/sgl-model-gateway/py_test/unit/test_arg_parser.py b/sgl-model-gateway/bindings/python/tests/test_arg_parser.py similarity index 100% rename from sgl-model-gateway/py_test/unit/test_arg_parser.py rename to sgl-model-gateway/bindings/python/tests/test_arg_parser.py diff --git a/sgl-model-gateway/py_test/unit/test_router_config.py b/sgl-model-gateway/bindings/python/tests/test_router_config.py similarity index 100% rename from sgl-model-gateway/py_test/unit/test_router_config.py rename to sgl-model-gateway/bindings/python/tests/test_router_config.py diff --git a/sgl-model-gateway/py_test/unit/test_startup_sequence.py b/sgl-model-gateway/bindings/python/tests/test_startup_sequence.py similarity index 100% rename from sgl-model-gateway/py_test/unit/test_startup_sequence.py rename to sgl-model-gateway/bindings/python/tests/test_startup_sequence.py diff --git a/sgl-model-gateway/py_test/unit/test_validation.py b/sgl-model-gateway/bindings/python/tests/test_validation.py similarity index 100% rename from sgl-model-gateway/py_test/unit/test_validation.py rename to sgl-model-gateway/bindings/python/tests/test_validation.py