fd-open-data-protocol 0.5.3__tar.gz → 0.5.5__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.
Files changed (49) hide show
  1. {fd_open_data_protocol-0.5.3 → fd_open_data_protocol-0.5.5}/PKG-INFO +1 -1
  2. {fd_open_data_protocol-0.5.3 → fd_open_data_protocol-0.5.5}/fd_open_data_protocol/__init__.py +1 -1
  3. {fd_open_data_protocol-0.5.3 → fd_open_data_protocol-0.5.5}/fd_open_data_protocol/line_ops/wellknown.py +30 -15
  4. {fd_open_data_protocol-0.5.3 → fd_open_data_protocol-0.5.5}/fd_open_data_protocol.egg-info/PKG-INFO +1 -1
  5. {fd_open_data_protocol-0.5.3 → fd_open_data_protocol-0.5.5}/tests/test_line_ops.py +44 -0
  6. {fd_open_data_protocol-0.5.3 → fd_open_data_protocol-0.5.5}/LICENSE +0 -0
  7. {fd_open_data_protocol-0.5.3 → fd_open_data_protocol-0.5.5}/README.md +0 -0
  8. {fd_open_data_protocol-0.5.3 → fd_open_data_protocol-0.5.5}/fd_open_data_protocol/conformance_adapter.py +0 -0
  9. {fd_open_data_protocol-0.5.3 → fd_open_data_protocol-0.5.5}/fd_open_data_protocol/constants.py +0 -0
  10. {fd_open_data_protocol-0.5.3 → fd_open_data_protocol-0.5.5}/fd_open_data_protocol/line_ops/__init__.py +0 -0
  11. {fd_open_data_protocol-0.5.3 → fd_open_data_protocol-0.5.5}/fd_open_data_protocol/line_ops/assemble.py +0 -0
  12. {fd_open_data_protocol-0.5.3 → fd_open_data_protocol-0.5.5}/fd_open_data_protocol/line_ops/auth_gate.py +0 -0
  13. {fd_open_data_protocol-0.5.3 → fd_open_data_protocol-0.5.5}/fd_open_data_protocol/line_ops/client.py +0 -0
  14. {fd_open_data_protocol-0.5.3 → fd_open_data_protocol-0.5.5}/fd_open_data_protocol/line_ops/config.py +0 -0
  15. {fd_open_data_protocol-0.5.3 → fd_open_data_protocol-0.5.5}/fd_open_data_protocol/loader.py +0 -0
  16. {fd_open_data_protocol-0.5.3 → fd_open_data_protocol-0.5.5}/fd_open_data_protocol/openalex_provider.py +0 -0
  17. {fd_open_data_protocol-0.5.3 → fd_open_data_protocol-0.5.5}/fd_open_data_protocol/provider.py +0 -0
  18. {fd_open_data_protocol-0.5.3 → fd_open_data_protocol-0.5.5}/fd_open_data_protocol/registry.py +0 -0
  19. {fd_open_data_protocol-0.5.3 → fd_open_data_protocol-0.5.5}/fd_open_data_protocol/registry_cli.py +0 -0
  20. {fd_open_data_protocol-0.5.3 → fd_open_data_protocol-0.5.5}/fd_open_data_protocol/registry_store.py +0 -0
  21. {fd_open_data_protocol-0.5.3 → fd_open_data_protocol-0.5.5}/fd_open_data_protocol/schema.py +0 -0
  22. {fd_open_data_protocol-0.5.3 → fd_open_data_protocol-0.5.5}/fd_open_data_protocol/surface_report.py +0 -0
  23. {fd_open_data_protocol-0.5.3 → fd_open_data_protocol-0.5.5}/fd_open_data_protocol/surface_selfcheck.py +0 -0
  24. {fd_open_data_protocol-0.5.3 → fd_open_data_protocol-0.5.5}/fd_open_data_protocol/vocabulary/alignment/foundation.yaml +0 -0
  25. {fd_open_data_protocol-0.5.3 → fd_open_data_protocol-0.5.5}/fd_open_data_protocol/vocabulary/concepts.yaml +0 -0
  26. {fd_open_data_protocol-0.5.3 → fd_open_data_protocol-0.5.5}/fd_open_data_protocol/vocabulary/crosswalks/datacommons-worldbank.yaml +0 -0
  27. {fd_open_data_protocol-0.5.3 → fd_open_data_protocol-0.5.5}/fd_open_data_protocol/vocabulary/entity_types.yaml +0 -0
  28. {fd_open_data_protocol-0.5.3 → fd_open_data_protocol-0.5.5}/fd_open_data_protocol/vocabulary/event_types.yaml +0 -0
  29. {fd_open_data_protocol-0.5.3 → fd_open_data_protocol-0.5.5}/fd_open_data_protocol/vocabulary/qualifiers.yaml +0 -0
  30. {fd_open_data_protocol-0.5.3 → fd_open_data_protocol-0.5.5}/fd_open_data_protocol/vocabulary/relation_types.yaml +0 -0
  31. {fd_open_data_protocol-0.5.3 → fd_open_data_protocol-0.5.5}/fd_open_data_protocol/vocabulary/units.yaml +0 -0
  32. {fd_open_data_protocol-0.5.3 → fd_open_data_protocol-0.5.5}/fd_open_data_protocol/vocabulary.py +0 -0
  33. {fd_open_data_protocol-0.5.3 → fd_open_data_protocol-0.5.5}/fd_open_data_protocol.egg-info/SOURCES.txt +0 -0
  34. {fd_open_data_protocol-0.5.3 → fd_open_data_protocol-0.5.5}/fd_open_data_protocol.egg-info/dependency_links.txt +0 -0
  35. {fd_open_data_protocol-0.5.3 → fd_open_data_protocol-0.5.5}/fd_open_data_protocol.egg-info/entry_points.txt +0 -0
  36. {fd_open_data_protocol-0.5.3 → fd_open_data_protocol-0.5.5}/fd_open_data_protocol.egg-info/requires.txt +0 -0
  37. {fd_open_data_protocol-0.5.3 → fd_open_data_protocol-0.5.5}/fd_open_data_protocol.egg-info/top_level.txt +0 -0
  38. {fd_open_data_protocol-0.5.3 → fd_open_data_protocol-0.5.5}/pyproject.toml +0 -0
  39. {fd_open_data_protocol-0.5.3 → fd_open_data_protocol-0.5.5}/setup.cfg +0 -0
  40. {fd_open_data_protocol-0.5.3 → fd_open_data_protocol-0.5.5}/tests/test_drift_inventory.py +0 -0
  41. {fd_open_data_protocol-0.5.3 → fd_open_data_protocol-0.5.5}/tests/test_loader.py +0 -0
  42. {fd_open_data_protocol-0.5.3 → fd_open_data_protocol-0.5.5}/tests/test_openalex_provider.py +0 -0
  43. {fd_open_data_protocol-0.5.3 → fd_open_data_protocol-0.5.5}/tests/test_registry_pipeline.py +0 -0
  44. {fd_open_data_protocol-0.5.3 → fd_open_data_protocol-0.5.5}/tests/test_registry_schema.py +0 -0
  45. {fd_open_data_protocol-0.5.3 → fd_open_data_protocol-0.5.5}/tests/test_schema_vocabulary.py +0 -0
  46. {fd_open_data_protocol-0.5.3 → fd_open_data_protocol-0.5.5}/tests/test_surface_report.py +0 -0
  47. {fd_open_data_protocol-0.5.3 → fd_open_data_protocol-0.5.5}/tests/test_surface_selfcheck.py +0 -0
  48. {fd_open_data_protocol-0.5.3 → fd_open_data_protocol-0.5.5}/tests/test_vocabulary.py +0 -0
  49. {fd_open_data_protocol-0.5.3 → fd_open_data_protocol-0.5.5}/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
3
+ Version: 0.5.5
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
@@ -5,4 +5,4 @@ concept hints + fetch reference) so that fd-open-data-mcp - or any consumer -
5
5
  can ingest it via ``register_datasource``. Ship one manifest file -> the
6
6
  datasource is added; no consumer-side wiring.
7
7
  """
8
- __version__ = "0.5.3"
8
+ __version__ = "0.5.5"
@@ -15,7 +15,7 @@ LINE_MANIFEST_ENV = "LINE_MANIFEST_PATH"
15
15
  MANIFEST_CACHE_CONTROL = "public, max-age=300"
16
16
 
17
17
 
18
- def manifest_candidates(anchor: Path | str | None = None) -> list[Path]:
18
+ def manifest_candidates(anchor: Path | str | None = None, *, up: tuple[int, ...] = (1,)) -> list[Path]:
19
19
  """按优先级列出可能放清单的位置(`LINE_MANIFEST_PATH` 一项即封顶)。
20
20
 
21
21
  为什么要链而不是一条:**pip 装进去的包与源码树的 `__file__` 不同**。镜像是
@@ -33,29 +33,31 @@ def manifest_candidates(anchor: Path | str | None = None) -> list[Path]:
33
33
  return [Path(override)]
34
34
  here = Path(anchor).resolve() if anchor is not None else Path(__file__).resolve()
35
35
  return [
36
- here.parents[1] / "line-manifest.json", # 源码树 / 镜像里包与清单同根
36
+ # Flat layout uses parents[1]; a src/ layout (e.g. paper-trading) needs
37
+ # parents[2] because parents[1] is `src/`. Consumers name their depth.
38
+ *(here.parents[n] / "line-manifest.json" for n in up),
37
39
  Path.cwd() / "line-manifest.json", # pip 装的包:CWD 才是仓根
38
40
  here.parent / "line-manifest.json", # 清单与包同级(兜底)
39
41
  ]
40
42
 
41
43
 
42
- def manifest_path(anchor: Path | str | None = None) -> Path:
44
+ def manifest_path(anchor: Path | str | None = None, *, up: tuple[int, ...] = (1,)) -> Path:
43
45
  """实际取用的清单路径;都不存在时返回首选位置(让 404 能点名期望路径)。"""
44
- candidates = manifest_candidates(anchor)
46
+ candidates = manifest_candidates(anchor, up=up)
45
47
  for candidate in candidates:
46
48
  if candidate.exists():
47
49
  return candidate
48
50
  return candidates[0]
49
51
 
50
52
 
51
- def manifest_response(anchor: Path | str | None = None) -> tuple[int, bytes, list[tuple[bytes, bytes]]]:
53
+ def manifest_response(anchor: Path | str | None = None, *, up: tuple[int, ...] = (1,)) -> tuple[int, bytes, list[tuple[bytes, bytes]]]:
52
54
  """(status, body, extra_headers) —— 不读网络、不建会话。
53
55
 
54
56
  缺失=404(该线未发布清单,属配置事实);存在但不可解析=500(属缺陷,不能
55
57
  伪装成 404 让调用方以为「本来就没有」)。
56
58
  """
57
59
  json_headers = [(b"content-type", b"application/json; charset=utf-8")]
58
- path = manifest_path(anchor)
60
+ path = manifest_path(anchor, up=up)
59
61
  try:
60
62
  raw = path.read_bytes()
61
63
  except FileNotFoundError:
@@ -72,7 +74,7 @@ def manifest_response(anchor: Path | str | None = None) -> tuple[int, bytes, lis
72
74
  ]
73
75
 
74
76
 
75
- def register(mcp, anchor: Path | str | None = None) -> None:
77
+ def register(mcp, anchor: Path | str | None = None, *, up: tuple[int, ...] = (1,)) -> None:
76
78
  """Mount the endpoint on a FastMCP instance (stdio has no HTTP face, so skip).
77
79
 
78
80
  ``custom_route`` is used rather than wrapping ASGI so the route exists in
@@ -84,15 +86,10 @@ def register(mcp, anchor: Path | str | None = None) -> None:
84
86
  ``wellknown.py`` adapter) so the manifest candidate chain resolves
85
87
  against that repo, not against this shared package.
86
88
  """
87
- if not hasattr(mcp, "custom_route"): # pragma: no cover - dependency error
88
- raise RuntimeError(
89
- "fastmcp 缺 custom_route:无法挂 " + WELL_KNOWN_PATH + "(升级依赖,别静默跳过)"
90
- )
91
- @mcp.custom_route(WELL_KNOWN_PATH, methods=["GET"])
92
- async def line_manifest(_request): # noqa: ANN001 - ASGI boundary
93
- from starlette.responses import Response # only the HTTP branch needs it
89
+ from starlette.responses import Response # only the HTTP branch needs it
94
90
 
95
- status, body, extra = manifest_response(anchor)
91
+ def _response() -> "Response":
92
+ status, body, extra = manifest_response(anchor, up=up)
96
93
  headers = {k.decode(): v.decode() for k, v in extra}
97
94
  return Response(
98
95
  content=body,
@@ -100,3 +97,21 @@ def register(mcp, anchor: Path | str | None = None) -> None:
100
97
  media_type="application/json; charset=utf-8",
101
98
  headers=headers,
102
99
  )
100
+
101
+ if hasattr(mcp, "custom_route"):
102
+ @mcp.custom_route(WELL_KNOWN_PATH, methods=["GET"])
103
+ async def line_manifest(_request): # noqa: ANN001 - ASGI boundary
104
+ return _response()
105
+
106
+ return
107
+
108
+ if hasattr(mcp, "get"):
109
+ @mcp.get(WELL_KNOWN_PATH, include_in_schema=False)
110
+ async def line_manifest_route():
111
+ return _response()
112
+
113
+ return
114
+
115
+ raise RuntimeError(
116
+ "应用既没有 custom_route 也没有 get:无法挂 " + WELL_KNOWN_PATH + "(别静默跳过)"
117
+ )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fd-open-data-protocol
3
- Version: 0.5.3
3
+ Version: 0.5.5
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
@@ -207,3 +207,47 @@ def test_register_mounts_the_endpoint_and_serves_the_manifest(tmp_path):
207
207
  ok = asyncio.run(handler(None))
208
208
  assert ok.status_code == 200
209
209
  assert ok.headers.get("cache-control") == wellknown.MANIFEST_CACHE_CONTROL
210
+
211
+
212
+ def test_register_supports_a_fastapi_style_app(tmp_path):
213
+ """paper-trading 是 FastAPI 单进程:register 必须走 app.get,而不是 custom_route。"""
214
+ import asyncio
215
+
216
+ import pytest
217
+
218
+ pytest.importorskip("starlette.responses")
219
+ from fd_open_data_protocol.line_ops import wellknown
220
+
221
+ class FakeApp:
222
+ def __init__(self):
223
+ self.routes = {}
224
+
225
+ def get(self, path, include_in_schema=True):
226
+ def deco(fn):
227
+ self.routes[path] = fn
228
+ return fn
229
+
230
+ return deco
231
+
232
+ repo = tmp_path / "repo"
233
+ (repo / "pkg").mkdir(parents=True)
234
+ anchor = repo / "pkg" / "server.py"
235
+ anchor.write_text("")
236
+ (repo / "line-manifest.json").write_text('{"line": "paper-trading"}')
237
+ app = FakeApp()
238
+ wellknown.register(app, anchor=anchor)
239
+ response = asyncio.run(app.routes[wellknown.WELL_KNOWN_PATH]())
240
+ assert response.status_code == 200
241
+
242
+
243
+ def test_src_layout_uses_a_deeper_parent(tmp_path, monkeypatch):
244
+ """src 布局(src/pkg/wellknown.py)的仓根是 parents[2],由消费仓显式声明。"""
245
+ from fd_open_data_protocol.line_ops import wellknown
246
+
247
+ monkeypatch.delenv(wellknown.LINE_MANIFEST_ENV, raising=False)
248
+ repo = tmp_path / "repo"
249
+ (repo / "src" / "pkg").mkdir(parents=True)
250
+ (repo / "line-manifest.json").write_text("{}")
251
+ anchor = repo / "src" / "pkg" / "wellknown.py"
252
+ anchor.write_text("")
253
+ assert wellknown.manifest_path(anchor, up=(2,)) == repo / "line-manifest.json"