From 79635b539a2d8e0a9a4166d7274ec1144d363521 Mon Sep 17 00:00:00 2001 From: "zhangxu.709" Date: Wed, 3 Dec 2025 15:03:59 +0800 Subject: [PATCH] feat: add function to retrieve Python version and update build paths accordingly. --- setup.py | 7 +++++-- xllm/__init__.py | 9 +++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/setup.py b/setup.py index 7cf2614fc..82cde4001 100644 --- a/setup.py +++ b/setup.py @@ -45,6 +45,9 @@ def get_base_dir(): def join_path(*paths): return os.path.join(get_base_dir(), *paths) +# return the python version as a string like "310" or "311" etc +def get_python_version(): + return f"{sys.version_info.major}{sys.version_info.minor}" def get_version(): # first read from environment variable @@ -398,9 +401,9 @@ def run(self): self.run_command('test') if self.arch == 'arm': - ext_path = get_base_dir() + "/build/lib.linux-aarch64-cpython-311/" + ext_path = get_base_dir() + f"/build/lib.linux-aarch64-cpython-{get_python_version()}/" else: - ext_path = get_base_dir() + "/build/lib.linux-x86_64-cpython-311/" + ext_path = get_base_dir() + f"/build/lib.linux-x86_64-cpython-{get_python_version()}/" if len(ext_path) == 0: print("Build wheel failed, not found path.") exit(1) diff --git a/xllm/__init__.py b/xllm/__init__.py index 7468c7432..ac7f98880 100644 --- a/xllm/__init__.py +++ b/xllm/__init__.py @@ -1,8 +1,13 @@ import importlib.util import os import xllm -install_path_x86 = os.path.dirname(xllm.__file__) + "/xllm_export.cpython-311-x86_64-linux-gnu.so" -install_path_arm = os.path.dirname(xllm.__file__) + "/xllm_export.cpython-311-aarch64-linux-gnu.so" +import sys + +def get_python_version(): + return f"{sys.version_info.major}{sys.version_info.minor}" + +install_path_x86 = os.path.dirname(xllm.__file__) + f"/xllm_export.cpython-{get_python_version()}-x86_64-linux-gnu.so" +install_path_arm = os.path.dirname(xllm.__file__) + f"/xllm_export.cpython-{get_python_version()}-aarch64-linux-gnu.so" if os.path.exists(install_path_x86): install_path = install_path_x86 elif os.path.exists(install_path_arm):