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",
    # 可选任务级参数(初始变换 / mask,不进 YAML):
    # initial_moving_transform="moments",   # 或变换文件、或二者混链(列表顺序=施加顺序)
    # masks=(Path(".../t1_mask.nii.gz"), Path(".../001_mask.nii.gz")),  # (fixed, moving)
)

建议在项目 __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.5.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.5.0
File Size Uploaded
xutk-0.5.0.tar.gz 35.6 kB Details

Built distribution (wheel)

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

Total release size: 79.3 kB

Release files / xutk-0.5.0.tar.gz

Download URL xutk-0.5.0.tar.gz
Size 35.6 kB
Tags Source
SHA-256 checksum
How to use checksums
6f770bd0dc497187843dd54b789be258872f273a2ec1d83d940228fefef04941
BLAKE2b-256 checksum
How to use checksums
5c676dec5f615f72881bd0158108c5f51fbd1d1ccae6369ce29f48a8c490ce3b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.1 {"installer":{"name":"uv","version":"0.13.1","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.5.0-py3-none-any.whl

Download URL xutk-0.5.0-py3-none-any.whl
Size 43.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b6727c3bf68b64a2986700b8af133991a3ffafa56d761ee126c848fab2469ee5
BLAKE2b-256 checksum
How to use checksums
8754472e596da8c76e1ef38759983e3a8a988d0230f2ae02159ff7be98cea201
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.1 {"installer":{"name":"uv","version":"0.13.1","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

This release

0.5.0 This release

2 release files

0.4.0

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