InfinityData
声明式配置语言(.infd / .inft)的 Python 编译器库。
- 编译优先:
.infd是源码,JSON/YAML/TOML 是构建产物 - 模板即约束:模板定义自动注册为约束校验器
- 零信任默认:库默认
deny_all沙盒,显式开放而非事后限制 - 结构化错误:稳定错误码 + 结构化参数 + 多语言渲染
快速使用
uv add infinity_data # 或 pip install infinity-data
from infinity_data import load, safe_load, SandboxConfig, Schema
result = load('app.infd') # 默认零信任
if result.has_errors:
for d in result.diagnostics:
print(d.location, d.code, d.message)
else:
print(result.value) # 降维后的 dict
文档导航
| 文档 | 内容 |
|---|---|
| neo_desg.md | 语言基础设计(语法 / 类型 / 模板 / 约束) |
| extra_desg.md | 库 API / CLI / 生态设计 |
| impl_desg.md | 编译器实现层的取舍与假设 |
官方工具
随库内置两个命令行工具(infd-lsp 语言服务器 + infd-cov 配置转换器),
零依赖手写 JSON-RPC / emitter,直接消费编译器的公开 API
(compile_source / parse_source / RawTokenizer / emit / semantic)。
工具的可选运行依赖(PyYAML / tomli-w)由 tool extra 提供,一次装齐:
uv add 'infinity_data[tool]' # 可选:!file 的 yaml 导入 + infd-cov -f toml 输出
配置转换(infd-cov)
编译 .infd / .inft → 各种配置格式(YAML / JSON / TOML):
infd-cov app.infd # → YAML(stdout,零依赖 emitter)
infd-cov app.infd out.json -f json # → JSON 文件
infd-cov app.infd -f toml # → TOML(需 tomli-w,见 tool extra)
infd-cov app.infd --extract web.spec # → 点分路径提取
cat a.infd | infd-cov -f json # stdin → stdout
--format:yaml(默认,零依赖手写 emitter)/json/toml--extract PATH:点分路径(如web.spec.selector);空 = 整树--severity LEVEL:拒绝阈值(error/warning/info/debug/none,默认error)#env: NAME "VALUE"声明的变量在当前进程缺失时自动注入虚拟值- 演示文件:
examples/app.infd(干净配置)/examples/demo.infd(含故意错误)
语言服务器(LSP)
infd-lsp:零依赖手写 JSON-RPC 2.0 over stdio 语言服务器。
infd-lsp # 作为任意 LSP 客户端的后端
# 或
python -m infinity_data.tools.lsp
已实现的能力
| 能力 | 说明 |
|---|---|
| 诊断 | didOpen/didChange/didSave → publishDiagnostics(精确位置 + 稳定错误码 + 中文消息;UTF-16 对齐) |
| 补全 | 命名空间($ 触发)+ 内置约束名 + 当前文件可见模板名 + 模板字段(含必填/可选)+ 语言关键字 |
| 悬停 | 约束描述、编译产物预览(字段/子字段/模板参数,jsonpath 投影)、被实例化的模板(模板骨架提示在前 + 实例预览在后)、$ 变量值(定义点与调用点)、模板结构骨架(必填/可选 + description 元数据) |
| 文档大纲 | documentSymbol:模板定义(Class)+ 顶层字段(Property) |
| 跳转定义 | definition:模板调用 / !from 导入 / $ 引用(含跨文件) |
| 语义令牌 | semanticTokens:直接用 RawTokenizer 分词(UTF-16 单元对齐;跨行多行字符串按行拆分) |
| 虚拟环境变量 | 扫描 #env: NAME "VALUE" 注释,进程未设置时自动注入虚拟值,避免 env_not_set 中止编译 |
在 VS Code 中使用
在项目 .vscode/settings.json 里用任意支持自定义 LSP 的扩展(如 lspConfig)配置:
{
"lspConfig.servers": [
{ "language": "infd", "cmd": ["infd-lsp"] },
{ "language": "inft", "cmd": ["infd-lsp"] }
]
}
打开 .infd / .inft 文件即可获得:诊断波浪线 + 语法高亮(semantic tokens)+ 补全 + 悬停 + 大纲 + 跳转定义。
端到端演示
uv run python examples/lsp_demo.py # 自动起服务器 + 走一遍握手 + 打印结果
演示文件在 examples/demo.infd(故意含若干错误,展示诊断 / 补全 / 悬停 / 高亮)。
虚拟环境变量(#env 注释)
.infd / .inft 里可以用特殊注释声明环境变量名和虚拟值,工具(LSP / infd-cov)
在当前进程缺失该变量时自动注入,避免 env_not_set 中止编译、吞掉同文件其他诊断:
#env: DEEPSEEK_API_KEY "sk-virtual-key"
!env import DEEPSEEK_API_KEY as ds_key
- 语法:
#env: NAME "VALUE"—— 变量名在前、虚拟值在后 - 真实环境变量优先:进程里已设置时用真实值,只有缺失时才用注释里的虚拟值兜底
- 动机:
infinity_data沙盒在 env 未授权/未设置时会中止编译;用#env声明兜底后, 编辑器/CLI 始终能看到全部诊断(如约束违反、未定义模板)
开发
uv run pytest -q # 测试
uv run ruff check src tests # lint
uv run pyright # 类型检查(strict)
uv run python test.py # 错误报告演示
Metadata
Release files for infinity-data 3.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| infinity_data-3.3.0.tar.gz | 131.2 kB | Without provenance | Details for infinity_data-3.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| infinity_data-3.3.0-py3-none-any.whl | Python 3 | none | any | Details for infinity_data-3.3.0-py3-none-any.whl |
Total release size: 292.2 kB
Release files / infinity_data-3.3.0.tar.gz
| Download URL | infinity_data-3.3.0.tar.gz |
|---|---|
| Size | 131.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7196ce1676b0c0397346b80ec778e7dd441947ada4561cc1fe03672915ca0873
|
|
BLAKE2b-256 checksum How to use checksums |
6ebc5ed7bea6a1572753cbf7f2ae618daed1b9ff534b05bd5ff9be6bee5d1d0c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.24 {"installer":{"name":"uv","version":"0.12.24","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / infinity_data-3.3.0-py3-none-any.whl
| Download URL | infinity_data-3.3.0-py3-none-any.whl |
|---|---|
| Size | 161.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3781528bf59beccf6b0e914f1861d16fb2fa140878655c2d63b48482c3a85f09
|
|
BLAKE2b-256 checksum How to use checksums |
e9f5f81ea09007141d2b3884a208b5c31f045c00ac9a315d025ba26db3c27414
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.24 {"installer":{"name":"uv","version":"0.12.24","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for infinity-data 3.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.