Documentation
¶
Overview ¶
Package uv 管理 uv、Python 与主项目环境。
Index ¶
- Constants
- func RelaySummaryDetails(summary relay.Summary) map[string]any
- type ArchiveExtractor
- type Artifact
- type BootstrapOption
- func WithArchiveExtractor(extractor ArchiveExtractor) BootstrapOption
- func WithArtifact(artifact Artifact) BootstrapOption
- func WithBootstrapCatalog(catalog *mirror.Catalog) BootstrapOption
- func WithBootstrapPlanner(plan mirror.PlanFunc) BootstrapOption
- func WithBootstrapRemover(remover TreeRemover) BootstrapOption
- func WithBootstrapRotator(rotator rotationRunner) BootstrapOption
- func WithDownloader(downloader DownloadClient) BootstrapOption
- func WithPublisher(publisher Publisher) BootstrapOption
- func WithVersionChecker(checker VersionChecker) BootstrapOption
- type Bootstrapper
- func (b *Bootstrapper) Check(ctx context.Context) (bool, error)
- func (b *Bootstrapper) CheckWithLine(ctx context.Context, line LineFunc) (bool, error)
- func (b *Bootstrapper) Ensure(ctx context.Context, operationID string, policy mirror.Policy) (executablePath string, returnErr error)
- func (b *Bootstrapper) EnsureWithLine(ctx context.Context, operationID string, policy mirror.Policy, line LineFunc) (executablePath string, returnErr error)
- func (b *Bootstrapper) EnsureWithProgress(ctx context.Context, operationID string, policy mirror.Policy, line LineFunc, ...) (executablePath string, returnErr error)
- func (b *Bootstrapper) Repair(ctx context.Context, operationID string, policy mirror.Policy) (string, error)
- func (b *Bootstrapper) RepairWithLine(ctx context.Context, operationID string, policy mirror.Policy, line LineFunc) (string, error)
- func (b *Bootstrapper) RepairWithProgress(ctx context.Context, operationID string, policy mirror.Policy, line LineFunc, ...) (string, error)
- type DependenciesOption
- func WithDependenciesCatalog(catalog *mirror.Catalog) DependenciesOption
- func WithDependenciesIntel(intel sourceIntel) DependenciesOption
- func WithDependenciesPlanner(plan mirror.PlanFunc) DependenciesOption
- func WithDependenciesRelay(factory RelayFactory) DependenciesOption
- func WithDependenciesRotator(rotator sourceRotator) DependenciesOption
- func WithDependenciesStagingRemover(remover TreeRemover) DependenciesOption
- type DependenciesRequest
- type DependenciesResult
- type DependenciesService
- func (s *DependenciesService) Check(ctx context.Context, request DependenciesRequest) (DependenciesResult, error)
- func (s *DependenciesService) Rebuild(ctx context.Context, request DependenciesRequest) (DependenciesResult, error)
- func (s *DependenciesService) Sync(ctx context.Context, request DependenciesRequest) (DependenciesResult, error)
- type DependencyOperations
- type DownloadClient
- type EnvironmentRequest
- type EnvironmentResult
- type EnvironmentService
- func (s *EnvironmentService) Check(ctx context.Context, request EnvironmentRequest) (EnvironmentResult, error)
- func (s *EnvironmentService) CheckDependencies(ctx context.Context, request DependenciesRequest) (DependenciesResult, error)
- func (s *EnvironmentService) CheckPython(ctx context.Context, request PythonRequest) (PythonCheckResult, error)
- func (s *EnvironmentService) CheckUV(ctx context.Context) (bool, error)
- func (s *EnvironmentService) CheckUVWithLine(ctx context.Context, line LineFunc) (bool, error)
- func (s *EnvironmentService) Ensure(ctx context.Context, request EnvironmentRequest) (EnvironmentResult, error)
- func (s *EnvironmentService) EnsureUV(ctx context.Context, operationID string, policy mirror.Policy) (string, error)
- func (s *EnvironmentService) EnsureUVWithLine(ctx context.Context, operationID string, policy mirror.Policy, line LineFunc) (string, error)
- func (s *EnvironmentService) EnsureUVWithProgress(ctx context.Context, operationID string, policy mirror.Policy, line LineFunc, ...) (string, error)
- func (s *EnvironmentService) PreparePython(ctx context.Context, request PythonRequest) (PythonResult, error)
- func (s *EnvironmentService) ReadPythonSpec(ctx context.Context, projectDir string) (PythonSpec, error)
- func (s *EnvironmentService) RebuildDependencies(ctx context.Context, request DependenciesRequest) (DependenciesResult, error)
- func (s *EnvironmentService) Repair(ctx context.Context, request EnvironmentRequest) (EnvironmentResult, error)
- func (s *EnvironmentService) RepairEnvironment(ctx context.Context, request EnvironmentRequest) (EnvironmentResult, error)
- func (s *EnvironmentService) RepairUV(ctx context.Context, operationID string, policy mirror.Policy) (string, error)
- func (s *EnvironmentService) RepairUVWithLine(ctx context.Context, operationID string, policy mirror.Policy, line LineFunc) (string, error)
- func (s *EnvironmentService) RepairUVWithProgress(ctx context.Context, operationID string, policy mirror.Policy, line LineFunc, ...) (string, error)
- func (s *EnvironmentService) SyncDependencies(ctx context.Context, request DependenciesRequest) (DependenciesResult, error)
- type Error
- type LineFunc
- type LockArtifact
- type LockPlan
- type ManagedOptions
- type MirrorAttempt
- type MirrorAttemptFunc
- type ProductionEnvironment
- func (s *ProductionEnvironment) Check(ctx context.Context, request EnvironmentRequest) (EnvironmentResult, error)
- func (s *ProductionEnvironment) CheckDependencies(ctx context.Context, request DependenciesRequest) (DependenciesResult, error)
- func (s *ProductionEnvironment) CheckPython(ctx context.Context, request PythonRequest) (PythonCheckResult, error)
- func (s *ProductionEnvironment) CheckUV(ctx context.Context) (bool, error)
- func (s *ProductionEnvironment) CheckUVWithLine(ctx context.Context, line LineFunc) (bool, error)
- func (s *ProductionEnvironment) Ensure(ctx context.Context, request EnvironmentRequest) (EnvironmentResult, error)
- func (s *ProductionEnvironment) EnsureUV(ctx context.Context, operationID string, policy mirror.Policy) (string, error)
- func (s *ProductionEnvironment) EnsureUVWithLine(ctx context.Context, operationID string, policy mirror.Policy, line LineFunc) (string, error)
- func (s *ProductionEnvironment) EnsureUVWithProgress(ctx context.Context, operationID string, policy mirror.Policy, line LineFunc, ...) (string, error)
- func (s *ProductionEnvironment) PreparePython(ctx context.Context, request PythonRequest) (PythonResult, error)
- func (s *ProductionEnvironment) ReadPythonSpec(ctx context.Context, projectDir string) (PythonSpec, error)
- func (s *ProductionEnvironment) RebuildDependencies(ctx context.Context, request DependenciesRequest) (DependenciesResult, error)
- func (s *ProductionEnvironment) Repair(ctx context.Context, request EnvironmentRequest) (EnvironmentResult, error)
- func (s *ProductionEnvironment) RepairEnvironment(ctx context.Context, request EnvironmentRequest) (EnvironmentResult, error)
- func (s *ProductionEnvironment) RepairUV(ctx context.Context, operationID string, policy mirror.Policy) (string, error)
- func (s *ProductionEnvironment) RepairUVWithLine(ctx context.Context, operationID string, policy mirror.Policy, line LineFunc) (string, error)
- func (s *ProductionEnvironment) RepairUVWithProgress(ctx context.Context, operationID string, policy mirror.Policy, line LineFunc, ...) (string, error)
- func (s *ProductionEnvironment) SyncDependencies(ctx context.Context, request DependenciesRequest) (DependenciesResult, error)
- type ProductionOption
- type PublishRequest
- type PublishResult
- type Publisher
- type PythonCheckResult
- type PythonOperations
- type PythonOption
- type PythonRequest
- type PythonResult
- type PythonService
- type PythonSpec
- type PythonVersion
- type RelayFactory
- type RunOptions
- type Runner
- type RunnerConfig
- type SupervisionIdentity
- type SupervisionInfrastructure
- type TreeRemover
- type UVOperations
- type UVRepairOperations
- type UVResult
- type UVRunner
- func (r *UVRunner) CheckVersion(ctx context.Context, expected string, stage protocol.Stage, line LineFunc) error
- func (r *UVRunner) CheckVersionWithOptions(ctx context.Context, expected string, options RunOptions) error
- func (r *UVRunner) CommandEnvironmentDetails(options RunOptions) map[string]any
- func (r *UVRunner) EnvironmentForTesting(options RunOptions) map[string]string
- func (r *UVRunner) Run(ctx context.Context, args []string, options RunOptions) (UVResult, error)
- func (r *UVRunner) StartManaged(ctx context.Context, args []string, options ManagedOptions, ...) (*process.ManagedProcess, error)
- type VersionChecker
Constants ¶
const ( // FixedVersion 是 Runtime 首版固定使用的 uv 版本。 FixedVersion = "0.12.3" // WindowsX64Artifact 是 Windows x64 官方发行文件名。 WindowsX64Artifact = "uv-x86_64-pc-windows-msvc.zip" // WindowsX64SHA256 是 Windows x64 发行文件的固定 SHA-256。 WindowsX64SHA256 = "b23350c79e8ad0192b8124af13a0f17e8d4e4549524785e1aef389ae5a06990e" )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ArchiveExtractor ¶
type ArchiveExtractor interface {
Extract(ctx context.Context, archivePath, stagingDir string) error
}
ArchiveExtractor 把已校验的 uv zip 解压到指定暂存目录。
type Artifact ¶
Artifact 描述当前平台的固定 uv 制品。
func WindowsX64ArtifactSpec ¶
func WindowsX64ArtifactSpec() Artifact
WindowsX64ArtifactSpec 返回 Windows x64 的防御性制品描述。
type BootstrapOption ¶
type BootstrapOption func(*bootstrapOptions) error
BootstrapOptions 配置 Bootstrapper 的可替换依赖。
func WithArchiveExtractor ¶
func WithArchiveExtractor(extractor ArchiveExtractor) BootstrapOption
WithArchiveExtractor 注入 zip 解压器。
func WithArtifact ¶
func WithArtifact(artifact Artifact) BootstrapOption
WithArtifact 注入测试制品;生产构造默认使用 D-open-6 固定值。
func WithBootstrapCatalog ¶
func WithBootstrapCatalog(catalog *mirror.Catalog) BootstrapOption
WithBootstrapCatalog 注入测试用 source catalog。
func WithBootstrapPlanner ¶ added in v0.1.7
func WithBootstrapPlanner(plan mirror.PlanFunc) BootstrapOption
WithBootstrapPlanner 注入 uv 源尝试顺序的构造函数(增补 2 C16 的实测排序);默认按目录顺序。
func WithBootstrapRemover ¶
func WithBootstrapRemover(remover TreeRemover) BootstrapOption
WithBootstrapRemover 注入版本目录的受控删除能力。
func WithBootstrapRotator ¶
func WithBootstrapRotator(rotator rotationRunner) BootstrapOption
WithBootstrapRotator 注入镜像轮换器。
func WithDownloader ¶
func WithDownloader(downloader DownloadClient) BootstrapOption
WithDownloader 注入制品下载器。
func WithPublisher ¶
func WithPublisher(publisher Publisher) BootstrapOption
WithPublisher 注入版本目录发布器。
func WithVersionChecker ¶
func WithVersionChecker(checker VersionChecker) BootstrapOption
WithVersionChecker 注入版本实测替身。
type Bootstrapper ¶
type Bootstrapper struct {
// contains filtered or unexported fields
}
Bootstrapper 负责固定 uv 制品的缓存、校验、解压和原子发布。
func NewBootstrapper ¶
func NewBootstrapper( layout *config.Layout, optionValues ...BootstrapOption, ) (*Bootstrapper, error)
NewBootstrapper 创建生产 bootstrap 服务。
func (*Bootstrapper) Check ¶
func (b *Bootstrapper) Check(ctx context.Context) (bool, error)
Check 只检查版本化 uv 是否存在且版本一致,不访问网络。
func (*Bootstrapper) CheckWithLine ¶
CheckWithLine 只检查版本化 uv 是否存在且版本一致,并转发版本检查输出。
func (*Bootstrapper) Ensure ¶
func (b *Bootstrapper) Ensure( ctx context.Context, operationID string, policy mirror.Policy, ) (executablePath string, returnErr error)
Ensure 返回已通过版本实测的 uv.exe;缓存命中不访问网络。
func (*Bootstrapper) EnsureWithLine ¶
func (b *Bootstrapper) EnsureWithLine( ctx context.Context, operationID string, policy mirror.Policy, line LineFunc, ) (executablePath string, returnErr error)
EnsureWithLine 返回已通过版本实测的 uv.exe,并转发版本检查输出。
func (*Bootstrapper) EnsureWithProgress ¶ added in v0.1.1
func (b *Bootstrapper) EnsureWithProgress( ctx context.Context, operationID string, policy mirror.Policy, line LineFunc, progress mirror.ProgressFunc, ) (executablePath string, returnErr error)
EnsureWithProgress 返回已通过版本实测的 uv.exe,并转发版本检查输出与真实下载字节进度。
func (*Bootstrapper) Repair ¶
func (b *Bootstrapper) Repair( ctx context.Context, operationID string, policy mirror.Policy, ) (string, error)
Repair 删除当前固定版本的 uv 受管事实后重新执行完整 bootstrap。
func (*Bootstrapper) RepairWithLine ¶
func (b *Bootstrapper) RepairWithLine( ctx context.Context, operationID string, policy mirror.Policy, line LineFunc, ) (string, error)
RepairWithLine 删除当前固定版本的 uv 受管事实后重新执行完整 bootstrap,并转发输出。
func (*Bootstrapper) RepairWithProgress ¶ added in v0.1.1
func (b *Bootstrapper) RepairWithProgress( ctx context.Context, operationID string, policy mirror.Policy, line LineFunc, progress mirror.ProgressFunc, ) (string, error)
RepairWithProgress 重新下载并校验固定版本 uv,同时转发输出与真实下载字节进度。
type DependenciesOption ¶
type DependenciesOption func(*dependenciesOptions) error
DependenciesOption 配置 DependenciesService 的可注入依赖。
func WithDependenciesCatalog ¶
func WithDependenciesCatalog(catalog *mirror.Catalog) DependenciesOption
WithDependenciesCatalog 注入包索引源目录。
func WithDependenciesIntel ¶ added in v0.1.7
func WithDependenciesIntel(intel sourceIntel) DependenciesOption
WithDependenciesIntel 注入测速器,用于登记包索引探针目标并把 Accept-Ranges 能力交给中继。
func WithDependenciesPlanner ¶ added in v0.1.7
func WithDependenciesPlanner(plan mirror.PlanFunc) DependenciesOption
WithDependenciesPlanner 注入包索引源尝试顺序的构造函数(增补 2 C16 的实测排序);默认按目录顺序。
func WithDependenciesRelay ¶ added in v0.1.7
func WithDependenciesRelay(factory RelayFactory) DependenciesOption
WithDependenciesRelay 启用经回环中继的依赖同步(增补 2 C17);nil 工厂视为参数错误。
func WithDependenciesRotator ¶
func WithDependenciesRotator(rotator sourceRotator) DependenciesOption
WithDependenciesRotator 注入镜像轮换器。
func WithDependenciesStagingRemover ¶
func WithDependenciesStagingRemover(remover TreeRemover) DependenciesOption
WithDependenciesStagingRemover 注入临时项目目录的受控删除能力。
type DependenciesRequest ¶
type DependenciesRequest struct {
ProjectDir string
ProjectEnvDir string
PythonVersion string
OperationID string
Branch string
Commit string
MirrorPolicy mirror.Policy
Line LineFunc
// Attempt 在镜像轮换的每次尝试开始前报告当前源,可为 nil。
Attempt MirrorAttemptFunc
// Progress 接收经中继下载时的聚合字节进度(增补 2 C18),可为 nil。
Progress func(relay.Progress) error
// RelayLog 接收中继的诊断(换源、哈希不符、剔除、收口失败),可为 nil;level 为 info / warning / error。
RelayLog func(level, message string, fields map[string]any)
}
DependenciesRequest 描述一次主项目依赖操作的固定工作区和 Python 身份。
type DependenciesResult ¶
type DependenciesResult struct {
LockfileChecked bool
Synchronized bool
Rebuilt bool
// SourceKind 恒为 package-index,同步执行过才有值。
SourceKind string
// Source 是实际完成同步的源 key;回退原锁时为官方源 key,离线时为空。
Source string
// AttemptCount 是实际执行 uv sync 的次数,含回退那次。
AttemptCount int
// LockRewritten 报告成功那次是否用了改写后的锁副本。
LockRewritten bool
// Relay 是经中继同步时的下载摘要;没有走中继时为 nil。
Relay *relay.Summary
}
DependenciesResult 保存锁文件检查或同步后的稳定结果。
type DependenciesService ¶
type DependenciesService struct {
// contains filtered or unexported fields
}
DependenciesService 负责锁文件契约、项目模式同步和 managed venv 重建。
func NewDependenciesService ¶
func NewDependenciesService( layout *config.Layout, runner Runner, remover TreeRemover, options ...DependenciesOption, ) (*DependenciesService, error)
NewDependenciesService 创建主项目依赖服务。
func (*DependenciesService) Check ¶
func (s *DependenciesService) Check( ctx context.Context, request DependenciesRequest, ) (DependenciesResult, error)
Check 只读检查 uv.lock 与现有主项目环境是否保持同步。
func (*DependenciesService) Rebuild ¶
func (s *DependenciesService) Rebuild( ctx context.Context, request DependenciesRequest, ) (DependenciesResult, error)
Rebuild 通过 T2.5 删除能力重建 managed venv,不触碰源码、锁文件和用户数据。
func (*DependenciesService) Sync ¶
func (s *DependenciesService) Sync( ctx context.Context, request DependenciesRequest, ) (DependenciesResult, error)
Sync 在只读锁文件检查通过后执行锁定依赖同步。
在线时按 C10 走包索引镜像轮换:每个镜像用改写后的锁副本安装,全部失败后 回退到 repo 原锁。离线时完全不改写,沿用原锁并只注入 UV_OFFLINE=1。
type DependencyOperations ¶
type DependencyOperations interface {
Sync(context.Context, DependenciesRequest) (DependenciesResult, error)
Check(context.Context, DependenciesRequest) (DependenciesResult, error)
Rebuild(context.Context, DependenciesRequest) (DependenciesResult, error)
}
DependencyOperations 是环境编排消费的主项目依赖 sync/check 能力。
type DownloadClient ¶
type DownloadClient interface {
Download(ctx context.Context, request mirror.DownloadRequest) (mirror.DownloadResult, error)
}
DownloadClient 是 bootstrap 所需的受控制品下载能力。
type EnvironmentRequest ¶
type EnvironmentRequest struct {
ProjectDir string
ProjectEnvDir string
PythonInstallDir string
CacheDir string
PythonVersion string
OperationID string
Branch string
Commit string
BootstrapPolicy mirror.Policy
Line LineFunc
}
EnvironmentRequest 描述一次 managed 环境 ensure/check。
type EnvironmentResult ¶
type EnvironmentResult struct {
UVExecutable string
UVReady bool
Python PythonSpec
Dependencies DependenciesResult
}
EnvironmentResult 保存环境操作的各阶段结果。
type EnvironmentService ¶
type EnvironmentService struct {
// contains filtered or unexported fields
}
EnvironmentService 编排 uv、Python 与主项目依赖,不启动后端。
func NewEnvironmentService ¶
func NewEnvironmentService( uv UVOperations, python PythonOperations, dependencies DependencyOperations, ) (*EnvironmentService, error)
NewEnvironmentService 创建环境编排服务。
func (*EnvironmentService) Check ¶
func (s *EnvironmentService) Check( ctx context.Context, request EnvironmentRequest, ) (EnvironmentResult, error)
Check 只读取 uv、项目 Python 契约和锁定依赖事实,不安装或删除任何内容。
func (*EnvironmentService) CheckDependencies ¶
func (s *EnvironmentService) CheckDependencies( ctx context.Context, request DependenciesRequest, ) (DependenciesResult, error)
CheckDependencies 只读取锁文件与 uv lock 检查结果。
func (*EnvironmentService) CheckPython ¶
func (s *EnvironmentService) CheckPython( ctx context.Context, request PythonRequest, ) (PythonCheckResult, error)
CheckPython 只读取项目 Python 契约与受管安装事实。
func (*EnvironmentService) CheckUV ¶
func (s *EnvironmentService) CheckUV(ctx context.Context) (bool, error)
CheckUV 只读取固定 uv 的可用性。
func (*EnvironmentService) CheckUVWithLine ¶
CheckUVWithLine 只读取固定 uv 的可用性,并转发版本检查输出。
func (*EnvironmentService) Ensure ¶
func (s *EnvironmentService) Ensure( ctx context.Context, request EnvironmentRequest, ) (EnvironmentResult, error)
Ensure 按 uv → Python → 锁定依赖顺序幂等准备 managed 环境。
func (*EnvironmentService) EnsureUV ¶
func (s *EnvironmentService) EnsureUV( ctx context.Context, operationID string, policy mirror.Policy, ) (string, error)
EnsureUV 只执行固定 uv bootstrap,供 bootstrap 顶层编排复用。
func (*EnvironmentService) EnsureUVWithLine ¶
func (s *EnvironmentService) EnsureUVWithLine( ctx context.Context, operationID string, policy mirror.Policy, line LineFunc, ) (string, error)
EnsureUVWithLine 只执行固定 uv bootstrap,并转发版本检查输出。
func (*EnvironmentService) EnsureUVWithProgress ¶ added in v0.1.1
func (s *EnvironmentService) EnsureUVWithProgress( ctx context.Context, operationID string, policy mirror.Policy, line LineFunc, progress mirror.ProgressFunc, ) (string, error)
EnsureUVWithProgress 只执行固定 uv bootstrap,并转发版本检查输出与真实下载字节进度。
func (*EnvironmentService) PreparePython ¶
func (s *EnvironmentService) PreparePython( ctx context.Context, request PythonRequest, ) (PythonResult, error)
PreparePython 读取项目契约并准备精确受管 Python。
func (*EnvironmentService) ReadPythonSpec ¶
func (s *EnvironmentService) ReadPythonSpec(ctx context.Context, projectDir string) (PythonSpec, error)
ReadPythonSpec 只读取并校验项目声明的精确 Python 契约。
func (*EnvironmentService) RebuildDependencies ¶
func (s *EnvironmentService) RebuildDependencies( ctx context.Context, request DependenciesRequest, ) (DependenciesResult, error)
RebuildDependencies 只删除受管 venv 并返回删除事实。
func (*EnvironmentService) Repair ¶
func (s *EnvironmentService) Repair( ctx context.Context, request EnvironmentRequest, ) (EnvironmentResult, error)
Repair 重新校验 uv、准备受管 Python、重建 venv 并执行 locked sync。
func (*EnvironmentService) RepairEnvironment ¶
func (s *EnvironmentService) RepairEnvironment( ctx context.Context, request EnvironmentRequest, ) (EnvironmentResult, error)
RepairEnvironment 只修复 uv 与受管 Python,不删除或同步项目 venv。
func (*EnvironmentService) RepairUV ¶
func (s *EnvironmentService) RepairUV( ctx context.Context, operationID string, policy mirror.Policy, ) (string, error)
RepairUV 删除固定版本 uv 受管事实并重新下载校验。
func (*EnvironmentService) RepairUVWithLine ¶
func (s *EnvironmentService) RepairUVWithLine( ctx context.Context, operationID string, policy mirror.Policy, line LineFunc, ) (string, error)
RepairUVWithLine 删除固定版本 uv 受管事实并重新下载校验,同时转发输出。
func (*EnvironmentService) RepairUVWithProgress ¶ added in v0.1.1
func (s *EnvironmentService) RepairUVWithProgress( ctx context.Context, operationID string, policy mirror.Policy, line LineFunc, progress mirror.ProgressFunc, ) (string, error)
RepairUVWithProgress 删除固定版本 uv 受管事实并重新下载校验,同时转发输出与真实下载字节进度。
func (*EnvironmentService) SyncDependencies ¶
func (s *EnvironmentService) SyncDependencies( ctx context.Context, request DependenciesRequest, ) (DependenciesResult, error)
SyncDependencies 执行只读锁文件检查和 locked sync。
type Error ¶
type Error struct {
// contains filtered or unexported fields
}
Error 是 uv、Python 与依赖操作向 CLI 暴露的结构化错误。
type LineFunc ¶
LineFunc 接收 uv stdout/stderr 的逐行诊断。 Runner 同步调用回调,因此实现必须快速返回、尊重 ctx 取消,不能等待 不受控的外部事件;回调返回错误会立即终止 uv 进程。
type LockArtifact ¶ added in v0.1.7
LockArtifact 是锁内为本平台选定的一个制品:PyPI 原路径(不含 `/packages/` 前缀)、大小与十六进制 sha256。
type LockPlan ¶ added in v0.1.7
type LockPlan struct {
Items []LockArtifact
TotalBytes int64
Largest LockArtifact
Skipped int
}
LockPlan 是从锁文件规划出的本平台可安装制品集合(增补 2 C18 第 3 条)。
它只用于进度总量与探针目标,不参与安装决策:uv 仍按锁自行选择制品, 因此 Skipped 记录的是求值不了、按可达处理的 marker 数,方向只会高估。
type ManagedOptions ¶
type ManagedOptions struct {
// Secret 由监督器为每次启动生成,禁止从宿主继承。
Secret string
RunOptions
Identity *SupervisionIdentity
Infrastructure SupervisionInfrastructure
// Port 是按增补 1 C12 注入的受监督后端端口(AUTO_MAS_SUPERVISED_PORT)。
// 为零时不注入:本包是通用启动器,不替调用方决定端口;backend 保证任何模式
// 都传非零值。非零但越界在 spawn 之前失败关闭。
Port int
}
ManagedOptions 把通用 uv 选项与长驻监督身份策略分开,避免调用方直接拼受控环境键。
type MirrorAttempt ¶
type MirrorAttempt struct {
SourceKind string
Source string
SourceTry int
GlobalTry int
// Fallback 为真表示这次用的是 repo 原锁与 --locked,即 C10 的回退路径。
Fallback bool
}
MirrorAttempt 描述依赖同步镜像轮换中的一次尝试。
type MirrorAttemptFunc ¶
type MirrorAttemptFunc func(ctx context.Context, attempt MirrorAttempt) error
MirrorAttemptFunc 在每次尝试开始前报告当前源;返回错误会中止整轮轮换。
type ProductionEnvironment ¶
type ProductionEnvironment struct {
// contains filtered or unexported fields
}
ProductionEnvironment 把固定 uv 与共享 UVRunner 绑定到 Python/依赖服务。 构造本身不访问网络;Ensure/Check/Repair 才执行各自声明的副作用。
func NewProductionEnvironment ¶
func NewProductionEnvironment(layout *config.Layout, options ...ProductionOption) (*ProductionEnvironment, error)
NewProductionEnvironment 创建 Windows 首版使用的受管环境适配器。
func (*ProductionEnvironment) Check ¶
func (s *ProductionEnvironment) Check( ctx context.Context, request EnvironmentRequest, ) (EnvironmentResult, error)
Check 只读取固定 uv、Python 契约和锁文件状态。
func (*ProductionEnvironment) CheckDependencies ¶
func (s *ProductionEnvironment) CheckDependencies( ctx context.Context, request DependenciesRequest, ) (DependenciesResult, error)
CheckDependencies 只读检查锁文件与现有主项目环境是否同步。
func (*ProductionEnvironment) CheckPython ¶
func (s *ProductionEnvironment) CheckPython( ctx context.Context, request PythonRequest, ) (PythonCheckResult, error)
CheckPython 只读取项目 Python 契约和已安装事实。
func (*ProductionEnvironment) CheckUV ¶
func (s *ProductionEnvironment) CheckUV(ctx context.Context) (bool, error)
CheckUV 只检查固定版本 uv,不触碰网络或创建目录。
func (*ProductionEnvironment) CheckUVWithLine ¶
CheckUVWithLine 只检查固定版本 uv,并转发版本检查输出。
func (*ProductionEnvironment) Ensure ¶
func (s *ProductionEnvironment) Ensure( ctx context.Context, request EnvironmentRequest, ) (EnvironmentResult, error)
Ensure 按固定顺序准备 uv、Python 和锁定依赖。
func (*ProductionEnvironment) EnsureUV ¶
func (s *ProductionEnvironment) EnsureUV( ctx context.Context, operationID string, policy mirror.Policy, ) (string, error)
EnsureUV 准备固定版本 uv,并返回已验证的可执行文件路径。
func (*ProductionEnvironment) EnsureUVWithLine ¶
func (s *ProductionEnvironment) EnsureUVWithLine( ctx context.Context, operationID string, policy mirror.Policy, line LineFunc, ) (string, error)
EnsureUVWithLine 准备固定版本 uv,并转发版本检查输出。
func (*ProductionEnvironment) EnsureUVWithProgress ¶ added in v0.1.1
func (s *ProductionEnvironment) EnsureUVWithProgress( ctx context.Context, operationID string, policy mirror.Policy, line LineFunc, progress mirror.ProgressFunc, ) (string, error)
EnsureUVWithProgress 准备固定版本 uv,并转发版本检查输出与真实下载字节进度。
func (*ProductionEnvironment) PreparePython ¶
func (s *ProductionEnvironment) PreparePython( ctx context.Context, request PythonRequest, ) (PythonResult, error)
PreparePython 准备项目声明的精确受管 Python。
func (*ProductionEnvironment) ReadPythonSpec ¶
func (s *ProductionEnvironment) ReadPythonSpec(ctx context.Context, projectDir string) (PythonSpec, error)
ReadPythonSpec 只读取并校验项目声明的精确 Python 契约。
func (*ProductionEnvironment) RebuildDependencies ¶
func (s *ProductionEnvironment) RebuildDependencies( ctx context.Context, request DependenciesRequest, ) (DependenciesResult, error)
RebuildDependencies 只删除受管 venv。
func (*ProductionEnvironment) Repair ¶
func (s *ProductionEnvironment) Repair( ctx context.Context, request EnvironmentRequest, ) (EnvironmentResult, error)
Repair 重新取得 uv、准备受管 Python 并重建 managed venv。
func (*ProductionEnvironment) RepairEnvironment ¶
func (s *ProductionEnvironment) RepairEnvironment( ctx context.Context, request EnvironmentRequest, ) (EnvironmentResult, error)
RepairEnvironment 重新取得 uv 并准备受管 Python,但保留现有项目 venv。
func (*ProductionEnvironment) RepairUV ¶
func (s *ProductionEnvironment) RepairUV( ctx context.Context, operationID string, policy mirror.Policy, ) (string, error)
RepairUV 删除固定版本 uv 受管事实并重新下载校验。
func (*ProductionEnvironment) RepairUVWithLine ¶
func (s *ProductionEnvironment) RepairUVWithLine( ctx context.Context, operationID string, policy mirror.Policy, line LineFunc, ) (string, error)
RepairUVWithLine 删除固定版本 uv 受管事实并重新下载校验,同时转发输出。
func (*ProductionEnvironment) RepairUVWithProgress ¶ added in v0.1.1
func (s *ProductionEnvironment) RepairUVWithProgress( ctx context.Context, operationID string, policy mirror.Policy, line LineFunc, progress mirror.ProgressFunc, ) (string, error)
RepairUVWithProgress 删除固定版本 uv 受管事实并重新下载校验,同时转发输出与真实下载字节进度。
func (*ProductionEnvironment) SyncDependencies ¶
func (s *ProductionEnvironment) SyncDependencies( ctx context.Context, request DependenciesRequest, ) (DependenciesResult, error)
SyncDependencies 执行锁定依赖同步。
type ProductionOption ¶ added in v0.1.7
type ProductionOption func(*productionOptions) error
ProductionOption 配置 ProductionEnvironment 的可注入依赖。
func WithProductionPlanner ¶ added in v0.1.7
func WithProductionPlanner(plan mirror.PlanFunc) ProductionOption
WithProductionPlanner 注入 uv / Python / 包索引三类源共用的尝试顺序构造函数(增补 2 C16 的实测排序)。
func WithProductionRanker ¶ added in v0.1.7
func WithProductionRanker(ranker *mirror.Ranker) ProductionOption
WithProductionRanker 注入测速器:既提供实测顺序,也接收 python / package-index 的探针目标登记。
func WithProductionRelay ¶ added in v0.1.7
func WithProductionRelay(factory RelayFactory) ProductionOption
WithProductionRelay 替换回环中继工厂;传 nil 表示关闭中继、退回逐源轮换(测试与诊断用)。
type PublishRequest ¶
type PublishRequest struct {
Source string
Destination string
OperationID string
Version string
// ExpectedSourceIdentity 把 staging lease 的关闭前身份交给受控 rename 复验。
ExpectedSourceIdentity *filesystem.DirectoryIdentity
}
PublishRequest 描述一次版本化 uv 目录发布。
type PublishResult ¶
type PublishResult struct {
MutationApplied bool
}
PublishResult 报告目录 rename 是否已经产生副作用。
type Publisher ¶
type Publisher interface {
Publish(ctx context.Context, request PublishRequest) (PublishResult, error)
}
Publisher 把经过验证的 uv 暂存目录原子发布到版本目录。
type PythonCheckResult ¶
type PythonCheckResult struct {
Spec PythonSpec
}
PythonCheckResult 保存不改变磁盘的 Python 检查结果。
type PythonOperations ¶
type PythonOperations interface {
ReadSpec(context.Context, string) (PythonSpec, error)
Prepare(context.Context, PythonRequest) (PythonResult, error)
Check(context.Context, PythonRequest) (PythonCheckResult, error)
}
PythonOperations 是环境编排消费的 Python prepare/check 能力。
type PythonOption ¶ added in v0.1.7
type PythonOption func(*pythonOptions) error
PythonOption 配置 PythonService 的可注入依赖。
func WithPythonIntel ¶ added in v0.1.7
func WithPythonIntel(intel sourceIntel) PythonOption
WithPythonIntel 注入测速器,用于登记 Python 分发包探针目标并把 Accept-Ranges 能力交给中继。
func WithPythonPlanner ¶ added in v0.1.7
func WithPythonPlanner(plan mirror.PlanFunc) PythonOption
WithPythonPlanner 注入 Python 分发源尝试顺序的构造函数(增补 2 C16 的实测排序);默认按目录顺序。
func WithPythonRelay ¶ added in v0.1.7
func WithPythonRelay(factory RelayFactory) PythonOption
WithPythonRelay 启用经回环中继的 Python 分发包下载(增补 2 C17 第 3 条)。
type PythonRequest ¶
type PythonRequest struct {
ProjectDir string
PythonInstallDir string
ProjectEnvDir string
CacheDir string
Branch string
Commit string
MirrorPolicy mirror.Policy
Reinstall bool
Line LineFunc
// Progress 接收经中继下载分发包时的字节进度(增补 2 C18),可为 nil。
Progress func(relay.Progress) error
// RelayLog 接收中继的诊断,可为 nil;level 为 info / warning / error。
RelayLog func(level, message string, fields map[string]any)
}
PythonRequest 描述一次受管 Python 准备操作。
type PythonResult ¶
type PythonResult struct {
Spec PythonSpec
// Source 是实际提供分发包的源 key;缓存命中或未经中继时为空。
Source string
// Relay 是经中继下载时的摘要;没有走中继时为 nil。
Relay *relay.Summary
}
PythonResult 保存已验证的 Python 版本。
type PythonService ¶
type PythonService struct {
// contains filtered or unexported fields
}
PythonService 负责读取项目 Python 契约并准备受管解释器。
func NewPythonService ¶
func NewPythonService(layout *config.Layout, runner Runner, options ...PythonOption) (*PythonService, error)
NewPythonService 创建 Python 服务。
func (*PythonService) Check ¶
func (s *PythonService) Check(ctx context.Context, request PythonRequest) (PythonCheckResult, error)
Check 只验证项目约束、uv 清单和已安装的受管 Python,不执行安装。
func (*PythonService) Prepare ¶
func (s *PythonService) Prepare(ctx context.Context, request PythonRequest) (PythonResult, error)
Prepare 检查 uv 的结构化 Python 清单、安装精确版本并复核可发现性。
func (*PythonService) ReadSpec ¶
func (s *PythonService) ReadSpec(ctx context.Context, projectDir string) (PythonSpec, error)
ReadSpec 只读取项目的版本文件和 pyproject.toml,不启动任何进程。
type PythonSpec ¶
type PythonSpec struct {
Version PythonVersion
RequiresPython string
}
PythonSpec 保存项目声明的精确 Python 与 requires-python 约束。
func ReadPythonSpec ¶
func ReadPythonSpec(ctx context.Context, layout *config.Layout, projectDir string) (PythonSpec, error)
ReadPythonSpec 只从受管项目文件读取并校验精确 Python 契约。
type PythonVersion ¶
PythonVersion 是精确的 CPython major.minor.patch 值对象。
func ParsePythonVersion ¶ added in v0.1.7
func ParsePythonVersion(text string) (PythonVersion, bool)
ParsePythonVersion 解析 "3.12.13" 形式的精确版本文本(允许首尾空白);缺少 major/minor 或含非数字时报告 false。
type RelayFactory ¶ added in v0.1.7
type RelayFactory func(ctx context.Context, cfg relay.Config, deps relay.Deps) (relaySession, error)
RelayFactory 启动一次中继会话;生产实现包装 relay.Start,测试注入替身。
func ProductionRelayFactory ¶ added in v0.1.7
func ProductionRelayFactory() RelayFactory
ProductionRelayFactory 返回包装 relay.Start 的工厂。
type RunOptions ¶
type RunOptions struct {
Stage protocol.Stage
// WorkingDir 是子进程的工作目录;为空时回退 ProjectDir。
// managed 后端按增补 1 C6 传 app-root,使用户数据不再落在会被
// workspace sync 整体替换的 repo/ 里;一次性 uv 命令都不传,行为不变。
WorkingDir string
ProjectDir string
PythonInstallDir string
ProjectEnvDir string
CacheDir string
// Environment 只接受非受控诊断变量,以及 network.go 明确允许的 UV 网络键;
// Runtime-only 遥测键会被拒绝,StartManaged 会清除并覆盖全部 AUTO_MAS 监督键。
Environment map[string]string
PythonVersion string
Branch string
Commit string
Line LineFunc
}
RunOptions 描述单次 uv 调用的可变信息。
type Runner ¶
type Runner interface {
Run(ctx context.Context, args []string, options RunOptions) (UVResult, error)
}
Runner 是 Python 服务消费的最小 uv 执行能力。
type RunnerConfig ¶
type RunnerConfig struct {
Executable string
ProjectDir string
PythonInstallDir string
ProjectEnvDir string
CacheDir string
Clock func() time.Time
}
RunnerConfig 描述一个受管 uv 执行器的固定目录上下文。
type SupervisionIdentity ¶
SupervisionIdentity 保存 managed 模式必须注入后端的版本与提交身份;development 传 nil。
type SupervisionInfrastructure ¶
type SupervisionInfrastructure struct {
UVCacheDir string
PythonInstallDir string
PackageIndexSources []string
PythonSources []string
// RelayBaseURL 非空时(增补 2 C17 第 8 条),两份列表以回环中继的 simple / python 路由开头。
// 只接受 http://127.0.0.1:<port>。
RelayBaseURL string
}
SupervisionInfrastructure 描述按增补 1 C11 下发给后端的受管基础设施事实。
四项在 managed 与 development 两种模式下都会被注入。两个目录留空时回退到本次 uv 调用实际解析出的受管目录,保证下发值与 UV_CACHE_DIR / UV_PYTHON_INSTALL_DIR 永远同源——C11 要的是「共用一份缓存与一份解释器」,两者一旦分叉契约即失效。 两个源列表按 Runtime 解析后的尝试顺序排列,空切片对应 --offline 的空串注入。
type TreeRemover ¶
type TreeRemover interface {
RemoveTree(context.Context, filesystem.DeleteRequest) (filesystem.DeleteResult, error)
}
TreeRemover 是需要删除受管目录的服务所消费的最小能力。
type UVOperations ¶
type UVOperations interface {
Ensure(context.Context, string, mirror.Policy) (string, error)
Check(context.Context) (bool, error)
}
UVOperations 是环境编排消费的 uv bootstrap/check 能力。
type UVRepairOperations ¶
type UVRepairOperations interface {
Repair(context.Context, string, mirror.Policy) (string, error)
}
UVRepairOperations 是显式 repair 消费的 uv 重下重验能力。
type UVRunner ¶
type UVRunner struct {
Executable string
ProjectDir string
PythonInstallDir string
ProjectEnvDir string
CacheDir string
Clock func() time.Time
}
UVRunner 是 Runtime 唯一的 uv 子进程执行入口。
func NewRunner ¶
func NewRunner(config RunnerConfig) (*UVRunner, error)
NewRunner 创建固定可执行文件的 uv 执行器。
func (*UVRunner) CheckVersion ¶
func (r *UVRunner) CheckVersion( ctx context.Context, expected string, stage protocol.Stage, line LineFunc, ) error
CheckVersion 验证受管 uv 的 --version 输出是否报告固定版本。
func (*UVRunner) CheckVersionWithOptions ¶
func (r *UVRunner) CheckVersionWithOptions(ctx context.Context, expected string, options RunOptions) error
CheckVersionWithOptions 使用调用方显式提供的路径上下文验证受管 uv 版本。
func (*UVRunner) CommandEnvironmentDetails ¶
func (r *UVRunner) CommandEnvironmentDetails(options RunOptions) map[string]any
CommandEnvironmentDetails 返回不会包含外部输出的调试字段。
func (*UVRunner) EnvironmentForTesting ¶
func (r *UVRunner) EnvironmentForTesting(options RunOptions) map[string]string
EnvironmentForTesting 返回受控环境的稳定键值视图,供假 uv 夹具断言。
func (*UVRunner) StartManaged ¶
func (r *UVRunner) StartManaged( ctx context.Context, args []string, options ManagedOptions, sink process.StreamSink, ) (*process.ManagedProcess, error)
StartManaged 复用 UVRunner 的路径与环境策略启动长驻 uv,且不提供普通 exec 降级。