Merge pull request #876 from yan-xiaoo/publish-improve-dev

改进 macOS 下的部分打包流程
This commit is contained in:
Naibo Wang
2025-07-21 00:54:35 +08:00
committed by GitHub
3 changed files with 43 additions and 18 deletions
+5
View File
@@ -8,6 +8,11 @@ rm -rf out
rm -r ../.temp_to_pub/EasySpider_MacOS/EasySpider.app
npm run make
unzip out/make/zip/darwin/*64/EasySpider-darwin* -d ../.temp_to_pub/EasySpider_MacOS/
# 使用 adhoc 签名
# 这样程序在 macOS 就会显示为“无法验证开发者,你应将其移动到废纸篓”而不是“此应用已损坏,无法打开”了。
# 这样软件就可以直接在设置-隐私与安全性中批准打开,而不需要 `xattr -d` 强行清除属性
# 这不是一个真正的签名,只是一个空签名,不能让软件通过门禁认证。
codesign --force --deep --sign - ../.temp_to_pub/EasySpider_MacOS/EasySpider.app
# mv out/EasySpider-darwin-*64/EasySpider.app ../.temp_to_pub/EasySpider_MacOS/
rm ../.temp_to_pub/EasySpider_MacOS/EasySpider.app/Contents/Resources/app/VS_BuildTools.exe
rm -r ../.temp_to_pub/EasySpider_MacOS/EasySpider.app/Contents/Resources/app/chrome_win64
+32 -17
View File
@@ -59,6 +59,15 @@ def get_chrome_version():
return version_re.findall(_v)[0][:3]
except WindowsError as e:
print("check Chrome failed:{}".format(e))
elif sys.platform == 'darwin':
# 通过读取 /Applications/Google Chrome.app/Contents/Frameworks/Google Chrome Framework.framework/Versions/Current 这一符号连接指向的文件夹的名称,获得 Chrome 版本号
try:
full_version = os.path.basename(os.path.abspath(os.readlink("/Applications/Google Chrome.app/Contents/Frameworks/Google "
"Chrome Framework.framework/Versions/Current")))
return full_version.split(".")[0]
# 如果找不到 Chrome 程序或者获取错误,回退到默认的 131 版本
except (OSError, IndexError):
return version
else:
return version
@@ -92,23 +101,29 @@ old_driver_version = {
if __name__ == "__main__":
os.system("npm install -g extract-stealth-evasions") # 安装stealth.min.js
os.system("npx extract-stealth-evasions") # 提取stealth.min.js
# chromedriver 在 chrome 114 版本之后,提供了一个新的 API 来获取已知的 Chrome 版本和下载链接
# 之前的版本需要手动维护下载链接
# 现在可以通过访问 https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json
# 来获取最新的 Chrome 版本和下载链接
driver_downloads = []
response = requests.get(chrome_driver_url)
if response.status_code == 200:
versions = json.loads(response.content)["versions"]
versions = versions[::-1] # 倒序排列数组
for info in versions:
version = info["version"].split(".")[0]
if version.find(chrome_version) == 0:
downloads = info["downloads"]
if "chromedriver" in downloads:
print(info["version"])
driver_downloads = downloads["chromedriver"]
break
if int(chrome_version.split(".")[0]) >= 114:
response = requests.get(chrome_driver_url)
if response.status_code == 200:
versions = json.loads(response.content)["versions"]
versions = versions[::-1] # 倒序排列数组
for info in versions:
version = info["version"].split(".")[0]
if version.find(chrome_version) == 0:
downloads = info["downloads"]
if "chromedriver" in downloads:
print(info["version"])
driver_downloads = downloads["chromedriver"]
break
else:
print("Error: ", response.status_code)
exit(1)
else:
print("Error: " + response.status_code)
exit(1)
if not driver_downloads and int(chrome_version) < 115:
if chrome_version not in old_driver_version:
print("没有可用的chromedriver")
exit(1)
@@ -249,7 +264,7 @@ if __name__ == "__main__":
finally:
shutil.rmtree("./chromedrivers")
os.chmod("./chromedriver_mac64", 0o755)
os.chmod("./chrome_mac64.app", 0o555)
os.chmod("./chrome_mac64.app/Contents/MacOS/Google Chrome", 0o555)
os.chmod("./chrome_mac64.app", 0o755)
os.chmod("./chrome_mac64.app/Contents/MacOS/Google Chrome", 0o755)
print("Done and don't forget to generate executestage EXEcutable program!")
+6 -1
View File
@@ -12,6 +12,11 @@ echo "With ddddocr and pandas"
# # 打包带ddddocr和pandas的版本
rm -r build
rm -r dist
pyinstaller -F --icon=favicon.ico --add-data "/Users/naibo/anaconda3/lib/python3.11/site-packages/onnxruntime/capi/onnxruntime_pybind11_state.so:onnxruntime/capi" --add-data "/Users/naibo/anaconda3/lib/python3.11/site-packages/ddddocr/common_old.onnx:ddddocr" easyspider_executestage.py
# Get the site-packages path for ddddocr and onnxruntime
# 如果当前终端激活了 conda 环境,下方脚本应当可以正确的从 conda 环境安装的包中获得数据文件位置
ddddocr_path=$(python3 -c "import ddddocr; print(ddddocr.__path__[0])")
onnxruntime_path=$(python3 -c "import onnxruntime; print(onnxruntime.__path__[0])")
pyinstaller -F --icon=favicon.ico --add-data "$onnxruntime_path/capi/onnxruntime_pybind11_state.so:onnxruntime/capi" --add-data "$ddddocr_path/common_old.onnx:ddddocr" easyspider_executestage.py
rm ../.temp_to_pub/EasySpider_MacOS/easyspider_executestage_full
cp dist/easyspider_executestage ../.temp_to_pub/EasySpider_MacOS/easyspider_executestage_full