xharness
面向 Python 和 TypeScript 的共享基础库,提供 Windows 应用打包、发布部署、配置与日志等运维支持。
最低环境要求:Python 3.12 与 Node.js 22。
安装
Python (uv)
uv add xharness
TypeScript / Node.js (npm)
npm i @lightxlab/xharness
快速上手
xharness 核心用于产品的打包与发布部署。
1. 本地打包 Windows 可执行文件
支持 .py(基于 PyInstaller)和 .js(基于 Node pkg)入口,默认打包输出至 dist/。
Python
from xharness import deploy
request = deploy.BuildRequest(entrypoint="app.py")
output_path = deploy.build(request)
print(f"可执行文件已生成: {output_path}")
也可以直接通过 CLI 打包:
uv run xharness-build --entrypoint app.py
TypeScript
import { deploy } from "@lightxlab/xharness";
const { artifactPath } = await deploy.build({
entrypoint: "app.js",
});
console.log(`可执行文件已生成: ${artifactPath}`);
2. 打包配置 (xharness.toml)
如果需要自定义打包名称、输出目录或打包工具参数,可在产品根目录创建 xharness.toml:
product = "my-product"
output = "dist"
[pyinstaller]
hidden-imports = ["uvicorn"]
resources = [
{ source = "assets", destination = "assets" }
]
[pkg]
compress = "GZip"
3. 日志
logging.configure() 基于 Loguru 配置控制台与文件日志:
from xharness import logging
logging.configure()
logging.info("应用已启动")
- 控制台输出到 stderr(默认
INFO),文件写入<product>.log(默认DEBUG) - 文件按 10 MB 或每天轮转,保留 14 天
log_dir、product、level、console_level、file_level可覆盖默认值,XHARNESS_LOG_DIR、XHARNESS_LOG_LEVEL作为回退product默认取可执行文件 / 脚本的文件名主干,须符合产品名规范^[a-z][a-z0-9_-]*$log_dir默认遵循路径策略:单文件可执行文件写在<runtime_root>/log/<product>/,否则写在<state_root>/<product>/log;优先级为log_dir参数 ><PRODUCT>_LOG_DIR>XHARNESS_LOG_DIR> 路径策略默认值(越具体越优先)- 重复调用会替换已有 sink;第三方库的标准库 logging 默认接管,
intercept_stdlib=False可关闭 - 一个日志文件只有一个写入者:同一产品的并发实例需传入不同的
log_dir - 日志目录不可写时降级为仅控制台输出,并给出警告
4. 运行时配置与打包模式
from xharness import config, env
runtime = env.runtime_name()
settings = config.load()
当前
config.load仍为接口占位桩函数(调用抛出NotImplementedError/Error),后续版本开放具体实现;env.runtime_name/runtimeName已实现打包模式探测(返回source、pyinstaller、pkg或unknown)。
5. 产品发布工具
npm 包提供 xharness-product-release 命令,从产品的 v* CalVer 标签构建并挂载发布产物。一次发布包含可执行文件、manifest 与 SHA-256 校验和,三者共用同一个文件名主干(release trio):
xharness-product-release pins --entrypoint app.js
xharness-product-release build --ref v2026.10.0 --entrypoint app.js --output dist
xharness-product-release attach --ref v2026.10.0 --output dist
pins:输出打包工具版本(pkg、pyinstaller、node),产品根目录的xharness.toml可以覆盖build:从标签构建并校验 release trio。--entrypoint是产品根目录内的相对路径;--signing-command接收 JSON 字符串数组,签名密钥取自XHARNESS_SIGNING_SECRET;--pre-ship-command在打包前执行。pkg 后端要求PKG_CACHE_PATH指向已预取的 Node 基础二进制attach:把校验过的 release trio 挂到对应的 GitHub Release,需要GH_TOKEN或GITHUB_TOKEN;GITHUB_REPOSITORY指定产品仓库,XHARNESS_RELEASE_API可覆盖 API 地址
Python 后端(.py 入口)要求目标 Python 环境能导入 xharness,用 uv pip install xharness 安装。
产品工作流安装的 PyPI xharness 与 npm 包版本保持一致(同一个 tag),两个包成对发布。
许可
Metadata
Release files for xharness 0.2.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| xharness-0.2.2.tar.gz | 20.8 kB | With provenance | Details for xharness-0.2.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| xharness-0.2.2-py3-none-any.whl | Python 3 | none | any | Details for xharness-0.2.2-py3-none-any.whl |
Total release size: 44.2 kB
Release files / xharness-0.2.2.tar.gz
| Download URL | xharness-0.2.2.tar.gz |
|---|---|
| Size | 20.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
48cc1fe71f9a84c8562ad35bc28aa1f402c8d8ecf6795063382c845b4de0f396
|
|
BLAKE2b-256 checksum How to use checksums |
a6a6cbdbc297a74e7045eb5280d5c80925eb49ed7a099d926d04e152720b7fd5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 18, 2026.
Transparency logRelease files / xharness-0.2.2-py3-none-any.whl
| Download URL | xharness-0.2.2-py3-none-any.whl |
|---|---|
| Size | 23.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a5f7b32751e1452ffa0f8403363e1b7aa4b5bfa67fc5ecdd20dcbb089d050b77
|
|
BLAKE2b-256 checksum How to use checksums |
6b0767b328838c4601d238a4049f37136e2ccdec4e331639eb015fddb7eb8f4c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 18, 2026.
Transparency logSecurity for xharness 0.2.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for xharness-0.2.2.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 18, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.