pytexmk 1.2.4__tar.gz → 1.2.6__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pytexmk-1.2.4 → pytexmk-1.2.6}/PKG-INFO +7 -7
- {pytexmk-1.2.4 → pytexmk-1.2.6}/README.md +3 -3
- {pytexmk-1.2.4 → pytexmk-1.2.6}/pyproject.toml +4 -12
- {pytexmk-1.2.4 → pytexmk-1.2.6}/src/pytexmk/cli/__main__.py +13 -1
- {pytexmk-1.2.4 → pytexmk-1.2.6}/src/pytexmk/cli/check_version.py +5 -5
- pytexmk-1.2.6/src/pytexmk/cli/cli_compile.py +202 -0
- pytexmk-1.2.6/src/pytexmk/cli/cli_context.py +202 -0
- pytexmk-1.2.6/src/pytexmk/cli/cli_early.py +79 -0
- pytexmk-1.2.6/src/pytexmk/cli/cli_latexdiff.py +179 -0
- pytexmk-1.2.6/src/pytexmk/cli/cli_state.py +82 -0
- pytexmk-1.2.6/src/pytexmk/cli/cli_workflow.py +45 -0
- {pytexmk-1.2.4 → pytexmk-1.2.6}/src/pytexmk/compile.py +14 -27
- {pytexmk-1.2.4 → pytexmk-1.2.6}/src/pytexmk/compile_engine.py +11 -23
- pytexmk-1.2.6/src/pytexmk/compile_report.py +91 -0
- {pytexmk-1.2.4 → pytexmk-1.2.6}/src/pytexmk/context.py +21 -9
- pytexmk-1.2.6/src/pytexmk/detection.py +775 -0
- {pytexmk-1.2.4 → pytexmk-1.2.6}/src/pytexmk/file_ops.py +43 -39
- {pytexmk-1.2.4 → pytexmk-1.2.6}/src/pytexmk/language.py +83 -7
- {pytexmk-1.2.4 → pytexmk-1.2.6}/src/pytexmk/latexdiff.py +26 -60
- pytexmk-1.2.6/src/pytexmk/lifecycle.py +36 -0
- {pytexmk-1.2.4 → pytexmk-1.2.6}/src/pytexmk/locale/en/LC_MESSAGES/__main__.mo +0 -0
- pytexmk-1.2.6/src/pytexmk/locale/en/LC_MESSAGES/check_version.mo +0 -0
- {pytexmk-1.2.4 → pytexmk-1.2.6}/src/pytexmk/locale/en/LC_MESSAGES/cli_args.mo +0 -0
- pytexmk-1.2.6/src/pytexmk/locale/en/LC_MESSAGES/cli_workflow.mo +0 -0
- {pytexmk-1.2.4 → pytexmk-1.2.6}/src/pytexmk/locale/en/LC_MESSAGES/compile.mo +0 -0
- pytexmk-1.2.6/src/pytexmk/locale/en/LC_MESSAGES/compile_engine.mo +0 -0
- pytexmk-1.2.6/src/pytexmk/locale/en/LC_MESSAGES/compile_report.mo +0 -0
- {pytexmk-1.2.4 → pytexmk-1.2.6}/src/pytexmk/locale/en/LC_MESSAGES/config.mo +0 -0
- {pytexmk-1.2.4 → pytexmk-1.2.6}/src/pytexmk/locale/en/LC_MESSAGES/context.mo +0 -0
- {pytexmk-1.2.4 → pytexmk-1.2.6}/src/pytexmk/locale/en/LC_MESSAGES/detection.mo +0 -0
- {pytexmk-1.2.4 → pytexmk-1.2.6}/src/pytexmk/locale/en/LC_MESSAGES/file_ops.mo +0 -0
- {pytexmk-1.2.4 → pytexmk-1.2.6}/src/pytexmk/locale/en/LC_MESSAGES/latexdiff.mo +0 -0
- pytexmk-1.2.6/src/pytexmk/locale/en/LC_MESSAGES/lifecycle.mo +0 -0
- {pytexmk-1.2.4 → pytexmk-1.2.6}/src/pytexmk/locale/en/LC_MESSAGES/logger_config.mo +0 -0
- {pytexmk-1.2.4 → pytexmk-1.2.6}/src/pytexmk/locale/en/LC_MESSAGES/paths.mo +0 -0
- {pytexmk-1.2.4 → pytexmk-1.2.6}/src/pytexmk/locale/en/LC_MESSAGES/pdf_tools.mo +0 -0
- pytexmk-1.2.6/src/pytexmk/locale/en/LC_MESSAGES/subprocess_runner.mo +0 -0
- {pytexmk-1.2.4 → pytexmk-1.2.6}/src/pytexmk/locale/en/LC_MESSAGES/subproject.mo +0 -0
- pytexmk-1.2.6/src/pytexmk/locale/en/LC_MESSAGES/tex_project.mo +0 -0
- pytexmk-1.2.6/src/pytexmk/locale/en/LC_MESSAGES/timing.mo +0 -0
- pytexmk-1.2.6/src/pytexmk/locale/en/LC_MESSAGES/ui_messages.mo +0 -0
- {pytexmk-1.2.4 → pytexmk-1.2.6}/src/pytexmk/locale/templates/__main__.pot +2 -2
- {pytexmk-1.2.4 → pytexmk-1.2.6}/src/pytexmk/locale/templates/check_version.pot +5 -2
- {pytexmk-1.2.4 → pytexmk-1.2.6}/src/pytexmk/locale/templates/cli_args.pot +2 -2
- {pytexmk-1.2.4 → pytexmk-1.2.6}/src/pytexmk/locale/templates/cli_workflow.pot +82 -83
- {pytexmk-1.2.4 → pytexmk-1.2.6}/src/pytexmk/locale/templates/compile.pot +2 -2
- {pytexmk-1.2.4 → pytexmk-1.2.6}/src/pytexmk/locale/templates/compile_engine.pot +3 -6
- {pytexmk-1.2.4 → pytexmk-1.2.6}/src/pytexmk/locale/templates/compile_report.pot +2 -8
- {pytexmk-1.2.4 → pytexmk-1.2.6}/src/pytexmk/locale/templates/config.pot +2 -2
- pytexmk-1.2.4/src/pytexmk/locale/templates/subprocess_runner.pot → pytexmk-1.2.6/src/pytexmk/locale/templates/context.pot +5 -4
- {pytexmk-1.2.4 → pytexmk-1.2.6}/src/pytexmk/locale/templates/detection.pot +2 -2
- {pytexmk-1.2.4 → pytexmk-1.2.6}/src/pytexmk/locale/templates/file_ops.pot +2 -2
- {pytexmk-1.2.4 → pytexmk-1.2.6}/src/pytexmk/locale/templates/latexdiff.pot +4 -4
- pytexmk-1.2.6/src/pytexmk/locale/templates/lifecycle.pot +34 -0
- {pytexmk-1.2.4 → pytexmk-1.2.6}/src/pytexmk/locale/templates/logger_config.pot +2 -2
- {pytexmk-1.2.4 → pytexmk-1.2.6}/src/pytexmk/locale/templates/paths.pot +2 -2
- {pytexmk-1.2.4 → pytexmk-1.2.6}/src/pytexmk/locale/templates/pdf_tools.pot +2 -2
- pytexmk-1.2.6/src/pytexmk/locale/templates/subprocess_runner.pot +45 -0
- {pytexmk-1.2.4 → pytexmk-1.2.6}/src/pytexmk/locale/templates/subproject.pot +2 -2
- {pytexmk-1.2.4 → pytexmk-1.2.6}/src/pytexmk/locale/templates/tex_project.pot +15 -5
- {pytexmk-1.2.4 → pytexmk-1.2.6}/src/pytexmk/locale/templates/timing.pot +2 -5
- {pytexmk-1.2.4 → pytexmk-1.2.6}/src/pytexmk/locale/templates/ui_messages.pot +2 -5
- {pytexmk-1.2.4 → pytexmk-1.2.6}/src/pytexmk/logger_config.py +2 -1
- pytexmk-1.2.6/src/pytexmk/subprocess_runner.py +222 -0
- {pytexmk-1.2.4 → pytexmk-1.2.6}/src/pytexmk/subproject_scanner.py +0 -1
- {pytexmk-1.2.4 → pytexmk-1.2.6}/src/pytexmk/tex_project.py +58 -97
- pytexmk-1.2.6/src/pytexmk/timing.py +146 -0
- {pytexmk-1.2.4 → pytexmk-1.2.6}/src/pytexmk/ui_messages.py +25 -31
- {pytexmk-1.2.4 → pytexmk-1.2.6}/src/pytexmk/version.py +3 -4
- {pytexmk-1.2.4 → pytexmk-1.2.6}/src/pytexmk.egg-info/PKG-INFO +7 -7
- {pytexmk-1.2.4 → pytexmk-1.2.6}/src/pytexmk.egg-info/SOURCES.txt +5 -0
- {pytexmk-1.2.4 → pytexmk-1.2.6}/src/pytexmk.egg-info/requires.txt +3 -3
- {pytexmk-1.2.4 → pytexmk-1.2.6}/tests/test_config_merge.py +1 -2
- {pytexmk-1.2.4 → pytexmk-1.2.6}/tests/test_context.py +1 -0
- {pytexmk-1.2.4 → pytexmk-1.2.6}/tests/test_subproject_scanner.py +0 -1
- {pytexmk-1.2.4 → pytexmk-1.2.6}/tests/test_tex_project.py +1 -0
- pytexmk-1.2.4/src/pytexmk/cli/cli_workflow.py +0 -445
- pytexmk-1.2.4/src/pytexmk/compile_report.py +0 -101
- pytexmk-1.2.4/src/pytexmk/detection.py +0 -531
- pytexmk-1.2.4/src/pytexmk/lifecycle.py +0 -22
- pytexmk-1.2.4/src/pytexmk/locale/en/LC_MESSAGES/check_version.mo +0 -0
- pytexmk-1.2.4/src/pytexmk/locale/en/LC_MESSAGES/cli_workflow.mo +0 -0
- pytexmk-1.2.4/src/pytexmk/locale/en/LC_MESSAGES/compile_engine.mo +0 -0
- pytexmk-1.2.4/src/pytexmk/locale/en/LC_MESSAGES/compile_report.mo +0 -0
- pytexmk-1.2.4/src/pytexmk/locale/en/LC_MESSAGES/lifecycle.mo +0 -0
- pytexmk-1.2.4/src/pytexmk/locale/en/LC_MESSAGES/subprocess_runner.mo +0 -0
- pytexmk-1.2.4/src/pytexmk/locale/en/LC_MESSAGES/tex_project.mo +0 -0
- pytexmk-1.2.4/src/pytexmk/locale/en/LC_MESSAGES/timing.mo +0 -0
- pytexmk-1.2.4/src/pytexmk/locale/en/LC_MESSAGES/ui_messages.mo +0 -0
- pytexmk-1.2.4/src/pytexmk/locale/templates/context.pot +0 -19
- pytexmk-1.2.4/src/pytexmk/locale/templates/lifecycle.pot +0 -22
- pytexmk-1.2.4/src/pytexmk/subprocess_runner.py +0 -126
- pytexmk-1.2.4/src/pytexmk/timing.py +0 -155
- {pytexmk-1.2.4 → pytexmk-1.2.6}/LICENSE +0 -0
- {pytexmk-1.2.4 → pytexmk-1.2.6}/setup.cfg +0 -0
- {pytexmk-1.2.4 → pytexmk-1.2.6}/src/pytexmk/__init__.py +0 -0
- {pytexmk-1.2.4 → pytexmk-1.2.6}/src/pytexmk/__main__.py +0 -0
- {pytexmk-1.2.4 → pytexmk-1.2.6}/src/pytexmk/cli/__init__.py +0 -0
- {pytexmk-1.2.4 → pytexmk-1.2.6}/src/pytexmk/cli/cli_args.py +0 -0
- {pytexmk-1.2.4 → pytexmk-1.2.6}/src/pytexmk/config.py +0 -0
- {pytexmk-1.2.4 → pytexmk-1.2.6}/src/pytexmk/data/README.html +0 -0
- {pytexmk-1.2.4 → pytexmk-1.2.6}/src/pytexmk/data/__init__.py +0 -0
- {pytexmk-1.2.4 → pytexmk-1.2.6}/src/pytexmk/data/default_project_config.toml +0 -0
- {pytexmk-1.2.4 → pytexmk-1.2.6}/src/pytexmk/data/default_user_config.toml +0 -0
- {pytexmk-1.2.4 → pytexmk-1.2.6}/src/pytexmk/locale/__init__.py +0 -0
- {pytexmk-1.2.4 → pytexmk-1.2.6}/src/pytexmk/locale/templates/__init__.py +0 -0
- {pytexmk-1.2.4 → pytexmk-1.2.6}/src/pytexmk/paths.py +0 -0
- {pytexmk-1.2.4 → pytexmk-1.2.6}/src/pytexmk/pdf_tools.py +0 -0
- {pytexmk-1.2.4 → pytexmk-1.2.6}/src/pytexmk/ui_theme.py +0 -0
- {pytexmk-1.2.4 → pytexmk-1.2.6}/src/pytexmk.egg-info/dependency_links.txt +0 -0
- {pytexmk-1.2.4 → pytexmk-1.2.6}/src/pytexmk.egg-info/entry_points.txt +0 -0
- {pytexmk-1.2.4 → pytexmk-1.2.6}/src/pytexmk.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pytexmk
|
|
3
|
-
Version: 1.2.
|
|
3
|
+
Version: 1.2.6
|
|
4
4
|
Summary: LaTeX 辅助编译命令行工具 LaTeX Auxiliary Compilation Command Line Tool
|
|
5
5
|
Author-email: 焱铭 <lxb-yanming@foxmail.com>
|
|
6
6
|
License-Expression: GPL-3.0-or-later
|
|
@@ -17,9 +17,9 @@ Classifier: Operating System :: OS Independent
|
|
|
17
17
|
Requires-Python: >=3.14
|
|
18
18
|
Description-Content-Type: text/markdown
|
|
19
19
|
License-File: LICENSE
|
|
20
|
-
Requires-Dist: packaging>=26.
|
|
21
|
-
Requires-Dist: platformdirs>=4.11.
|
|
22
|
-
Requires-Dist: pypdf>=6.
|
|
20
|
+
Requires-Dist: packaging>=26.3
|
|
21
|
+
Requires-Dist: platformdirs>=4.11.13
|
|
22
|
+
Requires-Dist: pypdf>=6.19.0
|
|
23
23
|
Requires-Dist: pytexlogs>=0.3.0
|
|
24
24
|
Requires-Dist: rich>=15.0.0
|
|
25
25
|
Requires-Dist: rich_argparse>=1.8.0
|
|
@@ -82,10 +82,10 @@ Dynamic: license-file
|
|
|
82
82
|
|
|
83
83
|
- 🚀 **多引擎支持**:XeLaTeX、PdfLaTeX、LuaLaTeX 三大编译引擎
|
|
84
84
|
- 📚 **参考文献**:支持 bibtex、biblatex、thebibliography
|
|
85
|
-
- 📑 **索引支持**:glossaries
|
|
85
|
+
- 📑 **索引支持**:glossaries(含 glossaries-extra + bib2gls + biber)、nomencl、makeidx
|
|
86
86
|
- 📋 **结构化编译检测报告**:将 6 维检测状态(参考文献/索引/目录/交叉引用/书签文件/日志 Rerun)与本轮结论整合为统一报告区块;报告采用 **Rich 5 色分层彩色(标题洋红、名称青粗、[OK]绿粗、[!!]黄粗、安全上限红粗)+ 粗体**,禁用表格网格,纯条目列表输出;**[OK] 状态不再千篇一律「状态稳定」,改为 6 维度各自独立的动态稳定文案**(如「参考文献引用计数无变化,参考文献解析稳定」「PDF 书签条目未发生变更,书签生成稳定」等);结论行 actual_next 语义严格对齐(2→1→无需,绝不兜底为 1,绝不打印「需额外进行 0 次」),编译名称按实际引擎动态替换为 XeLaTeX/PdfLaTeX/LuaLaTeX;所有报告文案完整适配国际化 `_()` 包装
|
|
87
87
|
- 🔁 **智能多次编译检测**:自动比较 aux/out 文件内容并解析日志 Rerun 警告,确保交叉引用、hyperref 书签、lastpage 总页数等收敛稳定
|
|
88
|
-
- 🔮 **魔法注释**:通过 `% !TEX`
|
|
88
|
+
- 🔮 **魔法注释**:通过 `% !TEX` 注释指定编译引擎、主文件、输出目录等;正则已加固,行内 TeX 转义百分号 `\%` 不会被误识别为魔法注释起始
|
|
89
89
|
- 🌍 **国际化**:支持多语言界面;**默认界面语言为中文**(源码字符串即中文),不强制默认英文;v1.2.1 起全面采用 **pybabel 官方工作流**(`pybabel extract → init → update → compile`),不再使用 xgettext / msgfmt;所有用户可见文案 100% `_()` 包装 + `%(name)s` 占位;**3 组遗留共享域全部拆为独立域**(lifecycle / paths、pdf_tools / subprocess_runner / tex_project、timing / ui_messages),与 set_language 参数、locale 文件名 1:1 严格对齐;提供新增语言的交互式命令(`make lang-add` 终端提问语言代码)、自动更新所有 pot/po 的 `make lang-update`、把 po 编译成 mo 的 `make lang-mo`、以及重抽所有 pot 的 `make lang-poup`
|
|
90
90
|
- 🧹 **智能清理**:支持多种清理模式,精确清理辅助文件
|
|
91
91
|
- 🔍 **日志解析**:编译失败后自动解析 LaTeX 日志,定位错误
|
|
@@ -128,7 +128,7 @@ uv pip install pytexmk
|
|
|
128
128
|
Windows 10 1809+ / Windows 11 用户可使用 [winget](https://learn.microsoft.com/zh-cn/windows/package-manager/) 一键安装(无需 Python 环境):
|
|
129
129
|
|
|
130
130
|
```powershell
|
|
131
|
-
winget install --id YanMing-lxb.PyTeXMK
|
|
131
|
+
winget install --id YanMing-lxb.PyTeXMK
|
|
132
132
|
```
|
|
133
133
|
|
|
134
134
|
> 提示:若已完成 moniker 注册,可简写为 `winget install pytexmk`。
|
|
@@ -49,10 +49,10 @@
|
|
|
49
49
|
|
|
50
50
|
- 🚀 **多引擎支持**:XeLaTeX、PdfLaTeX、LuaLaTeX 三大编译引擎
|
|
51
51
|
- 📚 **参考文献**:支持 bibtex、biblatex、thebibliography
|
|
52
|
-
- 📑 **索引支持**:glossaries
|
|
52
|
+
- 📑 **索引支持**:glossaries(含 glossaries-extra + bib2gls + biber)、nomencl、makeidx
|
|
53
53
|
- 📋 **结构化编译检测报告**:将 6 维检测状态(参考文献/索引/目录/交叉引用/书签文件/日志 Rerun)与本轮结论整合为统一报告区块;报告采用 **Rich 5 色分层彩色(标题洋红、名称青粗、[OK]绿粗、[!!]黄粗、安全上限红粗)+ 粗体**,禁用表格网格,纯条目列表输出;**[OK] 状态不再千篇一律「状态稳定」,改为 6 维度各自独立的动态稳定文案**(如「参考文献引用计数无变化,参考文献解析稳定」「PDF 书签条目未发生变更,书签生成稳定」等);结论行 actual_next 语义严格对齐(2→1→无需,绝不兜底为 1,绝不打印「需额外进行 0 次」),编译名称按实际引擎动态替换为 XeLaTeX/PdfLaTeX/LuaLaTeX;所有报告文案完整适配国际化 `_()` 包装
|
|
54
54
|
- 🔁 **智能多次编译检测**:自动比较 aux/out 文件内容并解析日志 Rerun 警告,确保交叉引用、hyperref 书签、lastpage 总页数等收敛稳定
|
|
55
|
-
- 🔮 **魔法注释**:通过 `% !TEX`
|
|
55
|
+
- 🔮 **魔法注释**:通过 `% !TEX` 注释指定编译引擎、主文件、输出目录等;正则已加固,行内 TeX 转义百分号 `\%` 不会被误识别为魔法注释起始
|
|
56
56
|
- 🌍 **国际化**:支持多语言界面;**默认界面语言为中文**(源码字符串即中文),不强制默认英文;v1.2.1 起全面采用 **pybabel 官方工作流**(`pybabel extract → init → update → compile`),不再使用 xgettext / msgfmt;所有用户可见文案 100% `_()` 包装 + `%(name)s` 占位;**3 组遗留共享域全部拆为独立域**(lifecycle / paths、pdf_tools / subprocess_runner / tex_project、timing / ui_messages),与 set_language 参数、locale 文件名 1:1 严格对齐;提供新增语言的交互式命令(`make lang-add` 终端提问语言代码)、自动更新所有 pot/po 的 `make lang-update`、把 po 编译成 mo 的 `make lang-mo`、以及重抽所有 pot 的 `make lang-poup`
|
|
57
57
|
- 🧹 **智能清理**:支持多种清理模式,精确清理辅助文件
|
|
58
58
|
- 🔍 **日志解析**:编译失败后自动解析 LaTeX 日志,定位错误
|
|
@@ -95,7 +95,7 @@ uv pip install pytexmk
|
|
|
95
95
|
Windows 10 1809+ / Windows 11 用户可使用 [winget](https://learn.microsoft.com/zh-cn/windows/package-manager/) 一键安装(无需 Python 环境):
|
|
96
96
|
|
|
97
97
|
```powershell
|
|
98
|
-
winget install --id YanMing-lxb.PyTeXMK
|
|
98
|
+
winget install --id YanMing-lxb.PyTeXMK
|
|
99
99
|
```
|
|
100
100
|
|
|
101
101
|
> 提示:若已完成 moniker 注册,可简写为 `winget install pytexmk`。
|
|
@@ -11,9 +11,9 @@ authors = [
|
|
|
11
11
|
description = "LaTeX 辅助编译命令行工具 LaTeX Auxiliary Compilation Command Line Tool"
|
|
12
12
|
keywords = ["LaTeX", "build", "latexmk"]
|
|
13
13
|
dependencies = [
|
|
14
|
-
"packaging>=26.
|
|
15
|
-
"platformdirs>=4.11.
|
|
16
|
-
"pypdf>=6.
|
|
14
|
+
"packaging>=26.3",
|
|
15
|
+
"platformdirs>=4.11.13",
|
|
16
|
+
"pypdf>=6.19.0",
|
|
17
17
|
"pytexlogs>=0.3.0",
|
|
18
18
|
"rich>=15.0.0",
|
|
19
19
|
"rich_argparse>=1.8.0",
|
|
@@ -58,7 +58,7 @@ dev = [
|
|
|
58
58
|
dev = [
|
|
59
59
|
"babel>=2.18",
|
|
60
60
|
"pillow>=12.3.0",
|
|
61
|
-
"pyinstaller>=6.
|
|
61
|
+
"pyinstaller>=6.22.3",
|
|
62
62
|
"pytest>=9.1.1",
|
|
63
63
|
]
|
|
64
64
|
|
|
@@ -90,11 +90,3 @@ include-package-data = true
|
|
|
90
90
|
|
|
91
91
|
[tool.ruff]
|
|
92
92
|
line-length = 120
|
|
93
|
-
|
|
94
|
-
[tool.ruff.lint.per-file-ignores]
|
|
95
|
-
"tests/*" = ["BLE001", "S112", "DTZ005", "PLW1510"]
|
|
96
|
-
"scripts/*" = ["BLE001", "S112", "DTZ005", "PLW1510"]
|
|
97
|
-
"tests/test.py" = ["BLE001", "S112", "DTZ005", "PLW1510"]
|
|
98
|
-
"tests/test_tr21_manager_compare.py" = ["BLE001", "S112", "DTZ005", "PLW1510"]
|
|
99
|
-
"tests/test_tr22_register_compat.py" = ["BLE001", "S112", "DTZ005", "PLW1510"]
|
|
100
|
-
"scripts/check_log_decouple.py" = ["BLE001", "S112", "DTZ005", "PLW1510"]
|
|
@@ -95,7 +95,19 @@ def main():
|
|
|
95
95
|
args = parse_args(UC)
|
|
96
96
|
from pytexmk.cli.cli_workflow import run_workflow
|
|
97
97
|
|
|
98
|
-
|
|
98
|
+
try:
|
|
99
|
+
run_workflow(args)
|
|
100
|
+
except KeyboardInterrupt:
|
|
101
|
+
try:
|
|
102
|
+
# 确保 console 已初始化(如果在 _ = set_language 之前就按 Ctrl+C)
|
|
103
|
+
from pytexmk.ui_theme import console
|
|
104
|
+
|
|
105
|
+
console.print()
|
|
106
|
+
console.print("[bold yellow]PyTeXMK 已被用户中断[/bold yellow]")
|
|
107
|
+
except Exception: # noqa: BLE001
|
|
108
|
+
# console 还没初始化成功就被 Ctrl+C,直接 print 兜底
|
|
109
|
+
print("\nPyTeXMK 已被用户中断", file=sys.stderr)
|
|
110
|
+
sys.exit(130) # 标准 SIGINT 退出码 (128 + 2)
|
|
99
111
|
|
|
100
112
|
|
|
101
113
|
if __name__ == "__main__":
|
|
@@ -38,9 +38,9 @@ from typing import Literal
|
|
|
38
38
|
import tomli_w
|
|
39
39
|
from packaging import version
|
|
40
40
|
from platformdirs import user_cache_dir
|
|
41
|
-
from rich import print
|
|
42
41
|
|
|
43
42
|
from ..language import set_language
|
|
43
|
+
from ..ui_theme import console
|
|
44
44
|
from ..version import __version__, script_name
|
|
45
45
|
|
|
46
46
|
_ = set_language("check_version")
|
|
@@ -324,7 +324,7 @@ class UpdateChecker:
|
|
|
324
324
|
|
|
325
325
|
# 增加版本号格式校验
|
|
326
326
|
if "tag_name" not in data:
|
|
327
|
-
raise ValueError()
|
|
327
|
+
raise ValueError(_("GitHub release 响应中缺少 tag_name 字段"))
|
|
328
328
|
|
|
329
329
|
latest_version = data["tag_name"].lstrip("v") # 去除可能存在的v前缀
|
|
330
330
|
parsed_version = version.parse(latest_version)
|
|
@@ -382,7 +382,7 @@ class UpdateChecker:
|
|
|
382
382
|
current_version = version.parse(__version__)
|
|
383
383
|
|
|
384
384
|
if current_version < latest_version:
|
|
385
|
-
print(
|
|
385
|
+
console.print(
|
|
386
386
|
_("有新版本可用: ")
|
|
387
387
|
+ f"[bold green]{latest_version}[/bold green] "
|
|
388
388
|
+ _("当前版本: ")
|
|
@@ -391,6 +391,6 @@ class UpdateChecker:
|
|
|
391
391
|
method = _detect_install_method()
|
|
392
392
|
lines = _build_upgrade_message(method)
|
|
393
393
|
for line in lines:
|
|
394
|
-
print(line)
|
|
394
|
+
console.print(line)
|
|
395
395
|
else:
|
|
396
|
-
print(_("当前版本: ") + f"[bold green]{current_version}[/bold green]")
|
|
396
|
+
console.print(_("当前版本: ") + f"[bold green]{current_version}[/bold green]")
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
"""PyTeXMK CLI 常规编译流程:清理、修复、编译与收尾。"""
|
|
2
|
+
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
|
|
5
|
+
import pytexlogs
|
|
6
|
+
|
|
7
|
+
from ..compile_engine import RUN
|
|
8
|
+
from ..language import set_language
|
|
9
|
+
from ..lifecycle import exit_pytexmk
|
|
10
|
+
from ..timing import time_count, time_print
|
|
11
|
+
from ..ui_messages import print_message
|
|
12
|
+
from ..ui_theme import console
|
|
13
|
+
from ..version import __version__
|
|
14
|
+
from .check_version import UpdateChecker
|
|
15
|
+
from .cli_state import WorkflowState
|
|
16
|
+
|
|
17
|
+
_ = set_language("cli_workflow")
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def handle_clean_any(args, state: WorkflowState) -> bool:
|
|
21
|
+
"""处理 -ca / -Ca(清理所有带辅助文件后缀的文件)。
|
|
22
|
+
|
|
23
|
+
返回 True 表示本次运行已结束,调用方应直接收工。
|
|
24
|
+
"""
|
|
25
|
+
if not (args.clean_any or args.Clean_any):
|
|
26
|
+
return False
|
|
27
|
+
|
|
28
|
+
runtime_remove_aux_matched_auxdir, _ret = time_count(
|
|
29
|
+
state.mro.remove_matched_files, state.aux_regex_files, "."
|
|
30
|
+
)
|
|
31
|
+
state.runtime_dict[_("清除所有的辅助文件")] = runtime_remove_aux_matched_auxdir
|
|
32
|
+
|
|
33
|
+
if args.Clean_any:
|
|
34
|
+
runtime_remove_out_outdir, _ret = time_count(
|
|
35
|
+
state.mro.remove_specific_files, state.out_files, state.outdir
|
|
36
|
+
)
|
|
37
|
+
state.runtime_dict[_("清除文件夹内输出文件")] = runtime_remove_out_outdir
|
|
38
|
+
console.print(
|
|
39
|
+
_("[bold green]已完成清除所有带辅助文件后缀的文件和主文件输出文件的指令[/bold green]")
|
|
40
|
+
)
|
|
41
|
+
else:
|
|
42
|
+
console.print(
|
|
43
|
+
_("[bold green]已完成清除所有带辅助文件后缀的文件的指令[/bold green]")
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
if state.runtime_dict:
|
|
47
|
+
time_print(state.start_time, state.runtime_dict)
|
|
48
|
+
return True
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def run(args, state: WorkflowState) -> None:
|
|
52
|
+
"""常规编译路径:清理 / 修复 PDF / 完整编译三选一。"""
|
|
53
|
+
if args.clean or args.Clean:
|
|
54
|
+
_clean(args, state)
|
|
55
|
+
elif args.pdf_repair:
|
|
56
|
+
runtime_pdf_repair, _ret = time_count(
|
|
57
|
+
state.pfo.pdf_repair, state.project_name, ".", state.outdir
|
|
58
|
+
)
|
|
59
|
+
state.runtime_dict[_("修复 PDF 文件")] = runtime_pdf_repair
|
|
60
|
+
else:
|
|
61
|
+
_compile(args, state)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def finalize(state: WorkflowState) -> None:
|
|
65
|
+
"""全部流程收尾:编译后 PDF 预览、耗时统计与版本更新检查。"""
|
|
66
|
+
if state.preview_after_compile and state.project_name:
|
|
67
|
+
state.pfo.pdf_preview(state.project_name, state.outdir)
|
|
68
|
+
exit_pytexmk()
|
|
69
|
+
|
|
70
|
+
if state.runtime_dict:
|
|
71
|
+
time_print(state.start_time, state.runtime_dict)
|
|
72
|
+
|
|
73
|
+
UpdateChecker(1, 6).check_for_updates()
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def _clean(args, state: WorkflowState) -> None:
|
|
77
|
+
"""-c / -C:清理主文件的辅助文件(-C 额外清理输出文件)。"""
|
|
78
|
+
runtime_remove_aux_auxdir, _ret = time_count(
|
|
79
|
+
state.mro.remove_specific_files, state.aux_files, state.auxdir
|
|
80
|
+
)
|
|
81
|
+
state.runtime_dict[_("清除文件夹内辅助文件")] = runtime_remove_aux_auxdir
|
|
82
|
+
runtime_remove_aux_root, _ret = time_count(
|
|
83
|
+
state.mro.remove_specific_files, state.aux_files, "."
|
|
84
|
+
)
|
|
85
|
+
state.runtime_dict[_("清除根目录内辅助文件")] = runtime_remove_aux_root
|
|
86
|
+
|
|
87
|
+
if args.Clean:
|
|
88
|
+
runtime_remove_out_outdir, _ret = time_count(
|
|
89
|
+
state.mro.remove_specific_files, state.out_files, state.outdir
|
|
90
|
+
)
|
|
91
|
+
state.runtime_dict[_("清除文件夹内输出文件")] = runtime_remove_out_outdir
|
|
92
|
+
console.print(
|
|
93
|
+
_("[bold green]已完成清除所有主文件的辅助文件和输出文件的指令[/bold green]")
|
|
94
|
+
)
|
|
95
|
+
else:
|
|
96
|
+
console.print(
|
|
97
|
+
_("[bold green]已完成清除所有主文件的辅助文件的指令[/bold green]")
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def _compile(args, state: WorkflowState) -> None:
|
|
102
|
+
"""执行一次完整编译:辅助文件就位 → 编译 → 结果与辅助文件归档 → 日志解析。"""
|
|
103
|
+
print_message(_("开始预处理"), "additional")
|
|
104
|
+
runtime_move_aux_root, aux_moved_count = time_count(
|
|
105
|
+
state.mro.move_specific_files, state.aux_files, state.auxdir, "."
|
|
106
|
+
)
|
|
107
|
+
state.runtime_dict[_("辅助文件->根目录")] = runtime_move_aux_root
|
|
108
|
+
|
|
109
|
+
aux_exist_count = sum(1 for f in state.aux_files if Path(f).exists())
|
|
110
|
+
if aux_exist_count == 0:
|
|
111
|
+
console.print("[green]" + _("未检测到已有辅助文件,进行初始化") + "[/green]")
|
|
112
|
+
else:
|
|
113
|
+
console.print(
|
|
114
|
+
"[green]"
|
|
115
|
+
+ _("已检测到 %(n)s 个已有辅助文件") % {"n": aux_exist_count}
|
|
116
|
+
+ "[/green]"
|
|
117
|
+
)
|
|
118
|
+
# P2 中断后辅助文件一致性检测:.log 缺失完成标记 ⇒ 警告用户
|
|
119
|
+
_warn_if_last_compile_interrupted(state)
|
|
120
|
+
|
|
121
|
+
if aux_moved_count == 0:
|
|
122
|
+
console.print("[green]" + _("没有检测到可迁移的辅助文件") + "[/green]")
|
|
123
|
+
else:
|
|
124
|
+
console.print(
|
|
125
|
+
"[yellow]"
|
|
126
|
+
+ _("已移动 %(n)s 个辅助文件到项目根目录") % {"n": aux_moved_count}
|
|
127
|
+
+ "[/yellow]"
|
|
128
|
+
)
|
|
129
|
+
|
|
130
|
+
RUN(
|
|
131
|
+
state.runtime_dict,
|
|
132
|
+
state.project_name,
|
|
133
|
+
state.compiled_program,
|
|
134
|
+
state.out_files,
|
|
135
|
+
state.aux_files,
|
|
136
|
+
state.outdir,
|
|
137
|
+
state.auxdir,
|
|
138
|
+
state.non_quiet,
|
|
139
|
+
args.draft,
|
|
140
|
+
)
|
|
141
|
+
|
|
142
|
+
print_message(_("开始后处理"), "additional")
|
|
143
|
+
|
|
144
|
+
console.print("[yellow]" + _("移动结果文件到输出目录...") + "[/yellow]")
|
|
145
|
+
runtime_move_out_outdir, _ret = time_count(
|
|
146
|
+
state.mro.move_specific_files, state.out_files, ".", state.outdir
|
|
147
|
+
)
|
|
148
|
+
state.runtime_dict[_("结果文件->输出目录")] = runtime_move_out_outdir
|
|
149
|
+
|
|
150
|
+
console.print("[yellow]" + _("移动辅助文件到辅助目录...") + "[/yellow]")
|
|
151
|
+
runtime_move_aux_auxdir, _ret = time_count(
|
|
152
|
+
state.mro.move_specific_files, state.aux_files, ".", state.auxdir
|
|
153
|
+
)
|
|
154
|
+
state.runtime_dict[_("辅助文件->辅助目录")] = runtime_move_aux_auxdir
|
|
155
|
+
|
|
156
|
+
pytexlogs.run_log_pipeline(
|
|
157
|
+
state.project_name,
|
|
158
|
+
state.auxdir,
|
|
159
|
+
root_file=state.project_name,
|
|
160
|
+
pytexmk_version=__version__,
|
|
161
|
+
ref_tracker_translate_fn=set_language("log_parser"),
|
|
162
|
+
)
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
def _warn_if_last_compile_interrupted(state: WorkflowState) -> None:
|
|
166
|
+
"""检测上次 LaTeX 编译是否被中断,若有则给出黄色警告。
|
|
167
|
+
|
|
168
|
+
检测逻辑:
|
|
169
|
+
1. auxdir 里 .log 文件存在(说明有过编译)
|
|
170
|
+
2. 取 .log 最后 3 行,检查是否包含正常完成标记
|
|
171
|
+
- "Output written on ..." (pdf)
|
|
172
|
+
- "No pages of output." (正常无输出也算完成)
|
|
173
|
+
- "Transcript written on ..." (latexmk 等包装的收尾)
|
|
174
|
+
3. 若没有完成标记 ⇒ 上次编译被 Ctrl+C / 崩溃中断
|
|
175
|
+
"""
|
|
176
|
+
log_path = Path(state.auxdir) / f"{state.project_name}.log"
|
|
177
|
+
if not log_path.exists():
|
|
178
|
+
return
|
|
179
|
+
|
|
180
|
+
try:
|
|
181
|
+
# 读最后 2KB(足以覆盖结尾标记),避免整文件加载大 log
|
|
182
|
+
with log_path.open("rb") as fh:
|
|
183
|
+
fh.seek(0, 2) # 移到末尾
|
|
184
|
+
size = fh.tell()
|
|
185
|
+
tail_size = min(2048, size)
|
|
186
|
+
fh.seek(size - tail_size)
|
|
187
|
+
tail_bytes = fh.read()
|
|
188
|
+
tail_text = tail_bytes.decode("utf-8", errors="replace")
|
|
189
|
+
except OSError:
|
|
190
|
+
return
|
|
191
|
+
|
|
192
|
+
completion_markers = (
|
|
193
|
+
"Output written on",
|
|
194
|
+
"No pages of output",
|
|
195
|
+
"Transcript written on",
|
|
196
|
+
)
|
|
197
|
+
if not any(marker in tail_text for marker in completion_markers):
|
|
198
|
+
console.print(
|
|
199
|
+
"[yellow]"
|
|
200
|
+
+ _("警告:检测到上次编译可能被中断,辅助文件可能不完整。")
|
|
201
|
+
+ _("建议先运行 [bold cyan]pytexmk -c[/bold cyan] 清理后再重试。[/yellow]")
|
|
202
|
+
)
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
"""PyTeXMK CLI 上下文解析:子项目定位、配置合并与魔法注释覆盖。"""
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
|
|
5
|
+
from ..config import ConfigParser
|
|
6
|
+
from ..language import set_language
|
|
7
|
+
from ..lifecycle import EXIT_ERROR, EXIT_PROJECT_NOT_FOUND, exit_pytexmk
|
|
8
|
+
from ..tex_project import standardize_name
|
|
9
|
+
from ..ui_theme import console
|
|
10
|
+
from .cli_state import (
|
|
11
|
+
MAGIC_COMMENT_KEYS,
|
|
12
|
+
PREVIEW_AFTER_COMPILE,
|
|
13
|
+
SUFFIXES_AUX,
|
|
14
|
+
SUFFIXES_OUT,
|
|
15
|
+
WorkflowState,
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
_ = set_language("cli_workflow")
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def build(args, cp: ConfigParser, logger) -> WorkflowState:
|
|
22
|
+
"""定位本次运行上下文,并完成「配置文件」这一层的参数合并。
|
|
23
|
+
|
|
24
|
+
依次完成:子项目解析 → 进入工作根目录 → 扫描主文件与魔法注释 →
|
|
25
|
+
合并配置文件参数 → 合并命令行参数 → (可选)单次 PDF 预览后退出。
|
|
26
|
+
"""
|
|
27
|
+
from ..context import ContextResolver, ProjectNotFoundError
|
|
28
|
+
|
|
29
|
+
state = WorkflowState(args=args, logger=logger)
|
|
30
|
+
|
|
31
|
+
try:
|
|
32
|
+
ctx = ContextResolver(cp).resolve(args)
|
|
33
|
+
except ProjectNotFoundError as e:
|
|
34
|
+
logger.error(str(e))
|
|
35
|
+
logger.warning(_("可运行 pytexmk -ls 同步子项目清单, 或检查根配置 \\[subprojects\\] 段"))
|
|
36
|
+
exit_pytexmk(EXIT_PROJECT_NOT_FOUND)
|
|
37
|
+
|
|
38
|
+
state.config_dict = ctx.config
|
|
39
|
+
if ctx.subproject and args.verbose:
|
|
40
|
+
logger.info(_("子项目调用: 忽略子项目目录下的本地 .pytexmkrc, 以根配置为准"))
|
|
41
|
+
|
|
42
|
+
# 进入工作根目录:用户终端 cwd 不变,编译流程在子项目/根目录内执行
|
|
43
|
+
os.chdir(ctx.work_root)
|
|
44
|
+
|
|
45
|
+
logger.info("-" * 70)
|
|
46
|
+
tex_files_in_root = state.mfo.get_suffix_files_in_dir(".", ".tex")
|
|
47
|
+
state.main_files_in_root = state.mfo.find_tex_commands(tex_files_in_root)
|
|
48
|
+
state.all_magic_comments = state.mfo.search_magic_comments(state.main_files_in_root, MAGIC_COMMENT_KEYS)
|
|
49
|
+
|
|
50
|
+
_apply_config_file(state)
|
|
51
|
+
|
|
52
|
+
logger.info("-" * 70)
|
|
53
|
+
if args.non_quiet:
|
|
54
|
+
state.non_quiet = args.non_quiet
|
|
55
|
+
if state.non_quiet:
|
|
56
|
+
logger.info(_("非安静模式运行"))
|
|
57
|
+
|
|
58
|
+
_apply_pdf_preview(state)
|
|
59
|
+
return state
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def resolve_target(args, state: WorkflowState) -> None:
|
|
63
|
+
"""决定本次要处理的目标:LaTeXDiff 新旧文件对,或待编译的主文件名。"""
|
|
64
|
+
if state.is_latexdiff:
|
|
65
|
+
_resolve_latexdiff_target(state)
|
|
66
|
+
else:
|
|
67
|
+
state.project_name = state.mfo.get_main_file(
|
|
68
|
+
state.default_file, args.document, state.main_files_in_root, state.all_magic_comments
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def apply_magic_comments(state: WorkflowState) -> None:
|
|
73
|
+
"""用魔法注释覆盖程序与目录设置,并派生出本次运行的文件清单。"""
|
|
74
|
+
logger = state.logger
|
|
75
|
+
|
|
76
|
+
if state.all_magic_comments:
|
|
77
|
+
for key, values in state.all_magic_comments.items():
|
|
78
|
+
if key == "root":
|
|
79
|
+
continue
|
|
80
|
+
if state.project_name in values:
|
|
81
|
+
state.magic_comments[key] = values[state.project_name]
|
|
82
|
+
logger.info(
|
|
83
|
+
_("提取魔法注释: ") + f"{state.project_name}.tex ==> % !TEX {key} = {values[state.project_name]}"
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
if state.args.XeLaTeX:
|
|
87
|
+
state.compiled_program = "XeLaTeX"
|
|
88
|
+
elif state.args.PdfLaTeX:
|
|
89
|
+
state.compiled_program = "PdfLaTeX"
|
|
90
|
+
elif state.args.LuaLaTeX:
|
|
91
|
+
state.compiled_program = "LuaLaTeX"
|
|
92
|
+
elif state.magic_comments.get("program"):
|
|
93
|
+
state.compiled_program = standardize_name(state.magic_comments["program"])
|
|
94
|
+
console.print(_("通过魔法注释设置程序为: ") + f"[bold cyan]{state.compiled_program}")
|
|
95
|
+
|
|
96
|
+
if state.magic_comments.get("outdir"):
|
|
97
|
+
state.outdir = state.magic_comments["outdir"]
|
|
98
|
+
console.print(_("通过魔法注释设置输出目录: ") + f"[bold cyan]{state.outdir}[/bold cyan]")
|
|
99
|
+
if state.magic_comments.get("auxdir"):
|
|
100
|
+
state.auxdir = state.magic_comments["auxdir"]
|
|
101
|
+
console.print(_("通过魔法注释设置辅助目录: ") + f"[bold cyan]{state.auxdir}[/bold cyan]")
|
|
102
|
+
|
|
103
|
+
state.out_files = [f"{state.project_name}{suffix}" for suffix in SUFFIXES_OUT]
|
|
104
|
+
state.aux_files = [f"{state.project_name}{suffix}" for suffix in SUFFIXES_AUX]
|
|
105
|
+
state.aux_regex_files = [f".*\\{suffix}" for suffix in SUFFIXES_AUX]
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def _apply_config_file(state: WorkflowState) -> None:
|
|
109
|
+
"""把配置文件中的取值合并进运行时参数(优先级:内置默认值 < 配置文件)。"""
|
|
110
|
+
logger = state.logger
|
|
111
|
+
config_dict = state.config_dict
|
|
112
|
+
|
|
113
|
+
if config_dict["default_file"]:
|
|
114
|
+
state.default_file = config_dict["default_file"]
|
|
115
|
+
logger.info(_("通过配置文件设置默认文件为: ") + f"[bold cyan]{state.default_file}")
|
|
116
|
+
if config_dict["compiled_program"]:
|
|
117
|
+
state.compiled_program = standardize_name(config_dict["compiled_program"])
|
|
118
|
+
logger.info(_("通过配置文件设置编译器为: ") + f"[bold cyan]{state.compiled_program}")
|
|
119
|
+
if config_dict["quiet_mode"]:
|
|
120
|
+
state.non_quiet = False
|
|
121
|
+
logger.info(_("通过配置文件设置安静模式为: ") + f"[bold cyan]{config_dict['quiet_mode']}")
|
|
122
|
+
|
|
123
|
+
if config_dict["folder"]:
|
|
124
|
+
if config_dict["folder"]["outdir"]:
|
|
125
|
+
state.outdir = config_dict["folder"]["outdir"]
|
|
126
|
+
logger.info(_("通过配置文件设置输出目录为: ") + f"[bold cyan]{state.outdir}")
|
|
127
|
+
if config_dict["folder"]["auxdir"]:
|
|
128
|
+
state.auxdir = config_dict["folder"]["auxdir"]
|
|
129
|
+
logger.info(_("通过配置文件设置辅助目录为: ") + f"[bold cyan]{state.auxdir}")
|
|
130
|
+
|
|
131
|
+
if config_dict["pdf"]:
|
|
132
|
+
if config_dict["pdf"]["pdf_preview_status"]:
|
|
133
|
+
state.preview_after_compile = True
|
|
134
|
+
logger.info(
|
|
135
|
+
_("通过配置文件设置 PDF 预览为: ") + f"[bold cyan]{config_dict['pdf']['pdf_preview_status']}"
|
|
136
|
+
)
|
|
137
|
+
if config_dict["pdf"]["pdf_viewer"]:
|
|
138
|
+
state.pfo.set_viewer(config_dict["pdf"]["pdf_viewer"])
|
|
139
|
+
logger.info(_("通过配置文件设置 PDF 预览器为: ") + f"[bold cyan]{config_dict['pdf']['pdf_viewer']}")
|
|
140
|
+
|
|
141
|
+
# [index] 段参数(index_style_file / input_suffix / output_suffix)暂未接入运行时:
|
|
142
|
+
# glossaries 输入后缀由 .aux 动态解析多值,单一后缀语义不成立;
|
|
143
|
+
# 其余索引系统后缀由 detection._INDEX_REGISTRY 硬编码统一管理。
|
|
144
|
+
# 若未来需要让用户可覆盖,应接通到 _INDEX_REGISTRY 的规则元数据而非在此处读取。
|
|
145
|
+
if config_dict["latexdiff"]:
|
|
146
|
+
if config_dict["latexdiff"]["old_tex_file"]:
|
|
147
|
+
state.old_tex_file = config_dict["latexdiff"]["old_tex_file"]
|
|
148
|
+
logger.info(_("通过配置文件设置 LaTeXDiff 旧文件为: ") + f"[bold cyan]{state.old_tex_file}")
|
|
149
|
+
if config_dict["latexdiff"]["new_tex_file"]:
|
|
150
|
+
state.new_tex_file = config_dict["latexdiff"]["new_tex_file"]
|
|
151
|
+
logger.info(_("通过配置文件设置 LaTeXDiff 新文件为: ") + f"[bold cyan]{state.new_tex_file}")
|
|
152
|
+
if config_dict["latexdiff"]["diff_tex_file"]:
|
|
153
|
+
state.diff_tex_file = config_dict["latexdiff"]["diff_tex_file"]
|
|
154
|
+
logger.info(_("通过配置文件设置 LaTeXDiff 对比文件为: ") + f"[bold cyan]{state.diff_tex_file}")
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
def _apply_pdf_preview(state: WorkflowState) -> None:
|
|
158
|
+
"""合并命令行 -pv 语义:给出文件名则预览该文件后退出,否则标记编译后预览。"""
|
|
159
|
+
args = state.args
|
|
160
|
+
if args.pdf_preview is None:
|
|
161
|
+
return
|
|
162
|
+
|
|
163
|
+
# 命令行显式给出 -pv,以命令行为准;-pv FILE 只做一次预览,不触发编译后预览
|
|
164
|
+
state.preview_after_compile = False
|
|
165
|
+
if args.pdf_preview == PREVIEW_AFTER_COMPILE:
|
|
166
|
+
state.preview_after_compile = True
|
|
167
|
+
return
|
|
168
|
+
if not args.pdf_preview or args.document:
|
|
169
|
+
return
|
|
170
|
+
|
|
171
|
+
pdf_files_in_outdir = state.mfo.get_suffix_files_in_dir(state.outdir, ".pdf")
|
|
172
|
+
target = state.mfo.check_project_name(pdf_files_in_outdir, args.pdf_preview, ".pdf")
|
|
173
|
+
state.pfo.pdf_preview(target, state.outdir)
|
|
174
|
+
exit_pytexmk()
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
def _resolve_latexdiff_target(state: WorkflowState) -> None:
|
|
178
|
+
"""校验并解析 LaTeXDiff 的两个待比较 TeX 文件(命令行优先,其次配置文件)。"""
|
|
179
|
+
args, logger = state.args, state.logger
|
|
180
|
+
|
|
181
|
+
if args.LaTeXDiff is not None and len(args.LaTeXDiff) != 2:
|
|
182
|
+
logger.error(_("LaTeXDiff 需恰好 2 个文件名,当前收到 %(n)s 个") % {"n": len(args.LaTeXDiff)})
|
|
183
|
+
exit_pytexmk(EXIT_ERROR)
|
|
184
|
+
if args.LaTeXDiff_compile is not None and len(args.LaTeXDiff_compile) != 2:
|
|
185
|
+
logger.error(_("LaTeXDiff-compile 需恰好 2 个文件名,当前收到 %(n)s 个") % {"n": len(args.LaTeXDiff_compile)})
|
|
186
|
+
exit_pytexmk(EXIT_ERROR)
|
|
187
|
+
if args.LaTeXDiff is not None and len(args.LaTeXDiff) == 2:
|
|
188
|
+
state.old_tex_file, state.new_tex_file = args.LaTeXDiff
|
|
189
|
+
elif args.LaTeXDiff_compile is not None and len(args.LaTeXDiff_compile) == 2:
|
|
190
|
+
state.old_tex_file, state.new_tex_file = args.LaTeXDiff_compile
|
|
191
|
+
else:
|
|
192
|
+
# 命令行未指定, 尝试从配置文件读取
|
|
193
|
+
console.print(_("命令行未指定 LaTeXDiff 相关参数"))
|
|
194
|
+
if state.new_tex_file and state.old_tex_file:
|
|
195
|
+
console.print(_("根据配置文件设置 LaTeXDiff 新 TeX 文件为: ") + f"[bold cyan]{state.new_tex_file}")
|
|
196
|
+
console.print(_("根据配置文件设置 LaTeXDiff 旧 TeX 文件为: ") + f"[bold cyan]{state.old_tex_file}")
|
|
197
|
+
else:
|
|
198
|
+
logger.error(_("请在命令行或配置文件中指定新旧两个 TeX 文件"))
|
|
199
|
+
exit_pytexmk(EXIT_ERROR)
|
|
200
|
+
|
|
201
|
+
state.old_tex_file = state.mfo.check_project_name(state.main_files_in_root, state.old_tex_file, ".tex")
|
|
202
|
+
state.new_tex_file = state.mfo.check_project_name(state.main_files_in_root, state.new_tex_file, ".tex")
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"""PyTeXMK CLI 早退出子命令:README / 配置初始化 / 子项目清单。"""
|
|
2
|
+
|
|
3
|
+
import webbrowser
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
from ..config import ConfigParser
|
|
7
|
+
from ..language import set_language
|
|
8
|
+
from ..lifecycle import exit_pytexmk
|
|
9
|
+
from ..paths import get_app_path
|
|
10
|
+
from ..subproject_scanner import (
|
|
11
|
+
discover_subprojects,
|
|
12
|
+
print_subproject_table,
|
|
13
|
+
write_subprojects_to_rc,
|
|
14
|
+
)
|
|
15
|
+
from ..ui_theme import console
|
|
16
|
+
|
|
17
|
+
_ = set_language("cli_workflow")
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def handle(args, cp: ConfigParser, logger) -> None:
|
|
21
|
+
"""处理 -r / -i / -iu / -ls 早退出子命令。
|
|
22
|
+
|
|
23
|
+
命中任意一个子命令都会在执行完后直接结束进程;全部未命中时直接返回,
|
|
24
|
+
由调用方继续编译流程。
|
|
25
|
+
"""
|
|
26
|
+
if args.readme:
|
|
27
|
+
_open_readme(logger)
|
|
28
|
+
exit_pytexmk()
|
|
29
|
+
|
|
30
|
+
logger.info("-" * 70)
|
|
31
|
+
if args.init:
|
|
32
|
+
if cp.init_project_config(args.force):
|
|
33
|
+
console.print(
|
|
34
|
+
_("[bold green]已生成根项目配置文件 [/bold green]")
|
|
35
|
+
+ str(Path.cwd() / ".pytexmkrc")
|
|
36
|
+
)
|
|
37
|
+
exit_pytexmk()
|
|
38
|
+
if args.init_user:
|
|
39
|
+
if cp.init_user_config(args.force):
|
|
40
|
+
console.print(
|
|
41
|
+
_("[bold green]已生成用户配置文件 ~/.pytexmkrc[/bold green]")
|
|
42
|
+
)
|
|
43
|
+
exit_pytexmk()
|
|
44
|
+
if args.list_subprojects:
|
|
45
|
+
_list_subprojects(cp)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def _open_readme(logger) -> None:
|
|
49
|
+
"""打开本地 README.html;出错只记录日志,不中断退出流程。"""
|
|
50
|
+
try:
|
|
51
|
+
app_path = get_app_path()
|
|
52
|
+
readme_path = app_path / "data" / "README.html"
|
|
53
|
+
if readme_path.exists():
|
|
54
|
+
console.print(_("[bold green]正在打开 README 文件...[/bold green]"))
|
|
55
|
+
local_path = f"file://{readme_path.resolve().as_posix()}"
|
|
56
|
+
logger.info(_("README 本地路径: %(args)s") % {"args": local_path})
|
|
57
|
+
webbrowser.open(local_path)
|
|
58
|
+
else:
|
|
59
|
+
logger.error(_("README.html 文件未找到: ") + str(readme_path))
|
|
60
|
+
except Exception as e: # noqa: BLE001
|
|
61
|
+
logger.error(_("打开 README 文件出错: ") + str(e))
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def _list_subprojects(cp: ConfigParser) -> None:
|
|
65
|
+
"""发现子项目并输出清单,同时把结果写回根 .pytexmkrc 的 [subprojects] 段。"""
|
|
66
|
+
root_path = Path.cwd()
|
|
67
|
+
entries = discover_subprojects(root_path, cp.load_config(root_path))
|
|
68
|
+
rc_path = root_path / ".pytexmkrc"
|
|
69
|
+
if rc_path.exists():
|
|
70
|
+
write_subprojects_to_rc(rc_path, entries)
|
|
71
|
+
console.print(
|
|
72
|
+
_("[bold green]已更新 .pytexmkrc 中的 \\[subprojects\\] 段[/bold green]")
|
|
73
|
+
)
|
|
74
|
+
else:
|
|
75
|
+
console.print(
|
|
76
|
+
_("[yellow]未找到根 .pytexmkrc , 请先运行 pytexmk -i 后再运行 -ls[/yellow]")
|
|
77
|
+
)
|
|
78
|
+
print_subproject_table(entries)
|
|
79
|
+
exit_pytexmk()
|