fd-open-data-protocol 0.5.0__tar.gz → 0.5.1__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.
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.1}/PKG-INFO +1 -1
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.1}/fd_open_data_protocol/__init__.py +1 -1
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.1}/fd_open_data_protocol/line_ops/assemble.py +11 -2
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.1}/fd_open_data_protocol/line_ops/client.py +7 -1
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.1}/fd_open_data_protocol/line_ops/wellknown.py +11 -6
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.1}/fd_open_data_protocol.egg-info/PKG-INFO +1 -1
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.1}/tests/test_line_ops.py +39 -0
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.1}/LICENSE +0 -0
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.1}/README.md +0 -0
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.1}/fd_open_data_protocol/conformance_adapter.py +0 -0
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.1}/fd_open_data_protocol/constants.py +0 -0
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.1}/fd_open_data_protocol/line_ops/__init__.py +0 -0
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.1}/fd_open_data_protocol/line_ops/auth_gate.py +0 -0
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.1}/fd_open_data_protocol/line_ops/config.py +0 -0
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.1}/fd_open_data_protocol/loader.py +0 -0
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.1}/fd_open_data_protocol/openalex_provider.py +0 -0
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.1}/fd_open_data_protocol/provider.py +0 -0
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.1}/fd_open_data_protocol/registry.py +0 -0
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.1}/fd_open_data_protocol/registry_cli.py +0 -0
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.1}/fd_open_data_protocol/registry_store.py +0 -0
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.1}/fd_open_data_protocol/schema.py +0 -0
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.1}/fd_open_data_protocol/surface_report.py +0 -0
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.1}/fd_open_data_protocol/surface_selfcheck.py +0 -0
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.1}/fd_open_data_protocol/vocabulary/alignment/foundation.yaml +0 -0
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.1}/fd_open_data_protocol/vocabulary/concepts.yaml +0 -0
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.1}/fd_open_data_protocol/vocabulary/crosswalks/datacommons-worldbank.yaml +0 -0
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.1}/fd_open_data_protocol/vocabulary/entity_types.yaml +0 -0
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.1}/fd_open_data_protocol/vocabulary/event_types.yaml +0 -0
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.1}/fd_open_data_protocol/vocabulary/qualifiers.yaml +0 -0
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.1}/fd_open_data_protocol/vocabulary/relation_types.yaml +0 -0
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.1}/fd_open_data_protocol/vocabulary/units.yaml +0 -0
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.1}/fd_open_data_protocol/vocabulary.py +0 -0
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.1}/fd_open_data_protocol.egg-info/SOURCES.txt +0 -0
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.1}/fd_open_data_protocol.egg-info/dependency_links.txt +0 -0
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.1}/fd_open_data_protocol.egg-info/entry_points.txt +0 -0
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.1}/fd_open_data_protocol.egg-info/requires.txt +0 -0
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.1}/fd_open_data_protocol.egg-info/top_level.txt +0 -0
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.1}/pyproject.toml +0 -0
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.1}/setup.cfg +0 -0
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.1}/tests/test_loader.py +0 -0
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.1}/tests/test_openalex_provider.py +0 -0
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.1}/tests/test_registry_pipeline.py +0 -0
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.1}/tests/test_registry_schema.py +0 -0
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.1}/tests/test_schema_vocabulary.py +0 -0
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.1}/tests/test_surface_report.py +0 -0
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.1}/tests/test_surface_selfcheck.py +0 -0
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.1}/tests/test_vocabulary.py +0 -0
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.1}/tests/test_vocabulary_additive.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: fd-open-data-protocol
|
|
3
|
-
Version: 0.5.
|
|
3
|
+
Version: 0.5.1
|
|
4
4
|
Summary: The open-data datasource protocol: a manifest contract a datasource exposes to be ingested by fd-open-data-mcp (or any consumer).
|
|
5
5
|
Author: FindDataOfficial
|
|
6
6
|
License: MIT
|
|
@@ -22,6 +22,8 @@ def assemble(
|
|
|
22
22
|
auth_cache_ttl_seconds: float = 60.0,
|
|
23
23
|
mcp_path: str = "/mcp",
|
|
24
24
|
enable_surface_report: bool = True,
|
|
25
|
+
gate_cls: Callable[[Any, AuthGate], Any] | None = None,
|
|
26
|
+
manifest_anchor: str | None = None,
|
|
25
27
|
):
|
|
26
28
|
"""返回完整 ASGI app:/health 与线自描述免门,其余走鉴权门(无 Bearer 拒)。
|
|
27
29
|
|
|
@@ -30,12 +32,19 @@ def assemble(
|
|
|
30
32
|
:param mcp_path: MCP 端点路径
|
|
31
33
|
:param enable_surface_report: 是否在首请求触发 `surface_report.ensure_started`。
|
|
32
34
|
该机制要求服务对象带 `_surface_report` 属性;本模块会初始化它。
|
|
35
|
+
:param gate_cls: 鉴权门中间件类,签名 `(app, gate)`。默认用共享实现;
|
|
36
|
+
消费仓传入自己 re-export 的那个名字,使测试 `monkeypatch.setattr(server,
|
|
37
|
+
"AuthGateMiddleware", …)` 能真的替换掉本函数里用的类。
|
|
38
|
+
:param manifest_anchor: 用来定位消费仓 `line-manifest.json` 的文件路径。
|
|
39
|
+
**消费仓必须传自己的**(通常 `__file__`):不传就按 protocol 包的
|
|
40
|
+
位置推导,仓根会算错(见 `wellknown.manifest_candidates`)。
|
|
33
41
|
"""
|
|
34
42
|
mcp = build_mcp()
|
|
35
43
|
if enable_surface_report and not hasattr(mcp, "_surface_report"):
|
|
36
44
|
mcp._surface_report = "not_configured"
|
|
37
45
|
mcp_app = mcp.http_app(path=mcp_path)
|
|
38
|
-
|
|
46
|
+
_gate_cls = gate_cls or AuthGateMiddleware
|
|
47
|
+
gate = _gate_cls(mcp_app, AuthGate(auth_cache_ttl_seconds))
|
|
39
48
|
|
|
40
49
|
if enable_surface_report:
|
|
41
50
|
from fd_open_data_protocol import surface_report as _sr
|
|
@@ -61,7 +70,7 @@ def assemble(
|
|
|
61
70
|
# 线自描述:公开元数据,必须在鉴权门**之前**应答(与 /health 同理),
|
|
62
71
|
# 否则平台/客户在未持有本线凭据时连「这条线认哪些钥匙」都读不到。
|
|
63
72
|
if path == WELL_KNOWN_PATH.rstrip("/"):
|
|
64
|
-
status, body, headers = manifest_response()
|
|
73
|
+
status, body, headers = manifest_response(manifest_anchor)
|
|
65
74
|
await send({"type": "http.response.start", "status": status,
|
|
66
75
|
"headers": headers + [(b"content-length", str(len(body)).encode())]})
|
|
67
76
|
await send({"type": "http.response.body", "body": body})
|
{fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.1}/fd_open_data_protocol/line_ops/client.py
RENAMED
|
@@ -83,6 +83,11 @@ class LineClient:
|
|
|
83
83
|
raise self._error(
|
|
84
84
|
"unreachable", None, f"{self._label}服务不可达:{type(e).__name__}: {e}"
|
|
85
85
|
) from e
|
|
86
|
+
return self._resolve(res)
|
|
87
|
+
|
|
88
|
+
def _resolve(self, res) -> Any:
|
|
89
|
+
"""状态码 → 值或错误。子类扩额外端点(如 multipart 上传)时复用它,
|
|
90
|
+
免得把这张映射表复制一遍(复制必然漂移)。"""
|
|
86
91
|
if res.status_code == 401:
|
|
87
92
|
raise self._error("unauthorized", 401, _detail(res))
|
|
88
93
|
if res.status_code == 402:
|
|
@@ -98,7 +103,8 @@ class LineClient:
|
|
|
98
103
|
if res.status_code == 429:
|
|
99
104
|
raise self._error("rate_limited", 429, _detail(res))
|
|
100
105
|
if res.status_code >= 500:
|
|
101
|
-
raise self._error("unreachable", res.status_code,
|
|
106
|
+
raise self._error("unreachable", res.status_code,
|
|
107
|
+
f"{self._label}服务错误:{_detail(res)}")
|
|
102
108
|
if res.status_code >= 400:
|
|
103
109
|
raise self._error("invalid", res.status_code, _detail(res))
|
|
104
110
|
if not res.content:
|
|
@@ -15,18 +15,23 @@ LINE_MANIFEST_ENV = "LINE_MANIFEST_PATH"
|
|
|
15
15
|
MANIFEST_CACHE_CONTROL = "public, max-age=300"
|
|
16
16
|
|
|
17
17
|
|
|
18
|
-
def manifest_candidates() -> list[Path]:
|
|
18
|
+
def manifest_candidates(anchor: Path | str | None = None) -> list[Path]:
|
|
19
19
|
"""按优先级列出可能放清单的位置(`LINE_MANIFEST_PATH` 一项即封顶)。
|
|
20
20
|
|
|
21
21
|
为什么要链而不是一条:**pip 装进去的包与源码树的 `__file__` 不同**。镜像是
|
|
22
22
|
console script 起的,`__file__` 落在 site-packages,`parents[1]` 根本不是仓根——
|
|
23
23
|
清单就在 `/app/line-manifest.json` 却读不到(lex 线 2026-11-11 真机 404,
|
|
24
24
|
源码运行验不出来)。所以源码树、CWD(镜像 WORKDIR)、与包同级三处依次找。
|
|
25
|
+
|
|
26
|
+
:param anchor: 用来推导「仓根」的文件路径。**消费仓必须传自己的**
|
|
27
|
+
(通常是该仓 `server.py` 的 `__file__`):不传就用本模块的 `__file__`,
|
|
28
|
+
那会指向 protocol 包自己的目录,算出来的仓根是错的(2026-11-25 实测:
|
|
29
|
+
五个消费仓的 `manifest_path()` 全部指到 protocol 包里)。
|
|
25
30
|
"""
|
|
26
31
|
override = os.environ.get(LINE_MANIFEST_ENV)
|
|
27
32
|
if override:
|
|
28
33
|
return [Path(override)]
|
|
29
|
-
here = Path(__file__).resolve()
|
|
34
|
+
here = Path(anchor).resolve() if anchor is not None else Path(__file__).resolve()
|
|
30
35
|
return [
|
|
31
36
|
here.parents[1] / "line-manifest.json", # 源码树 / 镜像里包与清单同根
|
|
32
37
|
Path.cwd() / "line-manifest.json", # pip 装的包:CWD 才是仓根
|
|
@@ -34,23 +39,23 @@ def manifest_candidates() -> list[Path]:
|
|
|
34
39
|
]
|
|
35
40
|
|
|
36
41
|
|
|
37
|
-
def manifest_path() -> Path:
|
|
42
|
+
def manifest_path(anchor: Path | str | None = None) -> Path:
|
|
38
43
|
"""实际取用的清单路径;都不存在时返回首选位置(让 404 能点名期望路径)。"""
|
|
39
|
-
candidates = manifest_candidates()
|
|
44
|
+
candidates = manifest_candidates(anchor)
|
|
40
45
|
for candidate in candidates:
|
|
41
46
|
if candidate.exists():
|
|
42
47
|
return candidate
|
|
43
48
|
return candidates[0]
|
|
44
49
|
|
|
45
50
|
|
|
46
|
-
def manifest_response() -> tuple[int, bytes, list[tuple[bytes, bytes]]]:
|
|
51
|
+
def manifest_response(anchor: Path | str | None = None) -> tuple[int, bytes, list[tuple[bytes, bytes]]]:
|
|
47
52
|
"""(status, body, extra_headers) —— 不读网络、不建会话。
|
|
48
53
|
|
|
49
54
|
缺失=404(该线未发布清单,属配置事实);存在但不可解析=500(属缺陷,不能
|
|
50
55
|
伪装成 404 让调用方以为「本来就没有」)。
|
|
51
56
|
"""
|
|
52
57
|
json_headers = [(b"content-type", b"application/json; charset=utf-8")]
|
|
53
|
-
path = manifest_path()
|
|
58
|
+
path = manifest_path(anchor)
|
|
54
59
|
try:
|
|
55
60
|
raw = path.read_bytes()
|
|
56
61
|
except FileNotFoundError:
|
{fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.1}/fd_open_data_protocol.egg-info/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: fd-open-data-protocol
|
|
3
|
-
Version: 0.5.
|
|
3
|
+
Version: 0.5.1
|
|
4
4
|
Summary: The open-data datasource protocol: a manifest contract a datasource exposes to be ingested by fd-open-data-mcp (or any consumer).
|
|
5
5
|
Author: FindDataOfficial
|
|
6
6
|
License: MIT
|
|
@@ -130,3 +130,42 @@ def test_two_lines_dont_share_env():
|
|
|
130
130
|
L = make_settings_class("LEX_OPS", "https://lex.example")
|
|
131
131
|
assert W.from_env({"LEX_OPS_BASE_URL": "https://lex.example"}).base_url == "https://wire.example"
|
|
132
132
|
assert L.from_env({"WIRE_OPS_BASE_URL": "https://wire.example"}).base_url == "https://lex.example"
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
# ── wellknown 的 anchor ───────────────────────────────────────────────────
|
|
136
|
+
|
|
137
|
+
def test_manifest_candidates_anchor_controls_repo_root(tmp_path):
|
|
138
|
+
"""anchor 决定仓根:传消费仓的 server.py,清单路径就在那个仓里。
|
|
139
|
+
|
|
140
|
+
这个参数是本模块的**必要**接口而不是可选装饰:不传 anchor 时用 protocol 包自己的
|
|
141
|
+
`__file__` 推仓根,会把五个消费仓的清单指到 fd_open_data_protocol/ 下(2026-11-25
|
|
142
|
+
在 lex-ops 的 CI 上实测:manifest_path() 返回 protocol 包里的路径)。
|
|
143
|
+
"""
|
|
144
|
+
from fd_open_data_protocol.line_ops.wellknown import manifest_candidates
|
|
145
|
+
|
|
146
|
+
fake_repo = tmp_path / "wire_ops_mcp"
|
|
147
|
+
fake_repo.mkdir()
|
|
148
|
+
anchor = fake_repo / "server.py"
|
|
149
|
+
anchor.write_text("")
|
|
150
|
+
cands = manifest_candidates(anchor)
|
|
151
|
+
assert cands[0] == fake_repo.parent / "line-manifest.json", cands
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
def test_manifest_path_env_override_wins(tmp_path, monkeypatch):
|
|
155
|
+
from fd_open_data_protocol.line_ops.wellknown import LINE_MANIFEST_ENV, manifest_path
|
|
156
|
+
|
|
157
|
+
target = tmp_path / "explicit.json"
|
|
158
|
+
target.write_text("{}")
|
|
159
|
+
monkeypatch.setenv(LINE_MANIFEST_ENV, str(target))
|
|
160
|
+
assert manifest_path() == target
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
def test_assemble_accepts_gate_cls_and_manifest_anchor():
|
|
164
|
+
"""assemble 的参数是消费仓的契约:gate_cls 让测试能替换门,manifest_anchor 定仓根。"""
|
|
165
|
+
import inspect
|
|
166
|
+
|
|
167
|
+
from fd_open_data_protocol.line_ops import assemble
|
|
168
|
+
|
|
169
|
+
params = inspect.signature(assemble).parameters
|
|
170
|
+
assert "gate_cls" in params
|
|
171
|
+
assert "manifest_anchor" in params
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.1}/fd_open_data_protocol/constants.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.1}/fd_open_data_protocol/line_ops/config.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.1}/fd_open_data_protocol/provider.py
RENAMED
|
File without changes
|
{fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.1}/fd_open_data_protocol/registry.py
RENAMED
|
File without changes
|
{fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.1}/fd_open_data_protocol/registry_cli.py
RENAMED
|
File without changes
|
{fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.1}/fd_open_data_protocol/registry_store.py
RENAMED
|
File without changes
|
|
File without changes
|
{fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.1}/fd_open_data_protocol/surface_report.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.1}/fd_open_data_protocol/vocabulary.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.1}/tests/test_vocabulary_additive.py
RENAMED
|
File without changes
|