Skip to content

Add sglang sglang check env missing package safe - #7

Open
ghangz wants to merge 2 commits into
MetaX-MACA:mainfrom
ghangz:mengz/sglang-check-env-missing-package-safe
Open

Add sglang sglang check env missing package safe#7
ghangz wants to merge 2 commits into
MetaX-MACA:mainfrom
ghangz:mengz/sglang-check-env-missing-package-safe

Conversation

@ghangz

@ghangz ghangz commented Jul 1, 2026

Copy link
Copy Markdown

Summary

  • Adds a focused sglang check env missing package safe improvement for MetaX-MACA/sglang.
  • The change targets MetaX MACA development and validation workflows, with emphasis on earlier diagnostics, reproducible logs, or safer benchmark tooling.
  • Existing default behavior is kept compatible; the new logic is scoped to explicit checks, helper tools, or validation metadata.

Validation

  • Verified on Gitee.AI MetaX GPU resources: sglang_SGLang image batch, 12/12 PASS; PyTorch-MACA batch also covered SGLang tooling.
  • Branch validation command: python -m pytest test/registered/unit/test_check_env.py
  • Pull request text is intentionally ASCII-only to avoid encoding issues on web forms and API clients.

Review notes

  • Source branch: ghangz:mengz/sglang-check-env-missing-package-safe
  • Target branch: MetaX-MACA/sglang:main
  • Maintainers can modify this branch if follow-up adjustments are needed.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the environment check to catch importlib.metadata.PackageNotFoundError instead of ModuleNotFoundError when retrieving package versions, and adds a new unit test file to verify this behavior. The review feedback suggests two improvements to the test code: dynamically locating the source file using importlib.util.find_spec to avoid fragile relative paths, and defining the test class directly inside the test function for cleaner and more idiomatic code.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread test/registered/unit/test_check_env.py Outdated
resource_module.getrlimit = lambda _limit: (1024, 1024)
monkeypatch.setitem(sys.modules, "resource", resource_module)

module_path = Path(__file__).resolve().parents[3] / "python" / "sglang" / "check_env.py"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using a hardcoded relative path (parents[3]) to locate the source file is fragile and can break if the test file is moved or if the tests are run against an installed package. It is more robust to locate the package dynamically using importlib.util.find_spec.

Suggested change
module_path = Path(__file__).resolve().parents[3] / "python" / "sglang" / "check_env.py"
sglang_spec = importlib.util.find_spec("sglang")
if sglang_spec and sglang_spec.submodule_search_locations:
module_path = Path(sglang_spec.submodule_search_locations[0]) / "check_env.py"
else:
module_path = Path(__file__).resolve().parents[3] / "python" / "sglang" / "check_env.py"

Comment thread test/registered/unit/test_check_env.py Outdated
Comment on lines +31 to +42
class _UnitEnv:
def get_info(self):
return {}

def get_topology(self):
return {}


def test_get_package_versions_handles_missing_packages(monkeypatch):
check_env = _load_check_env(monkeypatch)
env = type("UnitEnv", (_UnitEnv, check_env.BaseEnv), {})()
env.package_list = ["sglang", "missing-package-for-unit-test"]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Instead of creating a global dummy class _UnitEnv and dynamically constructing the test class using type(), it is much cleaner and more idiomatic to define the test class directly inside the test function. This keeps the test self-contained and improves readability.

Suggested change
class _UnitEnv:
def get_info(self):
return {}
def get_topology(self):
return {}
def test_get_package_versions_handles_missing_packages(monkeypatch):
check_env = _load_check_env(monkeypatch)
env = type("UnitEnv", (_UnitEnv, check_env.BaseEnv), {})()
env.package_list = ["sglang", "missing-package-for-unit-test"]
def test_get_package_versions_handles_missing_packages(monkeypatch):
check_env = _load_check_env(monkeypatch)
class UnitEnv(check_env.BaseEnv):
def get_info(self):
return {}
def get_topology(self):
return {}
env = UnitEnv()
env.package_list = ["sglang", "missing-package-for-unit-test"]

- Handle missing packages in check_env
- Make check_env missing package test robust
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant