修正了打包的问题

This commit is contained in:
xunbu
2025-05-19 14:19:37 +08:00
parent 2c8c07572e
commit e9f90b11ee
5 changed files with 27 additions and 23 deletions

24
.idea/workspace.xml generated
View File

@@ -5,22 +5,10 @@
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="6b18b44a-df57-4212-a857-9e291ebe5dd2" name="更改" comment=""> <list default="true" id="6b18b44a-df57-4212-a857-9e291ebe5dd2" name="更改" comment="">
<change afterPath="$PROJECT_DIR$/src/docutranslate/app.py" afterDir="false" /> <change afterPath="$PROJECT_DIR$/docutranslate/utils/resource_utils.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/docutranslate/__init__.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/docutranslate/__init__.py" afterDir="false" /> <change beforePath="$PROJECT_DIR$/app.spec" beforeDir="false" afterPath="$PROJECT_DIR$/app.spec" afterDir="false" />
<change beforePath="$PROJECT_DIR$/docutranslate/agents/__init__.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/docutranslate/agents/__init__.py" afterDir="false" /> <change beforePath="$PROJECT_DIR$/docutranslate/app.py" beforeDir="false" afterPath="$PROJECT_DIR$/docutranslate/app.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/docutranslate/agents/agent.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/docutranslate/agents/agent.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/docutranslate/agents/markdown_agent.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/docutranslate/agents/markdown_agent.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/docutranslate/app.py" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/docutranslate/cli.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/docutranslate/cli.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/docutranslate/logger/__init__.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/docutranslate/logger/__init__.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/docutranslate/logger/logger.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/docutranslate/logger/logger.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/docutranslate/translater.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/docutranslate/translater.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/docutranslate/utils/__init__.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/docutranslate/utils/__init__.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/docutranslate/utils/convert.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/docutranslate/utils/convert.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/docutranslate/utils/docling_utils.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/docutranslate/utils/docling_utils.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/docutranslate/utils/markdown_splitter.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/docutranslate/utils/markdown_splitter.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/docutranslate/utils/markdown_utils.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/docutranslate/utils/markdown_utils.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pyproject.toml" beforeDir="false" afterPath="$PROJECT_DIR$/pyproject.toml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/pyproject.toml" beforeDir="false" afterPath="$PROJECT_DIR$/pyproject.toml" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
@@ -31,9 +19,9 @@
<component name="FileTemplateManagerImpl"> <component name="FileTemplateManagerImpl">
<option name="RECENT_TEMPLATES"> <option name="RECENT_TEMPLATES">
<list> <list>
<option value="Python Script" />
<option value="HTML File" /> <option value="HTML File" />
<option value="CSS File" /> <option value="CSS File" />
<option value="Python Script" />
</list> </list>
</option> </option>
</component> </component>
@@ -581,7 +569,7 @@
<workItem from="1747617855241" duration="190000" /> <workItem from="1747617855241" duration="190000" />
<workItem from="1747619759939" duration="205000" /> <workItem from="1747619759939" duration="205000" />
<workItem from="1747624297447" duration="65000" /> <workItem from="1747624297447" duration="65000" />
<workItem from="1747628254543" duration="4111000" /> <workItem from="1747628254543" duration="7231000" />
</task> </task>
<servers /> <servers />
</component> </component>
@@ -589,7 +577,7 @@
<option name="version" value="3" /> <option name="version" value="3" />
</component> </component>
<component name="com.intellij.coverage.CoverageDataManagerImpl"> <component name="com.intellij.coverage.CoverageDataManagerImpl">
<SUITE FILE_PATH="coverage/filetranslate$app_test__1_.coverage" NAME="app_test (1) 覆盖结果" MODIFIED="1747631847708" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/tests" /> <SUITE FILE_PATH="coverage/filetranslate$app_test__1_.coverage" NAME="app_test (1) 覆盖结果" MODIFIED="1747634037187" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/tests" />
<SUITE FILE_PATH="coverage/filetranslate$test.coverage" NAME="test 覆盖结果" MODIFIED="1747472297913" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/tests" /> <SUITE FILE_PATH="coverage/filetranslate$test.coverage" NAME="test 覆盖结果" MODIFIED="1747472297913" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/tests" />
<SUITE FILE_PATH="coverage/filetranslate$convert.coverage" NAME="convert 覆盖结果" MODIFIED="1746963490689" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/docutranslate/utils" /> <SUITE FILE_PATH="coverage/filetranslate$convert.coverage" NAME="convert 覆盖结果" MODIFIED="1746963490689" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/docutranslate/utils" />
<SUITE FILE_PATH="coverage/PDFtranslate$PDFtranslater__1_.coverage" NAME="PDFtranslater (1) 覆盖结果" MODIFIED="1746633258205" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/pdftranslate_packages" /> <SUITE FILE_PATH="coverage/PDFtranslate$PDFtranslater__1_.coverage" NAME="PDFtranslater (1) 覆盖结果" MODIFIED="1746633258205" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/pdftranslate_packages" />

View File

@@ -1,7 +1,8 @@
# -*- mode: python ; coding: utf-8 -*- # -*- mode: python ; coding: utf-8 -*-
from PyInstaller.utils.hooks import collect_all from PyInstaller.utils.hooks import collect_all
datas = [('C:\\\\Users\\\\jxgm\\\\Desktop\\\\FileTranslate\\\\.venv\\\\Lib\\\\site-packages\\\\docling_parse\\\\pdf_resources_v2', 'docling_parse/pdf_resources_v2')] datas = [('C:/Users/jxgm/Desktop/FileTranslate/.venv/Lib/site-packages/docling_parse/pdf_resources_v2', 'docling_parse/pdf_resources_v2'),
('C:/Users/jxgm\Desktop/FileTranslate/docutranslate/static', 'docutranslate/static')]
binaries = [] binaries = []
hiddenimports = [] hiddenimports = []
tmp_ret = collect_all('easyocr') tmp_ret = collect_all('easyocr')

View File

@@ -13,13 +13,13 @@ from fastapi.templating import Jinja2Templates
from fastapi.staticfiles import StaticFiles from fastapi.staticfiles import StaticFiles
from docutranslate import FileTranslater from docutranslate import FileTranslater
from docutranslate.logger import translater_logger from docutranslate.logger import translater_logger
from docutranslate.utils.resource_utils import resource_path
app = FastAPI() app = FastAPI()
BASE_DIR = Path(__file__).resolve().parent STATIC_DIR=resource_path("static")
STATIC_DIR=BASE_DIR/"static"
# print(f"__file__:{Path(__file__).resolve()}")
app.mount("/static",StaticFiles(directory=STATIC_DIR), name="static") app.mount("/static",StaticFiles(directory=STATIC_DIR), name="static")
# --- 全局配置 --- # --- 全局配置 ---

View File

@@ -0,0 +1,15 @@
import sys
from pathlib import Path
def resource_path(relative_path):
""" 获取资源的绝对路径,适用于开发环境和 PyInstaller 打包后的环境 """
try:
base_path = Path(sys._MEIPASS)/"docutranslate"
except Exception:
base_path = Path(__file__).resolve().parent.parent # 开发时
# 更健壮的开发时路径(如果你的资源相对于项目根目录)
# base_path = Path(os.path.abspath("."))
# 或者,如果你的 static 目录总是和 app.py 在同一级(开发时)
# base_path = Path(__file__).resolve().parent
# print(f"base_path:{base_path}")
return base_path / relative_path

View File

@@ -1,6 +1,6 @@
[project] [project]
name = "docutranslate" name = "docutranslate"
version = "0.2.18" version = "0.2.19"
description = "文件翻译工具" description = "文件翻译工具"
readme = "README.md" readme = "README.md"
requires-python = ">=3.10" requires-python = ">=3.10"