uv-discohy
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseUV-DiscoHy Skill: Modern Python Tooling for Thread Operads
UV-DiscoHy Skill:面向Thread Operad的现代Python工具集
Status: ✅ Production Ready
Trit: 0 (ERGODIC - toolchain neutral)
Toolchain: uv + uvx + ruff
Package: music-topos with discohy_thread_operad
状态:✅ 可用于生产环境
Trit值:0(遍历性 - 工具链中立)
工具链:uv + uvx + ruff
包:music-topos 包含 discohy_thread_operad
Overview
概述
This skill provides the uv/uvx/ruff toolchain integration for the DiscoHy Thread Operad system. It enables:
- Fast dependency management via uv (10-100x faster than pip)
- One-shot tool execution via uvx (no install required)
- Modern linting/formatting via ruff (replaces black, isort, flake8)
- Python packaging via pyproject.toml with hatchling
本Skill为DiscoHy Thread Operad系统提供uv/uvx/ruff工具链集成,实现以下功能:
- 通过uv实现快速依赖管理(比pip快10-100倍)
- 通过uvx实现一次性工具执行(无需安装)
- 通过ruff实现现代化代码检查/格式化(替代black、isort、flake8)
- 通过pyproject.toml与hatchling实现Python打包
Quick Start
快速开始
bash
undefinedbash
undefinedInitialize the environment
初始化环境
just uv-init
just uv-init
Run the DiscoHy operad demo
运行DiscoHy operad示例
just uv-discohy
just uv-discohy
Lint and format
代码检查与格式化
just uv-lint
just uv-format
just uv-lint
just uv-format
Run with specific variant
使用指定变体运行
just uv-discohy-variant 2-transducer
undefinedjust uv-discohy-variant 2-transducer
undefinedUV Commands
UV 命令
Package Management
包管理
bash
undefinedbash
undefinedCreate virtual environment and install dependencies
创建虚拟环境并安装依赖
uv venv
uv pip install -e ".[dev]"
uv venv
uv pip install -e ".[dev]"
Add a dependency
添加依赖
uv pip install discopy>=1.1.0
uv pip install discopy>=1.1.0
Sync all dependencies from pyproject.toml
同步pyproject.toml中的所有依赖
uv pip sync pyproject.toml
uv pip sync pyproject.toml
Show dependency tree
查看依赖树
uv pip tree
undefineduv pip tree
undefinedUVX: One-Shot Tool Execution
UVX:一次性工具执行
bash
undefinedbash
undefinedRun ruff without installing
无需安装即可运行ruff
uvx ruff check src/
uvx ruff check src/
Run pytest without installing
无需安装即可运行pytest
uvx pytest tests/
uvx pytest tests/
Run a specific version
使用指定Python版本运行
uvx --python 3.12 ruff check src/
undefineduvx --python 3.12 ruff check src/
undefinedRuff Configuration
Ruff 配置
From :
pyproject.tomltoml
[tool.ruff]
target-version = "py311"
line-length = 100
indent-width = 4
[tool.ruff.lint]
select = [
"E", # pycodestyle errors
"W", # pycodestyle warnings
"F", # Pyflakes
"I", # isort
"B", # flake8-bugbear
"C4", # flake8-comprehensions
"UP", # pyupgrade
"ARG", # flake8-unused-arguments
"SIM", # flake8-simplify
]
[tool.ruff.format]
quote-style = "double"
indent-style = "space"来自:
pyproject.tomltoml
[tool.ruff]
target-version = "py311"
line-length = 100
indent-width = 4
[tool.ruff.lint]
select = [
"E", # pycodestyle错误
"W", # pycodestyle警告
"F", # Pyflakes
"I", # isort
"B", # flake8-bugbear
"C4", # flake8-comprehensions
"UP", # pyupgrade
"ARG", # flake8-unused-arguments
"SIM", # flake8-simplify
]
[tool.ruff.format]
quote-style = "double"
indent-style = "space"Ruff Commands
Ruff 命令
bash
undefinedbash
undefinedCheck for issues
检查代码问题
ruff check src/ lib/
ruff check src/ lib/
Auto-fix issues
自动修复问题
ruff check --fix src/
ruff check --fix src/
Format code
格式化代码
ruff format src/
ruff format src/
Check and format in one pass
一站式检查与修复
ruff check --fix src/ && ruff format src/
undefinedruff check --fix src/ && ruff format src/
undefinedDiscoHy Thread Operad Integration
DiscoHy Thread Operad 集成
Python API
Python API
python
from discohy_thread_operad import (
RootedColorOperad,
ThreadOperadNode,
OPERAD_VARIANTS,
build_operad_from_threads,
operad_to_mermaid,
)python
from discohy_thread_operad import (
RootedColorOperad,
ThreadOperadNode,
OPERAD_VARIANTS,
build_operad_from_threads,
operad_to_mermaid,
)Build operad from thread list
从线程列表构建operad
threads = [
{"id": "T-root", "title": "Root Thread", "created": 0},
{"id": "T-child", "title": "Child Thread", "created": 1},
]
operad = build_operad_from_threads(threads, variant="dendroidal")
threads = [
{"id": "T-root", "title": "Root Thread", "created": 0},
{"id": "T-child", "title": "Child Thread", "created": 1},
]
operad = build_operad_from_threads(threads, variant="dendroidal")
Switch variant dynamically
动态切换变体
operad.set_variant("2-transducer")
operad.set_variant("2-transducer")
Check GF(3) conservation
检查GF(3)守恒性
gf3 = operad.gf3_conservation()
print(f"Conserved: {gf3['conserved']}")
gf3 = operad.gf3_conservation()
print(f"守恒:{gf3['conserved']}")
Generate Mermaid diagram
生成Mermaid图
mermaid = operad_to_mermaid(operad)
print(mermaid)
undefinedmermaid = operad_to_mermaid(operad)
print(mermaid)
undefinedOperad Variants
Operad 变体
| Variant | Trit | UV Package | Description |
|---|---|---|---|
| 0 | discopy | Tree grafting (Ω(T)) |
| -1 | discopy | Σ-colored with permutations |
| 0 | discopy | Monoidal action |
| +1 | discopy | Day convolution on state |
| 变体 | Trit值 | UV包 | 描述 |
|---|---|---|---|
| 0 | discopy | 树嫁接(Ω(T)) |
| -1 | discopy | Σ-着色带排列 |
| 0 | discopy | 幺半群作用 |
| +1 | discopy | 状态上的Day卷积 |
3 Parallel Color Streams
3种并行颜色流
Each thread has 3 deterministic color streams:
python
node = ThreadOperadNode("T-123", "My Thread")每个线程包含3种确定性颜色流:
python
node = ThreadOperadNode("T-123", "My Thread")Access streams
访问颜色流
live_color = node.get_color("LIVE") # +1 trit
verify_color = node.get_color("VERIFY") # 0 trit
backfill_color = node.get_color("BACKFILL") # -1 trit
live_color = node.get_color("LIVE") # +1 Trit值
verify_color = node.get_color("VERIFY") # 0 Trit值
backfill_color = node.get_color("BACKFILL") # -1 Trit值
Get trit from hue
从色调获取Trit值
trit = live_color.to_trit() # -1, 0, or +1
undefinedtrit = live_color.to_trit() # -1、0或+1
undefinedProject Structure
项目结构
music-topos/
├── pyproject.toml # UV/Ruff/Hatch configuration
├── src/
│ └── discohy_thread_operad.py # Python implementation
├── lib/
│ └── discohy_thread_operad.hy # Hy implementation
├── db/
│ └── thread_operad_schema.sql # DuckDB materialization
└── tests/
└── test_discohy_operad.py # Pytest testsmusic-topos/
├── pyproject.toml # UV/Ruff/Hatch配置文件
├── src/
│ └── discohy_thread_operad.py # Python实现
├── lib/
│ └── discohy_thread_operad.hy # Hy实现
├── db/
│ └── thread_operad_schema.sql # DuckDB物化文件
└── tests/
└── test_discohy_operad.py # Pytest测试用例GF(3) Conservation
GF(3) 守恒性
The system verifies that sibling triplets satisfy:
sum(trits) ≡ 0 (mod 3)Where:
- (LIVE) = warm hues (0-60°, 300-360°)
+1 - (VERIFY) = neutral hues (60-180°)
0 - (BACKFILL) = cool hues (180-300°)
-1
系统会验证兄弟三元组是否满足:
sum(trits) ≡ 0 (mod 3)其中:
- (LIVE)= 暖色调(0-60°、300-360°)
+1 - (VERIFY)= 中性色调(60-180°)
0 - (BACKFILL)= 冷色调(180-300°)
-1
Justfile Commands
Justfile 命令
bash
undefinedbash
undefined═══════════════════════════════════════════════════════════════════════════════
═══════════════════════════════════════════════════════════════════════════════
UV/UVX/RUFF TOOLCHAIN
UV/UVX/RUFF 工具链
═══════════════════════════════════════════════════════════════════════════════
═══════════════════════════════════════════════════════════════════════════════
Initialize uv environment
初始化uv环境
uv-init:
uv venv
uv pip install -e ".[dev]"
uv-init:
uv venv
uv pip install -e ".[dev]"
Run DiscoHy operad demo
运行DiscoHy operad示例
uv-discohy:
uv run python src/discohy_thread_operad.py
uv-discohy:
uv run python src/discohy_thread_operad.py
Run with specific variant
使用指定变体运行
uv-discohy-variant variant:
uv run python -c "from discohy_thread_operad import *; demo_variant('{{variant}}')"
uv-discohy-variant variant:
uv run python -c "from discohy_thread_operad import *; demo_variant('{{variant}}')"
Lint with ruff
使用ruff进行代码检查
uv-lint:
uvx ruff check src/ lib/
uv-lint:
uvx ruff check src/ lib/
Format with ruff
使用ruff格式化代码
uv-format:
uvx ruff format src/
uv-format:
uvx ruff format src/
Fix and format
修复并格式化代码
uv-fix:
uvx ruff check --fix src/ && uvx ruff format src/
uv-fix:
uvx ruff check --fix src/ && uvx ruff format src/
Run tests
运行测试
uv-test:
uvx pytest tests/ -v
uv-test:
uvx pytest tests/ -v
Type check
类型检查
uv-typecheck:
uvx mypy src/
uv-typecheck:
uvx mypy src/
Full check (lint + format + test)
全面检查(代码检查 + 格式化检查 + 测试)
uv-check:
uvx ruff check src/
uvx ruff format --check src/
uvx pytest tests/ -v
undefineduv-check:
uvx ruff check src/
uvx ruff format --check src/
uvx pytest tests/ -v
undefinedIntegration with Other Skills
与其他Skill的集成
Triad: uv-discohy + acsets + gay-mcp = 0 ✓
三元组:uv-discohy + acsets + gay-mcp = 0 ✓
| Skill | Trit | Role |
|---|---|---|
| 0 | Coordinator (toolchain) |
| 0 | Coordinator (schema) |
| +1 | Generator (colors) |
→ Need | Add |
| Skill | Trit值 | 角色 |
|---|---|---|
| 0 | 协调者(工具链) |
| 0 | 协调者( schema) |
| +1 | 生成器(颜色) |
→ 需要 | 添加 |
With DiscoHy Streams
与DiscoHy Streams集成
python
undefinedpython
undefinedFrom discohy-streams skill
来自discohy-streams skill
color_url = f"color://{thread_id}/LIVE"
color_url = f"color://{thread_id}/LIVE"
Get color at index via MCP
通过MCP获取指定索引的颜色
undefinedundefinedWith ACSets
与ACSets集成
julia
undefinedjulia
undefinedThread operad as ACSet
作为ACSet的Thread operad
@present SchThreadOperad(FreeSchema) begin
Thread::Ob
continuation::Hom(Thread, Thread)
Trit::AttrType
trit::Attr(Thread, Trit)
end
undefined@present SchThreadOperad(FreeSchema) begin
Thread::Ob
continuation::Hom(Thread, Thread)
Trit::AttrType
trit::Attr(Thread, Trit)
end
undefinedEnvironment Variables
环境变量
bash
undefinedbash
undefinedUV cache directory (optional)
UV缓存目录(可选)
export UV_CACHE_DIR=~/.cache/uv
export UV_CACHE_DIR=~/.cache/uv
Ruff cache (optional)
Ruff缓存(可选)
export RUFF_CACHE_DIR=~/.cache/ruff
export RUFF_CACHE_DIR=~/.cache/ruff
Python version (optional)
Python版本(可选)
export UV_PYTHON=3.12
undefinedexport UV_PYTHON=3.12
undefinedTroubleshooting
故障排除
UV Not Found
未找到UV
bash
undefinedbash
undefinedInstall uv
安装uv
curl -LsSf https://astral.sh/uv/install.sh | sh
curl -LsSf https://astral.sh/uv/install.sh | sh
Or via pip
或通过pip安装
pip install uv
undefinedpip install uv
undefinedRuff Errors
Ruff错误
bash
undefinedbash
undefinedShow all available rules
查看所有可用规则
uvx ruff linter
uvx ruff linter
Ignore specific rule
忽略特定规则
uvx ruff check --ignore E501 src/
undefineduvx ruff check --ignore E501 src/
undefinedHy Not Found
未找到Hy
bash
undefinedbash
undefinedInstall hy via uv
通过uv安装hy
uv pip install hy>=1.0.0
uv pip install hy>=1.0.0
Run hy file
运行hy文件
uv run hy lib/discohy_thread_operad.hy
undefineduv run hy lib/discohy_thread_operad.hy
undefinedReferences
参考资料
Skill Name: uv-discohy
Type: Python Toolchain / DiscoHy Integration
Trit: 0 (ERGODIC)
Toolchain: uv + uvx + ruff
Package Format: pyproject.toml + hatchling