优化更新脚本的处理逻辑

This commit is contained in:
杍超
2025-01-22 14:48:42 +08:00
parent 933922334e
commit 4b5968acd4

View File

@@ -25,7 +25,7 @@ def install_wheel(whl_file, force_reinstall=True):
subprocess.run(['pip', 'install', whl_file]) subprocess.run(['pip', 'install', whl_file])
print(f"Installation of {whl_file} successful.") print(f"Installation of {whl_file} successful.")
def main(force_reinstall): def main():
# 获取当前脚本所在的目录 # 获取当前脚本所在的目录
script_dir = os.path.dirname(os.path.abspath(__file__)) script_dir = os.path.dirname(os.path.abspath(__file__))
@@ -35,7 +35,11 @@ def main(force_reinstall):
# 查找 dist 目录下的 .whl 文件 # 查找 dist 目录下的 .whl 文件
whl_files = glob.glob('dist/*.whl') whl_files = glob.glob('dist/*.whl')
if not check_node_installed() or whl_files is None or len(whl_files) == 0: # 有node 且没有whl文件时执行gradio cc install和gradio cc build
if (whl_files is None or len(whl_files)) == 0:
if not check_node_installed():
print ("need to build .whl, but nodejs not installed")
return
# 移除 gradio_webrtc 包 # 移除 gradio_webrtc 包
subprocess.run(['pip', 'uninstall', '-y', 'gradio_webrtc']) subprocess.run(['pip', 'uninstall', '-y', 'gradio_webrtc'])
@@ -49,17 +53,18 @@ def main(force_reinstall):
# 执行 gradio cc build --no-generate-docs # 执行 gradio cc build --no-generate-docs
subprocess.run(['gradio', 'cc', 'build', '--no-generate-docs']) subprocess.run(['gradio', 'cc', 'build', '--no-generate-docs'])
# 查找 dist 目录下的 .whl 文件
whl_files = glob.glob('dist/*.whl')
if whl_files: if whl_files:
whl_file = whl_files[0] whl_file = whl_files[0]
# 安装 .whl 文件 # 安装 .whl 文件
install_wheel(whl_file, force_reinstall) install_wheel(whl_file, True)
else: else:
print("没有找到 .whl 文件") print("没有找到 .whl 文件")
if __name__ == "__main__": if __name__ == "__main__":
# 解析命令行参数 # 解析命令行参数
parser = argparse.ArgumentParser(description="Update and install gradio-webrtc package.") parser = argparse.ArgumentParser(description="Update and install gradio-webrtc package.")
parser.add_argument('--force-reinstall', action='store_true', help='Force reinstall the .whl file')
args = parser.parse_args() args = parser.parse_args()
main(args.force_reinstall) main()