refactor: 将装饰器 gobridge 重命名为 expose,并添加 pyproject.toml

This commit is contained in:
2026-04-13 17:13:54 +08:00
parent 308faa95ff
commit 07e9239ac5
4 changed files with 38 additions and 26 deletions

View File

@@ -3,24 +3,24 @@ gobridge - Python 端库,配合 Go 侧 gobridge 使用
用法::
from gobridge import gobridge, run
from gobridge import expose, run
from typing import Iterator
@gobridge
@expose
def add(a: int, b: int) -> int:
return a + b
@gobridge
@expose
def range_gen(start: int, stop: int) -> Iterator[int]:
for i in range(start, stop):
yield i # 对应 Go 侧 Invoke[chan int]
@gobridge
@expose
def sum_stream(numbers: Iterator[int]) -> int:
return sum(numbers) # 对应 Go 侧传入 chan int 参数
# ctx 取消时,框架自动向该线程注入 InterruptedError无需在函数中检查
@gobridge
@expose
def slow_compute(n: int) -> int:
total = 0
for i in range(n):
@@ -43,7 +43,7 @@ import threading
_exposed: dict = {}
def gobridge(fn):
def expose(fn):
"""装饰器:将函数暴露给 Go 侧调用"""
_exposed[fn.__name__] = fn
return fn

12
python/pyproject.toml Normal file
View File

@@ -0,0 +1,12 @@
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
[project]
name = "gobridge"
version = "0.1.0"
description = "Python 端库,配合 Go 侧 gobridge 使用"
requires-python = ">=3.10"
[tool.hatch.build.targets.wheel]
packages = ["gobridge"]