@@ -32,9 +32,9 @@ def mock_engine_libraries():
3232 vllm_mock .__file__ = "mock_vllm.py"
3333
3434 # Create mock mlx module with core submodule
35-
35+
3636 mlx_mock = ModuleType ('mlx' )
37- mlx_mock .__version__ = "0.1 .0"
37+ mlx_mock .__version__ = "1.0 .0"
3838 mlx_mock .__spec__ = ModuleSpec ('mlx' , None )
3939 mlx_mock .__file__ = "mock_mlx.py"
4040
@@ -56,25 +56,57 @@ def mock_engine_libraries():
5656 sglang_mock .__version__ = "0.3.0"
5757 sglang_mock .__spec__ = ModuleSpec ('sglang' , None )
5858 sglang_mock .__file__ = "mock_sglang.py"
59-
59+
60+ # Create mock xllamacpp module with proper module spec for importlib.util.find_spec
61+ import importlib .util
62+ import importlib .machinery
63+
64+ xllamacpp_mock = ModuleType ('xllamacpp' )
65+ xllamacpp_mock .__version__ = "1.0.0"
66+
67+ # Create a proper ModuleSpec that importlib.util.find_spec can find
68+ xllamacpp_spec = importlib .machinery .ModuleSpec ('xllamacpp' , None )
69+ xllamacpp_spec .origin = "mock_xllamacpp.py"
70+ xllamacpp_mock .__spec__ = xllamacpp_spec
71+ xllamacpp_mock .__file__ = "mock_xllamacpp.py"
72+
73+ # Create mock mlx_lm module
74+ mlx_lm_mock = ModuleType ('mlx_lm' )
75+ mlx_lm_mock .__version__ = "1.0.0"
76+ mlx_lm_mock .__spec__ = ModuleSpec ('mlx_lm' , None )
77+ mlx_lm_mock .__file__ = "mock_mlx_lm.py"
78+
79+ # Create mock mlx_vlm module
80+ mlx_vlm_mock = ModuleType ('mlx_vlm' )
81+ mlx_vlm_mock .__version__ = "1.0.0"
82+ mlx_vlm_mock .__spec__ = ModuleSpec ('mlx_vlm' , None )
83+ mlx_vlm_mock .__file__ = "mock_mlx_vlm.py"
84+
6085 # Mock these modules in sys.modules
6186 sys .modules ['vllm' ] = vllm_mock
6287 sys .modules ['mlx' ] = mlx_mock
6388 sys .modules ['mlx.core' ] = mlx_core_mock
6489 sys .modules ['lmdeploy' ] = lmdeploy_mock
6590 sys .modules ['sglang' ] = sglang_mock
91+ sys .modules ['xllamacpp' ] = xllamacpp_mock
92+ sys .modules ['mlx_lm' ] = mlx_lm_mock
93+ sys .modules ['mlx_vlm' ] = mlx_vlm_mock
6694
6795# Apply mocking before importing xinference modules
6896mock_engine_libraries ()
6997
70- from xinference .model .llm .llm_family import SUPPORTED_ENGINES , check_engine_by_spec_parameters
71- from xinference .model .llm .vllm .core import VLLM_INSTALLED , VLLM_SUPPORTED_MODELS , VLLM_SUPPORTED_CHAT_MODELS
72-
73- # Additional mocking for platform/hardware checks in documentation generation
98+ # Mock platform checks BEFORE importing xinference modules
7499def mock_platform_checks ():
75100 """Mock platform and hardware checks for documentation generation"""
76101 from unittest .mock import patch
77-
102+ import sys
103+ import platform
104+
105+ # Mock platform system for MLX (make it appear as Apple Silicon)
106+ sys .platform = "darwin"
107+ platform .system = lambda : "Darwin"
108+ platform .processor = lambda : "arm"
109+
78110 # Mock vLLM platform checks
79111 import xinference .model .llm .vllm .core as vllm_core
80112 vllm_core .VLLMModel ._is_linux = lambda : True
@@ -83,7 +115,7 @@ def mock_platform_checks():
83115 vllm_core .VLLMChatModel ._has_cuda_device = lambda : True
84116 vllm_core .VLLMMultiModel ._is_linux = lambda : True
85117 vllm_core .VLLMMultiModel ._has_cuda_device = lambda : True
86-
118+
87119 # Mock SGLang platform checks if available
88120 try :
89121 import xinference .model .llm .sglang .core as sglang_core
@@ -95,7 +127,7 @@ def mock_platform_checks():
95127 sglang_core .SGLANGVisionModel ._has_cuda_device = lambda : True
96128 except ImportError :
97129 pass
98-
130+
99131 # Mock LMDEPLOY platform checks if available
100132 try :
101133 import xinference .model .llm .lmdeploy .core as lmdeploy_core
@@ -108,6 +140,11 @@ def mock_platform_checks():
108140
109141mock_platform_checks ()
110142
143+ from xinference .model .llm .llm_family import SUPPORTED_ENGINES , check_engine_by_spec_parameters
144+ from xinference .model .llm .vllm .core import VLLM_INSTALLED , VLLM_SUPPORTED_MODELS , VLLM_SUPPORTED_CHAT_MODELS
145+
146+ # Mock platform checks again after imports to ensure they stick
147+
111148# Re-register engines with mocked platform checks
112149from xinference .model .llm import generate_engine_config_by_model_family
113150from xinference .model .llm .llm_family import BUILTIN_LLM_FAMILIES , LLM_ENGINES
0 commit comments