Add your description here
Project description
tools-for-dev
基于 DEBUG 环境变量控制的 Python 开发调试工具库
功能特性
debug_only- 装饰器,仅在 DEBUG 模式下执行函数debug_print- 仅在 DEBUG 模式下输出的调试打印debug_pprint- 仅在 DEBUG 模式下输出的美化打印is_debug- DEBUG 环境变量检测
安装
使用 uv 安装:
uv add tools-for-dev
使用 pip 安装:
pip install tools-for-dev
快速开始
设置 DEBUG 环境变量
# Linux / macOS
export DEBUG=1
# Windows (PowerShell)
$env:DEBUG=1
使用示例
from tools_for_dev import debug_only, debug_print, debug_pprint
# 使用 debug_print
debug_print("这是一条调试信息")
debug_print("变量值:", {"name": "test", "value": 42})
# 使用 debug_pprint(美化打印)
debug_pprint({"user": {"name": "Buffalo", "age": 25}})
# 使用 debug_only 装饰器
@debug_only()
def my_debug_function():
print("仅在 DEBUG 模式下执行")
return "debug result"
result = my_debug_function()
# DEBUG=1 时返回 "debug result",否则返回 None
# 强制启用装饰器(不受环境变量影响)
@debug_only(enable=True)
def always_enabled():
print("始终执行")
API 文档
debug_only(enable: bool = False)
装饰器工厂函数,控制被装饰函数仅在 DEBUG 模式下执行。
enable: 如果设为True,强制启用装饰器,不受环境变量影响
debug_print(*args, **kwargs)
基于 devtools.debug 的调试打印,仅在 DEBUG 模式下输出。
debug_pprint(*args, **kwargs)
基于 devtools.pprint 的美化打印,仅在 DEBUG 模式下输出。
is_debug() -> bool
检测当前是否处于 DEBUG 模式,通过读取 DEBUG 环境变量判断。
注意:当前实现使用 os.getenv("DEBUG", False),当环境变量设置为任意值(包括 DEBUG=0)时均会返回 True。如需更精确的控制,建议修改为:
def is_debug() -> bool:
return os.getenv("DEBUG", "").lower() in ("1", "true", "yes")
开发
安装开发依赖
uv sync
运行测试
uv run pytest
运行测试(带覆盖率)
uv run pytest --cov
构建
uv build
依赖
- Python >= 3.11
- devtools >= 0.12.2
开发依赖
- allure-pytest >= 2.16.0
- pytest-cov >= 7.1.0
- pytest-mock >= 3.15.1
许可证
MIT License
作者
Buffalo
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tools_for_dev-0.1.1.tar.gz.
File metadata
- Download URL: tools_for_dev-0.1.1.tar.gz
- Upload date:
- Size: 2.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
90de56ea46c7a8e4f123965aba4c2b04ea1a4984623c424a008105f3c5424a75
|
|
| MD5 |
ef6be580cffed4caf912df13908018b7
|
|
| BLAKE2b-256 |
2edae8b04445652dfd42e66cc5ed84acc960a1f72740be366fe24329bb2d3415
|
File details
Details for the file tools_for_dev-0.1.1-py3-none-any.whl.
File metadata
- Download URL: tools_for_dev-0.1.1-py3-none-any.whl
- Upload date:
- Size: 3.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ddfcd6535e5f6ac45888f520ea5c97b84cc6e4ba17eb8dd9f9bbacef5bd61841
|
|
| MD5 |
d7f79da52c2fed0c69375d1fde2143e8
|
|
| BLAKE2b-256 |
0f18f95254f055a73af4cb1cb42d6c8e788e503178fd503bd49979374b520371
|