wimotek-edge-agent 1.0.6 → 1.0.7

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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Wimotek
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/MANIFEST.in ADDED
@@ -0,0 +1,5 @@
1
+ include README.md
2
+ include LICENSE
3
+ include pyproject.toml
4
+ include setup.py
5
+ recursive-include wimotek_edge_agent *.py py.typed
package/README.md CHANGED
@@ -8,6 +8,7 @@ Commercial-grade edge access control, service bridge, and tunnel agent featuring
8
8
  - [Architecture](#architecture)
9
9
  - [Decision matrix](#decision-matrix)
10
10
  - [Installation & Quickstart](#installation--quickstart)
11
+ - [PyPI 安装与 ModuleNotFoundError 深度排查](#pypi-安装与-modulenotfounderror-深度排查)
11
12
  - [Environment variables](#environment-variables)
12
13
  - [CLI usage](#cli-usage)
13
14
  - [Programmatic usage](#programmatic-usage)
@@ -73,25 +74,158 @@ Commercial-grade edge access control, service bridge, and tunnel agent featuring
73
74
 
74
75
  ## Installation & Quickstart
75
76
 
76
- ### Python Package
77
+ ### 1. PyPI 安装与导入规则
78
+
79
+ > 📌 **关键名称区别**:
80
+ > - **PyPI 仓库包名(用于 pip 安装)**:`wimotek-edge-agent`(中划线 `-`)
81
+ > - **Python 导入包名(用于代码 import)**:`wimotek_edge_agent`(下划线 `_`)
82
+
83
+ 在终端中使用当前 Python 运行环境安装:
77
84
 
78
85
  ```bash
79
- pip install wimotek-edge-agent
86
+ # 推荐做法:使用当前 Python 解释器执行,避免装错环境
87
+ python -m pip install --upgrade wimotek-edge-agent
88
+ ```
89
+
90
+ 在 Python 代码中使用标准导入:
91
+
92
+ ```python
93
+ from wimotek_edge_agent import EdgeAgent, Config, AccessPolicyEngine
80
94
  ```
81
95
 
82
- From source:
96
+ ---
97
+
98
+ ### PyPI 安装与 ModuleNotFoundError 深度排查
99
+
100
+ 如果在上传 PyPI 后本地执行 `from wimotek_edge_agent ...` 报 `ModuleNotFoundError: No module named 'wimotek_edge_agent'`,请按以下 4 种最常见情况逐一排查:
101
+
102
+ #### 🔴 原因 1:Python 运行环境不一致(最常见,占 80%)
103
+ - **根因分析**:
104
+ 在终端中执行的 `pip install` 将包安装到了全局 Python、系统 Python 或 Conda 的 base 环境;而你在 IDE(VS Code、PyCharm、Cursor)或者运行代码时,使用的是项目独立的虚拟环境(例如 `.venv`)。
105
+ - **一键自查命令**:
106
+ 在运行报错的代码同级终端中执行:
107
+ ```bash
108
+ python -c "import sys; print('当前 Python 解释器路径:', sys.executable); print('模块搜索路径:', sys.path)"
109
+ ```
110
+ - **解决方法**:
111
+ 确保使用**执行代码的同一个 Python 解释器**进行安装:
112
+ ```bash
113
+ python -m pip install --upgrade wimotek-edge-agent
114
+ ```
115
+ 如果使用了虚拟环境,先激活虚拟环境再安装:
116
+ ```bash
117
+ # Linux / macOS:
118
+ source .venv/bin/activate
119
+ python -m pip install --upgrade wimotek-edge-agent
120
+
121
+ # Windows (PowerShell / CMD):
122
+ .venv\Scripts\activate
123
+ python -m pip install --upgrade wimotek-edge-agent
124
+ ```
125
+
126
+ ---
127
+
128
+ #### 🔴 原因 2:PyPI 全球 CDN 刷新延迟 或 国内镜像源未同步
129
+ - **根因分析**:
130
+ 1. 上传到 PyPI(通过 `twine upload dist/*`)后,PyPI 主站的全球 Fastly CDN 边缘节点通常需要 1~5 分钟同步刷新。
131
+ 2. 如果你的本地 pip 配置了国内镜像源(如清华源、阿里源、腾讯源),镜像源通常会有几十分钟到数小时的同步周期。如果刚上传就立刻通过镜像源安装,镜像源尚未同步,会提示找不到包或匹配不到版本。
132
+ 3. `pip` 本地存在 HTTP 缓存,可能命中了上传前的 404 记录。
133
+ - **解决方法**:
134
+ 直连 PyPI 官方源,并跳过本地缓存强制安装:
135
+ ```bash
136
+ python -m pip install -i https://pypi.org/simple/ --no-cache-dir --upgrade wimotek-edge-agent
137
+ ```
138
+
139
+ ---
140
+
141
+ #### 🔴 原因 3:打包时生成了“空包”(Empty Wheel 陷阱)
142
+ - **根因分析**:
143
+ 打包工具在执行 `python -m build` 或 `python setup.py bdist_wheel` 时,如果打包配置中未显式声明包路径,生成的 `.whl` 文件可能**只包含元数据 `wimotek_edge_agent-1.0.0.dist-info/`,而漏掉了 `wimotek_edge_agent/` 源码目录**。
144
+ 安装时 pip 会显示安装成功,但 `site-packages` 里其实没有代码目录,因此运行时必然报错 `ModuleNotFoundError`。
145
+ - **一键自查本地构建产物**:
146
+ 在执行打包的机器上检查生成的 `.whl` 和 `.tar.gz` 内容:
147
+ ```bash
148
+ # 检查 wheel 文件内容列表
149
+ unzip -l dist/wimotek_edge_agent-*.whl
150
+
151
+ # 或检查源码 tar 包
152
+ tar -ztvf dist/wimotek_edge_agent-*.tar.gz
153
+ ```
154
+ **正常的文件列表**必须包含以下源码文件:
155
+ ```text
156
+ wimotek_edge_agent/__init__.py
157
+ wimotek_edge_agent/agent.py
158
+ wimotek_edge_agent/config.py
159
+ wimotek_edge_agent/policy.py
160
+ wimotek_edge_agent/trust_store.py
161
+ ...
162
+ wimotek_edge_agent/py.typed
163
+ ```
164
+ 如果列表里全都是 `dist-info/` 开头的文件,而**没有** `wimotek_edge_agent/`,则说明上传的是空包!
165
+ - **彻底根治与重新发布**:
166
+ 本项目已在 `pyproject.toml` 中配置了明确的 setuptools 规则:
167
+ ```toml
168
+ [tool.setuptools]
169
+ packages = ["wimotek_edge_agent"]
170
+
171
+ [tool.setuptools.package-data]
172
+ wimotek_edge_agent = ["py.typed"]
173
+ ```
174
+ 并配备了 `MANIFEST.in` 与 `setup.py` 双重保障。重新打包与发布:
175
+ ```bash
176
+ # 1. 清理所有历史缓存构建目录
177
+ rm -rf dist build *.egg-info
178
+
179
+ # 2. 安装/升级标准构建工具
180
+ python -m pip install --upgrade build twine
181
+
182
+ # 3. 规范打包
183
+ python -m build
184
+
185
+ # 4. 验证 wheel 是否包含代码
186
+ unzip -l dist/*.whl | grep "wimotek_edge_agent/__init__.py"
187
+
188
+ # 5. 上传到 PyPI(注意修改 pyproject.toml 递增版本号,如 1.0.1)
189
+ twine upload dist/*
190
+ ```
191
+
192
+ ---
193
+
194
+ #### 🔴 原因 4:当前工作目录文件遮蔽(Shadowing)
195
+ - **根因分析**:
196
+ Python 会把执行命令的当前目录(`sys.path[0]`)作为最高优先级的模块搜索路径。如果当前目录下碰巧有一个名为 `wimotek_edge_agent.py` 的测试脚本,或者一个空的同名文件夹,Python 会直接加载该文件,导致无法找到内部类和函数。
197
+ - **排查验证**:
198
+ ```bash
199
+ python -c "import wimotek_edge_agent; print('实际加载的文件路径:', wimotek_edge_agent.__file__)"
200
+ ```
201
+ 如果路径指向了当前临时目录而非 `site-packages`,说明发生了路径遮蔽。
202
+
203
+ ---
204
+
205
+ ### 2. 本地源码免上传开发(推荐)
206
+
207
+ 在日常开发、测试或修改功能时,建议在本地项目根目录下使用可编辑模式(Editable Mode)直接安装,无需频繁上传 PyPI:
83
208
 
84
209
  ```bash
85
- git clone https://github.com/wimotek/wimotek-edge-agent.git
86
210
  cd wimotek-edge-agent
87
211
  pip install -e .
88
212
  ```
89
213
 
90
- ### Node.js CLI Runner
214
+ 安装后,本地对 `wimotek_edge_agent/` 目录中代码的任何改动会立即反映在 Python 环境中。验证:
215
+
216
+ ```bash
217
+ python -c "import wimotek_edge_agent; print('版本:', wimotek_edge_agent.__version__, '路径:', wimotek_edge_agent.__file__)"
218
+ ```
219
+
220
+ ---
221
+
222
+ ### 3. Node.js CLI Runner
223
+
224
+ 除了 Python CLI 外,还可通过 npm / npx 直接运行:
91
225
 
92
226
  ```bash
93
227
  npm install -g wimotek-edge-agent
94
- # or directly execute:
228
+ # 或者直接免安装执行:
95
229
  npx wimotek-edge-agent --help
96
230
  ```
97
231
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wimotek-edge-agent",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "description": "Universal Edge Reverse Proxy & Service Bridge Agent CLI Runner",
5
5
  "bin": {
6
6
  "wimotek-edge-agent": "./bin/cli.js",
package/pyproject.toml CHANGED
@@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta"
6
6
 
7
7
  [project]
8
8
  name = "wimotek-edge-agent"
9
- version = "1.0.0.6"
9
+ version = "1.0.0.7"
10
10
  description = "Universal Edge Reverse Proxy & Service Bridge Agent"
11
11
  readme = "README.md"
12
12
  requires-python = ">=3.9"
@@ -42,10 +42,12 @@ wimotek-edge-agent = "wimotek_edge_agent.agent:main"
42
42
  wimotek-agent = "wimotek_edge_agent.agent:main"
43
43
  edge-agent = "wimotek_edge_agent.agent:main"
44
44
 
45
- [tool.setuptools.packages.find]
46
- where = [
47
- ".",
45
+ [tool.setuptools]
46
+ packages = [
47
+ "wimotek_edge_agent",
48
48
  ]
49
- include = [
50
- "wimotek_edge_agent*",
49
+
50
+ [tool.setuptools.package-data]
51
+ wimotek_edge_agent = [
52
+ "py.typed",
51
53
  ]
package/setup.py ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env python3
2
+ """Standard setup.py shim for backward compatibility with older build tools and editable installs."""
3
+ from setuptools import setup, find_packages
4
+
5
+ setup(
6
+ packages=find_packages(include=["wimotek_edge_agent", "wimotek_edge_agent.*"]),
7
+ package_data={
8
+ "wimotek_edge_agent": ["py.typed"],
9
+ },
10
+ )
File without changes