Skip to content

Commit

Permalink
自动安装依赖,自动获取系统代理
Browse files Browse the repository at this point in the history
  • Loading branch information
aidenli committed Sep 2, 2024
1 parent 108c6d1 commit 68f5fed
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
29 changes: 29 additions & 0 deletions __init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,32 @@
import importlib.util
import subprocess
import os
import re


def install_package(full_name, package_name):
try:
spec = importlib.util.find_spec(package_name)
if spec is None:
raise ImportError(f"{package_name} 未安装")
except ImportError:
print(f"{package_name} 未安装,正在安装...")
subprocess.check_call(["python", "-m", "pip", "install", full_name])
print(f"{package_name} 安装完成。")


def check_and_install_packages():
packages = ["pygtrans"]
for package in packages:
package_name = re.match(r"^([^\s=<>!]+)", package.strip())
if package_name:
install_package(package, package_name.group(1))


# 检查 requirements.txt 文件中的包
check_and_install_packages()


from .nodes.Translate import TranslateNode
from .nodes.JoyTag.JoyTag import JoyTagNode
from .nodes.JoyCaption.JoyCaption import JoyCaptionNode
Expand Down
24 changes: 24 additions & 0 deletions nodes/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,25 @@
import json
from inspect import currentframe, stack, getmodule
import time
import winreg


# 获取系统代理地址
def get_system_proxy():
try:
internet_settings = winreg.OpenKey(
winreg.HKEY_CURRENT_USER,
r"Software\Microsoft\Windows\CurrentVersion\Internet Settings",
)
proxy_server, _ = winreg.QueryValueEx(internet_settings, "ProxyServer")
proxy_enable, _ = winreg.QueryValueEx(internet_settings, "ProxyEnable")
if proxy_enable:
return proxy_server
else:
return None
except FileNotFoundError:
return None


config_template = {
"Baidu": {"AppId": "", "Secret": ""},
Expand Down Expand Up @@ -42,6 +61,11 @@ def LoadConfig():
# 合并最新的配置项(当config_template有变动的时候)
config_data = merge_config(config_data, config_template)

# 获取系统代理地址,并修改配置文件
proxy = get_system_proxy()
if proxy:
config_data["Google"]["proxy"] = proxy

with open(config_path, "w") as f:
f.write(json.dumps(config_data, indent=4))

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ torch
torchvision>=0.15.2
einops>=0.7.0
safetensors>=0.4.1
pillow>=9.4.0
Pillow>=9.4.0
huggingface_hub>=0.23.5
accelerate
transformers>=4.43.3
Expand Down

0 comments on commit 68f5fed

Please sign in to comment.