uv-discohy

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

UV-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:
  1. Fast dependency management via uv (10-100x faster than pip)
  2. One-shot tool execution via uvx (no install required)
  3. Modern linting/formatting via ruff (replaces black, isort, flake8)
  4. Python packaging via pyproject.toml with hatchling
本Skill为DiscoHy Thread Operad系统提供uv/uvx/ruff工具链集成,实现以下功能:
  1. 通过uv实现快速依赖管理(比pip快10-100倍)
  2. 通过uvx实现一次性工具执行(无需安装)
  3. 通过ruff实现现代化代码检查/格式化(替代black、isort、flake8)
  4. 通过pyproject.toml与hatchling实现Python打包

Quick Start

快速开始

bash
undefined
bash
undefined

Initialize 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
undefined
just uv-discohy-variant 2-transducer
undefined

UV Commands

UV 命令

Package Management

包管理

bash
undefined
bash
undefined

Create 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
undefined
uv pip tree
undefined

UVX: One-Shot Tool Execution

UVX:一次性工具执行

bash
undefined
bash
undefined

Run 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/
undefined
uvx --python 3.12 ruff check src/
undefined

Ruff Configuration

Ruff 配置

From
pyproject.toml
:
toml
[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.toml
toml
[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
undefined
bash
undefined

Check 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/
undefined
ruff check --fix src/ && ruff format src/
undefined

DiscoHy 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)
undefined
mermaid = operad_to_mermaid(operad) print(mermaid)
undefined

Operad Variants

Operad 变体

VariantTritUV PackageDescription
dendroidal
0discopyTree grafting (Ω(T))
colored-symmetric
-1discopyΣ-colored with permutations
actegory
0discopyMonoidal action
2-transducer
+1discopyDay convolution on state
变体Trit值UV包描述
dendroidal
0discopy树嫁接(Ω(T))
colored-symmetric
-1discopyΣ-着色带排列
actegory
0discopy幺半群作用
2-transducer
+1discopy状态上的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
undefined
trit = live_color.to_trit() # -1、0或+1
undefined

Project 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 tests
music-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:
  • +1
    (LIVE) = warm hues (0-60°, 300-360°)
  • 0
    (VERIFY) = neutral hues (60-180°)
  • -1
    (BACKFILL) = cool hues (180-300°)
系统会验证兄弟三元组是否满足:
sum(trits) ≡ 0 (mod 3)
其中:
  • +1
    (LIVE)= 暖色调(0-60°、300-360°)
  • 0
    (VERIFY)= 中性色调(60-180°)
  • -1
    (BACKFILL)= 冷色调(180-300°)

Justfile Commands

Justfile 命令

bash
undefined
bash
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
undefined
uv-check: uvx ruff check src/ uvx ruff format --check src/ uvx pytest tests/ -v
undefined

Integration with Other Skills

与其他Skill的集成

Triad: uv-discohy + acsets + gay-mcp = 0 ✓

三元组:uv-discohy + acsets + gay-mcp = 0 ✓

SkillTritRole
uv-discohy
0Coordinator (toolchain)
acsets
0Coordinator (schema)
gay-mcp
+1Generator (colors)
→ Need
-1
Add
three-match
or
slime-lisp
SkillTrit值角色
uv-discohy
0协调者(工具链)
acsets
0协调者( schema)
gay-mcp
+1生成器(颜色)
→ 需要
-1
添加
three-match
slime-lisp

With DiscoHy Streams

与DiscoHy Streams集成

python
undefined
python
undefined

From 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获取指定索引的颜色

undefined
undefined

With ACSets

与ACSets集成

julia
undefined
julia
undefined

Thread 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
undefined

Environment Variables

环境变量

bash
undefined
bash
undefined

UV 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
undefined
export UV_PYTHON=3.12
undefined

Troubleshooting

故障排除

UV Not Found

未找到UV

bash
undefined
bash
undefined

Install uv

安装uv

Or via pip

或通过pip安装

pip install uv
undefined
pip install uv
undefined

Ruff Errors

Ruff错误

bash
undefined
bash
undefined

Show all available rules

查看所有可用规则

uvx ruff linter
uvx ruff linter

Ignore specific rule

忽略特定规则

uvx ruff check --ignore E501 src/
undefined
uvx ruff check --ignore E501 src/
undefined

Hy Not Found

未找到Hy

bash
undefined
bash
undefined

Install 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
undefined
uv run hy lib/discohy_thread_operad.hy
undefined

References

参考资料


Skill Name: uv-discohy Type: Python Toolchain / DiscoHy Integration Trit: 0 (ERGODIC) Toolchain: uv + uvx + ruff Package Format: pyproject.toml + hatchling

Skill名称:uv-discohy 类型:Python工具链 / DiscoHy集成 Trit值:0(遍历性) 工具链:uv + uvx + ruff 包格式:pyproject.toml + hatchling