fix: 运行方式改回脚本并自注入项目根,修复 Windows No module named 'src'

- 现象:Windows(Python 3.7) python -m src.main 报 No module named 'src',
  即便 cwd 在项目根、src/__init__.py 存在。
- 根因:该环境运行时不把当前目录加入 sys.path,python -m 找不到 cwd 下的 src 包。
- 修复:
  - src/main.py 启动时自注入项目根到 sys.path,不依赖运行环境配置;
  - 运行方式从 python -m src.main 改回脚本方式 python src/main.py;
  - dev.bat 恢复 CRLF 行尾并改用 python src\main.py;
  - 00/03/05/current-state 文档命令同步。

验证:WSL 下从不含 src 的目录脚本方式运行 exit=0;unittest 17 passed。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
chengma
2026-06-24 17:48:35 +08:00
co-authored by Claude Opus 4.8
parent b1e38ffd7a
commit c204fc205c
7 changed files with 30 additions and 10 deletions
+1 -1
View File
@@ -115,7 +115,7 @@ MVP 不做:
```powershell
python -m compileall src
python -m unittest discover -s tests -t .
python -m src.main
python src/main.py
```
说明:
+2 -2
View File
@@ -38,7 +38,7 @@
| 创建虚拟环境 | `python -m venv .venv` |
| 激活虚拟环境 | `.venv\Scripts\Activate.ps1` |
| 安装依赖 | `pip install -r requirements.txt` |
| 本地运行 | `python -m src.main` |
| 本地运行 | `python src/main.py` |
| 测试 | `python -m unittest discover -s tests -t .` |
| 语法检查 | `python -m compileall src` |
| 打包(待 T-402) | `pyinstaller app.spec` |
@@ -49,7 +49,7 @@ Windows PowerShell:
python -m venv .venv
.venv\Scripts\Activate.ps1
pip install -r requirements.txt
python -m src.main
python src/main.py
python -m unittest discover -s tests -t .
```
+1 -1
View File
@@ -78,7 +78,7 @@
```powershell
python -m compileall src
python -m unittest discover -s tests -t .
python -m src.main
python src/main.py
```
## 8. 绝不
+1 -1
View File
@@ -39,7 +39,7 @@
```powershell
# 本地运行入口
python -m src.main
python src/main.py
# 测试
python -m unittest discover -s tests -t .