datainfra 0.7.0__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.
- datainfra-0.7.0/LICENSE +21 -0
- datainfra-0.7.0/PKG-INFO +122 -0
- datainfra-0.7.0/README.md +87 -0
- datainfra-0.7.0/pyproject.toml +127 -0
- datainfra-0.7.0/setup.cfg +4 -0
- datainfra-0.7.0/src/datainfra/__init__.py +119 -0
- datainfra-0.7.0/src/datainfra/__main__.py +235 -0
- datainfra-0.7.0/src/datainfra/_version.py +13 -0
- datainfra-0.7.0/src/datainfra/catalogs/__init__.py +19 -0
- datainfra-0.7.0/src/datainfra/catalogs/registry.py +132 -0
- datainfra-0.7.0/src/datainfra/contract/__init__.py +111 -0
- datainfra-0.7.0/src/datainfra/contract/dataset.py +314 -0
- datainfra-0.7.0/src/datainfra/contract/errors.py +535 -0
- datainfra-0.7.0/src/datainfra/contract/ports.py +367 -0
- datainfra-0.7.0/src/datainfra/contract/provenance.py +109 -0
- datainfra-0.7.0/src/datainfra/contract/query.py +100 -0
- datainfra-0.7.0/src/datainfra/contract/records.py +365 -0
- datainfra-0.7.0/src/datainfra/contract/secret.py +125 -0
- datainfra-0.7.0/src/datainfra/contract/write.py +191 -0
- datainfra-0.7.0/src/datainfra/encoder/__init__.py +21 -0
- datainfra-0.7.0/src/datainfra/encoder/json_rows.py +62 -0
- datainfra-0.7.0/src/datainfra/encoder/table_rows.py +94 -0
- datainfra-0.7.0/src/datainfra/export/__init__.py +40 -0
- datainfra-0.7.0/src/datainfra/export/frame.py +91 -0
- datainfra-0.7.0/src/datainfra/export/jsonl.py +109 -0
- datainfra-0.7.0/src/datainfra/export/mcp.py +118 -0
- datainfra-0.7.0/src/datainfra/kernel/__init__.py +21 -0
- datainfra-0.7.0/src/datainfra/kernel/catalog.py +127 -0
- datainfra-0.7.0/src/datainfra/kernel/plan.py +135 -0
- datainfra-0.7.0/src/datainfra/kernel/source.py +783 -0
- datainfra-0.7.0/src/datainfra/policy/__init__.py +58 -0
- datainfra-0.7.0/src/datainfra/policy/engine/__init__.py +34 -0
- datainfra-0.7.0/src/datainfra/policy/engine/auth.py +190 -0
- datainfra-0.7.0/src/datainfra/policy/engine/backoff.py +93 -0
- datainfra-0.7.0/src/datainfra/policy/engine/credentials.py +87 -0
- datainfra-0.7.0/src/datainfra/policy/engine/rate_limit.py +140 -0
- datainfra-0.7.0/src/datainfra/policy/engine/retry.py +121 -0
- datainfra-0.7.0/src/datainfra/policy/engine/token_client.py +142 -0
- datainfra-0.7.0/src/datainfra/policy/schemes/__init__.py +42 -0
- datainfra-0.7.0/src/datainfra/policy/schemes/api_key.py +90 -0
- datainfra-0.7.0/src/datainfra/policy/schemes/base.py +129 -0
- datainfra-0.7.0/src/datainfra/policy/schemes/basic.py +81 -0
- datainfra-0.7.0/src/datainfra/policy/schemes/bearer.py +87 -0
- datainfra-0.7.0/src/datainfra/policy/schemes/hmac_signature.py +116 -0
- datainfra-0.7.0/src/datainfra/policy/schemes/oauth2_client_credentials.py +150 -0
- datainfra-0.7.0/src/datainfra/py.typed +1 -0
- datainfra-0.7.0/src/datainfra/reader/__init__.py +29 -0
- datainfra-0.7.0/src/datainfra/reader/columns.py +97 -0
- datainfra-0.7.0/src/datainfra/reader/csv.py +185 -0
- datainfra-0.7.0/src/datainfra/reader/json.py +141 -0
- datainfra-0.7.0/src/datainfra/reader/mapping.py +67 -0
- datainfra-0.7.0/src/datainfra/reader/records.py +96 -0
- datainfra-0.7.0/src/datainfra/reader/xml.py +156 -0
- datainfra-0.7.0/src/datainfra/sources/__init__.py +30 -0
- datainfra-0.7.0/src/datainfra/sources/csv_file.py +110 -0
- datainfra-0.7.0/src/datainfra/sources/rest_json.py +155 -0
- datainfra-0.7.0/src/datainfra/sources/rss.py +115 -0
- datainfra-0.7.0/src/datainfra/sources/sqlite.py +121 -0
- datainfra-0.7.0/src/datainfra/transport/__init__.py +34 -0
- datainfra-0.7.0/src/datainfra/transport/callable.py +89 -0
- datainfra-0.7.0/src/datainfra/transport/csv.py +299 -0
- datainfra-0.7.0/src/datainfra/transport/file.py +131 -0
- datainfra-0.7.0/src/datainfra/transport/http.py +633 -0
- datainfra-0.7.0/src/datainfra/transport/memory.py +150 -0
- datainfra-0.7.0/src/datainfra/transport/sdk.py +153 -0
- datainfra-0.7.0/src/datainfra/transport/sql.py +249 -0
- datainfra-0.7.0/src/datainfra.egg-info/PKG-INFO +122 -0
- datainfra-0.7.0/src/datainfra.egg-info/SOURCES.txt +72 -0
- datainfra-0.7.0/src/datainfra.egg-info/dependency_links.txt +1 -0
- datainfra-0.7.0/src/datainfra.egg-info/entry_points.txt +2 -0
- datainfra-0.7.0/src/datainfra.egg-info/requires.txt +12 -0
- datainfra-0.7.0/src/datainfra.egg-info/top_level.txt +1 -0
- datainfra-0.7.0/tests/test_check_composition.py +128 -0
- datainfra-0.7.0/tests/test_check_imports.py +244 -0
datainfra-0.7.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Abigail Williams
|
|
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.
|
datainfra-0.7.0/PKG-INFO
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: datainfra
|
|
3
|
+
Version: 0.7.0
|
|
4
|
+
Summary: One pipeline for every data source: transport, auth, paging and decoding behind a single interface
|
|
5
|
+
Author-email: AbigailWilliams1692 <alfred.xy1020@gmail.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/AbigailWilliams1692/data_infrastructure
|
|
8
|
+
Project-URL: Issues, https://github.com/AbigailWilliams1692/data_infrastructure/issues
|
|
9
|
+
Project-URL: Changelog, https://github.com/AbigailWilliams1692/data_infrastructure/blob/main/CHANGELOG.md
|
|
10
|
+
Keywords: data,etl,data-source,pagination,oauth2,adapter
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
19
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
20
|
+
Classifier: Typing :: Typed
|
|
21
|
+
Requires-Python: >=3.12
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
License-File: LICENSE
|
|
24
|
+
Provides-Extra: pandas
|
|
25
|
+
Requires-Dist: pandas>=2.2; extra == "pandas"
|
|
26
|
+
Provides-Extra: dev
|
|
27
|
+
Requires-Dist: pytest>=8.0; extra == "dev"
|
|
28
|
+
Requires-Dist: pytest-cov>=5.0; extra == "dev"
|
|
29
|
+
Requires-Dist: ruff>=0.5; extra == "dev"
|
|
30
|
+
Requires-Dist: mypy>=1.10; extra == "dev"
|
|
31
|
+
Requires-Dist: build>=1.2; extra == "dev"
|
|
32
|
+
Requires-Dist: twine>=5.0; extra == "dev"
|
|
33
|
+
Requires-Dist: pre-commit>=3.7; extra == "dev"
|
|
34
|
+
Dynamic: license-file
|
|
35
|
+
|
|
36
|
+
# datainfra
|
|
37
|
+
|
|
38
|
+
同一个接口,接所有数据源。传输、鉴权、分页、编解码、限流、重试全部收进管道,新增数据源只新增文件。
|
|
39
|
+
|
|
40
|
+
```python
|
|
41
|
+
from datainfra.sources import CsvFileSource
|
|
42
|
+
|
|
43
|
+
source = CsvFileSource("examples/data")
|
|
44
|
+
batch = source.fetch("file.bars") # → 带 schema 与出处的行集
|
|
45
|
+
|
|
46
|
+
frame = batch.to_dataframe() # 需要 pandas 时再装上
|
|
47
|
+
rows = batch.to_records() # 零依赖:列名 → 值的映射
|
|
48
|
+
text = batch.to_json() # 或 to_jsonl():一行一个对象
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## 装什么
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
pip install datainfra # 核心,零第三方依赖
|
|
55
|
+
pip install "datainfra[pandas]" # 需要 DataFrame 时
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Python 要求 `>=3.12`。
|
|
59
|
+
|
|
60
|
+
## 它解决什么
|
|
61
|
+
|
|
62
|
+
同一个逻辑请求,背后可能是不同的东西:
|
|
63
|
+
|
|
64
|
+
| 场景 | 你要写的 | 库替你做的 |
|
|
65
|
+
| --- | --- | --- |
|
|
66
|
+
| 读本地 CSV | 一份 `DatasetSpec` | 读文件、按类型转换、校验列 |
|
|
67
|
+
| 读 SQLite 表 | 一行 `SqliteSource(conn)` | 拼 SQL、offset 翻页、列名映射 |
|
|
68
|
+
| 调 REST API | 一份 `DatasetSpec` + 字段映射 | 路径模板、`Link` 翻页、状态码分类 |
|
|
69
|
+
| 带 OAuth2 的行情 API | 一个 `AuthManager` | 取令牌、缓存、临期刷新、401 续期一次 |
|
|
70
|
+
| 写回数据库 / 接口 | 一个 `WriteSpec` | 切批、编码、发送、回执、幂等判断 |
|
|
71
|
+
| 交给 pandas 或 Agent | 一个 `batch.to_dataframe()` / `tool_specs` | 类型转换、JSON Schema 描述 |
|
|
72
|
+
|
|
73
|
+
## 四件事是一等公民
|
|
74
|
+
|
|
75
|
+
- **目录**:`source.catalog()` 说出「我能提供什么」,机器可读,不需要翻文档。
|
|
76
|
+
- **信封**:所有源都返回 `RecordBatch`,下游换供应商不改代码。
|
|
77
|
+
- **出处**:每个批次带来源、耗时、物理请求数、重试次数、配额等待。
|
|
78
|
+
- **契约**:源必须通过同一套契约测试;不变量由 CI 强制,不靠自觉。
|
|
79
|
+
|
|
80
|
+
## 例子
|
|
81
|
+
|
|
82
|
+
`examples/` 里有七个可直接运行的脚本,从「读一个 CSV」到「接一家新 API」:
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
python examples/01_csv_quickstart.py # 离线
|
|
86
|
+
python examples/02_sqlite_read_write.py # 离线,读写往返
|
|
87
|
+
python examples/05_custom_source.py # 离线,自带模拟供应商
|
|
88
|
+
python examples/06_catalog_and_cli.py # 离线,目录 / MCP / CLI
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
其余两个(`03_rest_api.py`、`04_rss_feed.py`)走真实网络,失败时会打印诊断而不是堆栈。
|
|
92
|
+
|
|
93
|
+
命令行复用同一个注册表:
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
datainfra --module my_project.registry catalog # 或 python -m datainfra ...
|
|
97
|
+
datainfra --module my_project.registry fetch \
|
|
98
|
+
--source files --dataset file.bars --format jsonl
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## 明确不做
|
|
102
|
+
|
|
103
|
+
不做服务、不做数仓、不做调度、不做推送订阅(WebSocket / Kafka)与 CDC。库只回答
|
|
104
|
+
「怎么取一次、怎么写一次」,其余交给调用方。
|
|
105
|
+
|
|
106
|
+
## 文档
|
|
107
|
+
|
|
108
|
+
- `docs/README.md` — 交接入口:当前状态、能力表、命令、索引
|
|
109
|
+
- `docs/architecture.md` — 分层边界与模块清单
|
|
110
|
+
- `docs/notes/design-v1.md` — 设计稿:六根轴、不变量、阶段计划
|
|
111
|
+
- `docs/adr/` — 十三篇决策记录,每篇含被否决方案
|
|
112
|
+
- `docs/tech-debt.md` — 欠账与**刻意取舍**(后者用来挡「顺手优化」)
|
|
113
|
+
|
|
114
|
+
## 开发
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
python -m venv .venv
|
|
118
|
+
.venv/Scripts/python -m pip install -e ".[dev,pandas]"
|
|
119
|
+
python -m pytest -q
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
六道门(依赖方向、见证组合、风格、ruff、mypy、pytest)的命令见 `docs/README.md`。
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# datainfra
|
|
2
|
+
|
|
3
|
+
同一个接口,接所有数据源。传输、鉴权、分页、编解码、限流、重试全部收进管道,新增数据源只新增文件。
|
|
4
|
+
|
|
5
|
+
```python
|
|
6
|
+
from datainfra.sources import CsvFileSource
|
|
7
|
+
|
|
8
|
+
source = CsvFileSource("examples/data")
|
|
9
|
+
batch = source.fetch("file.bars") # → 带 schema 与出处的行集
|
|
10
|
+
|
|
11
|
+
frame = batch.to_dataframe() # 需要 pandas 时再装上
|
|
12
|
+
rows = batch.to_records() # 零依赖:列名 → 值的映射
|
|
13
|
+
text = batch.to_json() # 或 to_jsonl():一行一个对象
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## 装什么
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
pip install datainfra # 核心,零第三方依赖
|
|
20
|
+
pip install "datainfra[pandas]" # 需要 DataFrame 时
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Python 要求 `>=3.12`。
|
|
24
|
+
|
|
25
|
+
## 它解决什么
|
|
26
|
+
|
|
27
|
+
同一个逻辑请求,背后可能是不同的东西:
|
|
28
|
+
|
|
29
|
+
| 场景 | 你要写的 | 库替你做的 |
|
|
30
|
+
| --- | --- | --- |
|
|
31
|
+
| 读本地 CSV | 一份 `DatasetSpec` | 读文件、按类型转换、校验列 |
|
|
32
|
+
| 读 SQLite 表 | 一行 `SqliteSource(conn)` | 拼 SQL、offset 翻页、列名映射 |
|
|
33
|
+
| 调 REST API | 一份 `DatasetSpec` + 字段映射 | 路径模板、`Link` 翻页、状态码分类 |
|
|
34
|
+
| 带 OAuth2 的行情 API | 一个 `AuthManager` | 取令牌、缓存、临期刷新、401 续期一次 |
|
|
35
|
+
| 写回数据库 / 接口 | 一个 `WriteSpec` | 切批、编码、发送、回执、幂等判断 |
|
|
36
|
+
| 交给 pandas 或 Agent | 一个 `batch.to_dataframe()` / `tool_specs` | 类型转换、JSON Schema 描述 |
|
|
37
|
+
|
|
38
|
+
## 四件事是一等公民
|
|
39
|
+
|
|
40
|
+
- **目录**:`source.catalog()` 说出「我能提供什么」,机器可读,不需要翻文档。
|
|
41
|
+
- **信封**:所有源都返回 `RecordBatch`,下游换供应商不改代码。
|
|
42
|
+
- **出处**:每个批次带来源、耗时、物理请求数、重试次数、配额等待。
|
|
43
|
+
- **契约**:源必须通过同一套契约测试;不变量由 CI 强制,不靠自觉。
|
|
44
|
+
|
|
45
|
+
## 例子
|
|
46
|
+
|
|
47
|
+
`examples/` 里有七个可直接运行的脚本,从「读一个 CSV」到「接一家新 API」:
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
python examples/01_csv_quickstart.py # 离线
|
|
51
|
+
python examples/02_sqlite_read_write.py # 离线,读写往返
|
|
52
|
+
python examples/05_custom_source.py # 离线,自带模拟供应商
|
|
53
|
+
python examples/06_catalog_and_cli.py # 离线,目录 / MCP / CLI
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
其余两个(`03_rest_api.py`、`04_rss_feed.py`)走真实网络,失败时会打印诊断而不是堆栈。
|
|
57
|
+
|
|
58
|
+
命令行复用同一个注册表:
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
datainfra --module my_project.registry catalog # 或 python -m datainfra ...
|
|
62
|
+
datainfra --module my_project.registry fetch \
|
|
63
|
+
--source files --dataset file.bars --format jsonl
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## 明确不做
|
|
67
|
+
|
|
68
|
+
不做服务、不做数仓、不做调度、不做推送订阅(WebSocket / Kafka)与 CDC。库只回答
|
|
69
|
+
「怎么取一次、怎么写一次」,其余交给调用方。
|
|
70
|
+
|
|
71
|
+
## 文档
|
|
72
|
+
|
|
73
|
+
- `docs/README.md` — 交接入口:当前状态、能力表、命令、索引
|
|
74
|
+
- `docs/architecture.md` — 分层边界与模块清单
|
|
75
|
+
- `docs/notes/design-v1.md` — 设计稿:六根轴、不变量、阶段计划
|
|
76
|
+
- `docs/adr/` — 十三篇决策记录,每篇含被否决方案
|
|
77
|
+
- `docs/tech-debt.md` — 欠账与**刻意取舍**(后者用来挡「顺手优化」)
|
|
78
|
+
|
|
79
|
+
## 开发
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
python -m venv .venv
|
|
83
|
+
.venv/Scripts/python -m pip install -e ".[dev,pandas]"
|
|
84
|
+
python -m pytest -q
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
六道门(依赖方向、见证组合、风格、ruff、mypy、pytest)的命令见 `docs/README.md`。
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
# 77 起支持 PEP 639 的 license 表达式,无需再用 license = { text = "MIT" } 的老写法
|
|
3
|
+
requires = ["setuptools>=77"]
|
|
4
|
+
build-backend = "setuptools.build_meta"
|
|
5
|
+
|
|
6
|
+
[project]
|
|
7
|
+
name = "datainfra"
|
|
8
|
+
dynamic = ["version"]
|
|
9
|
+
description = "One pipeline for every data source: transport, auth, paging and decoding behind a single interface"
|
|
10
|
+
readme = "README.md"
|
|
11
|
+
requires-python = ">=3.12"
|
|
12
|
+
license = "MIT"
|
|
13
|
+
license-files = ["LICENSE"]
|
|
14
|
+
authors = [{ name = "AbigailWilliams1692", email = "alfred.xy1020@gmail.com" }]
|
|
15
|
+
keywords = ["data", "etl", "data-source", "pagination", "oauth2", "adapter"]
|
|
16
|
+
# 0.x 阶段按 Beta 申报:Pre-Alpha 会让下游在 PyPI 上直接跳过
|
|
17
|
+
classifiers = [
|
|
18
|
+
"Development Status :: 4 - Beta",
|
|
19
|
+
"Intended Audience :: Developers",
|
|
20
|
+
"Operating System :: OS Independent",
|
|
21
|
+
"Programming Language :: Python :: 3",
|
|
22
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
23
|
+
"Programming Language :: Python :: 3.12",
|
|
24
|
+
"Programming Language :: Python :: 3.13",
|
|
25
|
+
"Programming Language :: Python :: 3.14",
|
|
26
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
27
|
+
"Typing :: Typed",
|
|
28
|
+
]
|
|
29
|
+
# 库的默认依赖必须为空:core 只用标准库,驱动与解码器走 extras(ADR-0001)
|
|
30
|
+
dependencies = []
|
|
31
|
+
|
|
32
|
+
[project.optional-dependencies]
|
|
33
|
+
# 按功能分组,不要把所有东西塞进一个 dev 组;adapter 的 extras 随实现落地再加
|
|
34
|
+
pandas = ["pandas>=2.2"]
|
|
35
|
+
dev = [
|
|
36
|
+
"pytest>=8.0",
|
|
37
|
+
"pytest-cov>=5.0",
|
|
38
|
+
"ruff>=0.5",
|
|
39
|
+
"mypy>=1.10",
|
|
40
|
+
"build>=1.2",
|
|
41
|
+
"twine>=5.0",
|
|
42
|
+
"pre-commit>=3.7",
|
|
43
|
+
]
|
|
44
|
+
|
|
45
|
+
[project.scripts]
|
|
46
|
+
# 与 python -m datainfra 同一个入口;装完即可用短命令
|
|
47
|
+
datainfra = "datainfra.__main__:main"
|
|
48
|
+
|
|
49
|
+
[project.urls]
|
|
50
|
+
Homepage = "https://github.com/AbigailWilliams1692/data_infrastructure"
|
|
51
|
+
Issues = "https://github.com/AbigailWilliams1692/data_infrastructure/issues"
|
|
52
|
+
Changelog = "https://github.com/AbigailWilliams1692/data_infrastructure/blob/main/CHANGELOG.md"
|
|
53
|
+
|
|
54
|
+
[tool.setuptools.packages.find]
|
|
55
|
+
# src layout:仓库根不放包,避免 cwd 遮蔽已安装版本导致的假绿
|
|
56
|
+
where = ["src"]
|
|
57
|
+
include = ["datainfra*"]
|
|
58
|
+
|
|
59
|
+
[tool.setuptools.package-data]
|
|
60
|
+
# 没有 py.typed,mypy 会忽略本库所有类型标注(PEP 561)
|
|
61
|
+
datainfra = ["py.typed"]
|
|
62
|
+
|
|
63
|
+
[tool.setuptools.dynamic]
|
|
64
|
+
# 版本只在 _version.py 里写一次,构建时读取,杜绝两处漂移
|
|
65
|
+
version = { attr = "datainfra._version.__version__" }
|
|
66
|
+
|
|
67
|
+
[tool.ruff]
|
|
68
|
+
line-length = 88
|
|
69
|
+
# requires-python 的语法预算:本机与主测用 3.14,但只允许用 3.12 起步的语法
|
|
70
|
+
target-version = "py312"
|
|
71
|
+
src = ["src", "tests", "scripts", "examples"]
|
|
72
|
+
extend-exclude = [".venv", "build", "dist", "docs"]
|
|
73
|
+
|
|
74
|
+
[tool.ruff.lint]
|
|
75
|
+
select = ["E", "F", "W", "I", "N", "UP", "B", "C4", "SIM", "RET", "ANN", "D", "S"]
|
|
76
|
+
# D100 / D104: banner 承担模块说明职责,包文件也不例外
|
|
77
|
+
# D200: docstring 首行只写三引号是刻意约定
|
|
78
|
+
# D203 / D212: 摘要从第二行开始
|
|
79
|
+
# ANN401: Any 的使用由 check_style.py 复核
|
|
80
|
+
ignore = ["D100", "D104", "D200", "D203", "D212", "ANN401"]
|
|
81
|
+
|
|
82
|
+
[tool.ruff.lint.pydocstyle]
|
|
83
|
+
convention = "pep257"
|
|
84
|
+
|
|
85
|
+
[tool.ruff.lint.per-file-ignores]
|
|
86
|
+
# S101: 测试就是要用 assert
|
|
87
|
+
# S106: 测试里 "token" 是游标值,不是口令
|
|
88
|
+
"tests/**" = ["S101", "S106"]
|
|
89
|
+
# 示例是给人读的:允许 print,允许未使用的函数参数
|
|
90
|
+
# 示例是教学material:允许 print、允许用 assert 演示不变量
|
|
91
|
+
"examples/**" = ["D400", "S101", "S105", "T201"]
|
|
92
|
+
|
|
93
|
+
[tool.mypy]
|
|
94
|
+
python_version = "3.12"
|
|
95
|
+
strict = true
|
|
96
|
+
mypy_path = "src"
|
|
97
|
+
# scripts/ 是正式资产(CI 依赖其退出码),同样纳入类型检查
|
|
98
|
+
files = ["src", "scripts", "examples"]
|
|
99
|
+
warn_unused_ignores = true
|
|
100
|
+
|
|
101
|
+
[tool.pytest.ini_options]
|
|
102
|
+
# 靠 pythonpath 而不是 pip install -e,CI 少一步安装也能暴露 import 错误
|
|
103
|
+
pythonpath = ["src", "scripts"]
|
|
104
|
+
testpaths = ["tests"]
|
|
105
|
+
# 不在 addopts 里挂 --cov:`pytest tests/unit/test_x.py` 这类定向调试会因全局覆盖率
|
|
106
|
+
# 必然失败。门禁命令是 `pytest -q --cov`,阈值由 [tool.coverage.report] 单点提供。
|
|
107
|
+
addopts = "-ra"
|
|
108
|
+
markers = [
|
|
109
|
+
"contract: 源实现必须通过的契约套件",
|
|
110
|
+
"slow: 耗时用例",
|
|
111
|
+
]
|
|
112
|
+
|
|
113
|
+
[tool.coverage.run]
|
|
114
|
+
# 分支覆盖率:只数行数会漏掉「条件永远走同一侧」这类缺陷
|
|
115
|
+
branch = true
|
|
116
|
+
source = ["datainfra"]
|
|
117
|
+
|
|
118
|
+
[tool.coverage.report]
|
|
119
|
+
# 阈值留 3 个点余量:新增代码尚未写测试时,门禁应当提醒而不是阻断发布
|
|
120
|
+
fail_under = 85
|
|
121
|
+
skip_covered = true
|
|
122
|
+
show_missing = true
|
|
123
|
+
exclude_lines = [
|
|
124
|
+
"pragma: no cover",
|
|
125
|
+
"if TYPE_CHECKING:",
|
|
126
|
+
"raise NotImplementedError",
|
|
127
|
+
]
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
################################################################################
|
|
2
|
+
# @Project: datainfra
|
|
3
|
+
# @File Path: src/datainfra/__init__.py
|
|
4
|
+
# @Description: Public surface of the library. Anything absent from
|
|
5
|
+
# __all__ is an implementation detail and may change
|
|
6
|
+
# without a major release.
|
|
7
|
+
# @Creation Date: 2026-12-01
|
|
8
|
+
# @Last Update: 2026-12-01
|
|
9
|
+
################################################################################
|
|
10
|
+
|
|
11
|
+
################################################################################
|
|
12
|
+
# Import Libraries
|
|
13
|
+
################################################################################
|
|
14
|
+
# Local Modules
|
|
15
|
+
from datainfra._version import __version__
|
|
16
|
+
from datainfra.contract import (
|
|
17
|
+
AttemptStats,
|
|
18
|
+
AuthError,
|
|
19
|
+
CapabilityError,
|
|
20
|
+
Cursor,
|
|
21
|
+
DataInfraError,
|
|
22
|
+
DatasetNotFoundError,
|
|
23
|
+
DatasetSpec,
|
|
24
|
+
DecodedPage,
|
|
25
|
+
DecodeError,
|
|
26
|
+
Encoder,
|
|
27
|
+
ErrorStage,
|
|
28
|
+
ExportError,
|
|
29
|
+
Field,
|
|
30
|
+
FieldType,
|
|
31
|
+
Kind,
|
|
32
|
+
MissingCredentialError,
|
|
33
|
+
PageLimitError,
|
|
34
|
+
ParamError,
|
|
35
|
+
ParamSpec,
|
|
36
|
+
PartialWriteError,
|
|
37
|
+
Policies,
|
|
38
|
+
Provenance,
|
|
39
|
+
Query,
|
|
40
|
+
RateLimitError,
|
|
41
|
+
Reader,
|
|
42
|
+
Record,
|
|
43
|
+
RecordBatch,
|
|
44
|
+
RequestView,
|
|
45
|
+
Schema,
|
|
46
|
+
SchemaMismatchError,
|
|
47
|
+
Secret,
|
|
48
|
+
SourceSpec,
|
|
49
|
+
SpecError,
|
|
50
|
+
Transport,
|
|
51
|
+
TransportCapabilities,
|
|
52
|
+
TransportError,
|
|
53
|
+
TransportRequest,
|
|
54
|
+
TransportResponse,
|
|
55
|
+
WriteError,
|
|
56
|
+
WriteMode,
|
|
57
|
+
WriteReceipt,
|
|
58
|
+
WriteSpec,
|
|
59
|
+
)
|
|
60
|
+
from datainfra.kernel import Catalog, Plan, Source, Step
|
|
61
|
+
|
|
62
|
+
# 导入出口层只是为了登记 RecordBatch 的转换方法(to_records / to_dataframe /
|
|
63
|
+
# to_jsonl / to_json)。契约层不能反向依赖它,所以由门面来做这件事:
|
|
64
|
+
# 少了这一行,用户拿到 batch 后调 .to_dataframe() 会得到「没有登记转换器」。
|
|
65
|
+
import datainfra.export # noqa: F401 # isort: skip
|
|
66
|
+
|
|
67
|
+
################################################################################
|
|
68
|
+
# Module Constants
|
|
69
|
+
################################################################################
|
|
70
|
+
# 导出面即契约:不在此列的名字随时可能改名,下游不应直接 import
|
|
71
|
+
__all__ = [
|
|
72
|
+
"AttemptStats",
|
|
73
|
+
"AuthError",
|
|
74
|
+
"CapabilityError",
|
|
75
|
+
"Catalog",
|
|
76
|
+
"Cursor",
|
|
77
|
+
"DataInfraError",
|
|
78
|
+
"DatasetNotFoundError",
|
|
79
|
+
"DatasetSpec",
|
|
80
|
+
"DecodeError",
|
|
81
|
+
"DecodedPage",
|
|
82
|
+
"Encoder",
|
|
83
|
+
"ErrorStage",
|
|
84
|
+
"ExportError",
|
|
85
|
+
"Field",
|
|
86
|
+
"FieldType",
|
|
87
|
+
"Kind",
|
|
88
|
+
"MissingCredentialError",
|
|
89
|
+
"PageLimitError",
|
|
90
|
+
"ParamError",
|
|
91
|
+
"ParamSpec",
|
|
92
|
+
"PartialWriteError",
|
|
93
|
+
"Plan",
|
|
94
|
+
"Policies",
|
|
95
|
+
"Provenance",
|
|
96
|
+
"Query",
|
|
97
|
+
"RateLimitError",
|
|
98
|
+
"Reader",
|
|
99
|
+
"Record",
|
|
100
|
+
"RecordBatch",
|
|
101
|
+
"RequestView",
|
|
102
|
+
"Schema",
|
|
103
|
+
"SchemaMismatchError",
|
|
104
|
+
"Secret",
|
|
105
|
+
"Source",
|
|
106
|
+
"SourceSpec",
|
|
107
|
+
"SpecError",
|
|
108
|
+
"Step",
|
|
109
|
+
"Transport",
|
|
110
|
+
"TransportCapabilities",
|
|
111
|
+
"TransportError",
|
|
112
|
+
"TransportRequest",
|
|
113
|
+
"TransportResponse",
|
|
114
|
+
"WriteError",
|
|
115
|
+
"WriteMode",
|
|
116
|
+
"WriteReceipt",
|
|
117
|
+
"WriteSpec",
|
|
118
|
+
"__version__",
|
|
119
|
+
]
|