Skip to main content

Xulab Useful Toolkit in Python (xutk)

Maintenance PyPI - Python Version License: Apache-2.0

XuTK 是课题组泛用 Python 小工具。 来自于古法编程时代,旨在消除重复代码、提高小工具质量。

导入项目

# 在 uv 项目下添加依赖安装
uv add xutk
# 或使用 pip 安装
pip install xutk

快速开始

from xutk import verchk, log, mp_runner
from xutk.script_lib.ants import AntsRegistrator
from pathlib import Path

# 版本检查
verchk.check_version("0.2.0", "some_package")

# 日志记录
logger = log.CtxLogger("my_app")
logger.info({"caller": "some_module", "note_file": "data.csv"}, "Processing started")

# 多进程运行器
runner = mp_runner.mprunner_factory(2, log_file=Path("process.log")) # 进程队列,取 2 个运行
runner.batch_run((f"echo test{num}" for num in range(1, 25))) # 排队 25 个进程

# ANTs 配准
slurm_cfg = ...
ants = AntsRegistrator(Path("config/ants_registration.yaml"), slurm_cfg)
job_id = ants.submit(
    project_root=Path("/data/project"),
    fixed_image=Path("/data/project/templates/t1.nii.gz"),
    moving_image=Path("/data/project/subjects/001.nii.gz"),
    job_name="subj001",
)

建议在项目 __init__.py 创建 CtxLogger("my_app"),避免实例化顺序问题。

项目结构

xutk/
├── .gitea/
│   └── workflows/       # CI 工作流
├── examples/            # 使用案例
├── src/
│   └── xutk/                # 主包
│       ├── __init__.py
│       ├── log.py           # 日志记录
│       ├── mp_runner/       # 多进程运行管理
│       ├── perf.py          # 资源追踪
│       ├── verchk.py        # 版本检查
│       └── script_lib/      # 脚本工具
│           └── ants/        # ANTs 配准工具
├── test/
│   ├── integration/     # 集成测试
│   └── unit/            # 单元测试
├── pyproject.toml       # 项目配置
└── README.md            # 项目文档

开发

安装开发依赖

uv sync --all-extras

运行测试

uv run pytest

代码检查

uv run ruff check      # 代码风格检查
uv run ty check        # 类型检查
uv run pytest          # 样例测试

Metadata

Release files for xutk 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for xutk 0.4.0
File Size Uploaded
xutk-0.4.0.tar.gz 31.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for xutk 0.4.0
File Interpreter ABI Platform
xutk-0.4.0-py3-none-any.whl Python 3 none any Details

Total release size: 71.1 kB

Release files / xutk-0.4.0.tar.gz

Download URL xutk-0.4.0.tar.gz
Size 31.3 kB
Tags Source
SHA-256 checksum
How to use checksums
14d3c377a9be5d803d02c24d44ed96169cdebbe7d19b185ea7ef547c5f8092f5
BLAKE2b-256 checksum
How to use checksums
6f726749eaabb8c624cf7004e8f973a1e6a9f965166e570ddb3b3a9100ac3dae
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.3 {"installer":{"name":"uv","version":"0.12.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Gentoo","version":"2.18","id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / xutk-0.4.0-py3-none-any.whl

Download URL xutk-0.4.0-py3-none-any.whl
Size 39.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
eced5c81ac6089b923b7182bd026c8d033ce905b78fe94905359755068fa1905
BLAKE2b-256 checksum
How to use checksums
80fe36e531334712df94ff7d729a61417336af9c18bdaa59050a9d00ad2e7eac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.3 {"installer":{"name":"uv","version":"0.12.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Gentoo","version":"2.18","id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release history Release notifications | RSS feed

0.5.0

2 release files

This release

0.4.0 This release

2 release files

0.3.5

2 release files

0.3.4

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page